From e59cebaf22e175252dd6d5dd633b3d985c87ba14 Mon Sep 17 00:00:00 2001 From: Draknyte1 Date: Sun, 24 Apr 2016 02:24:39 +1000 Subject: Code Cleanups. Liquid Test 1. --- src/Java/miscutil/core/util/Benchmark.java | 153 ----------------- src/Java/miscutil/core/util/ItemUtils.java | 186 --------------------- src/Java/miscutil/core/util/Log.java | 2 +- src/Java/miscutil/core/util/MiningMethods.java | 179 -------------------- src/Java/miscutil/core/util/UtilsItems.java | 186 +++++++++++++++++++++ src/Java/miscutil/core/util/UtilsMining.java | 179 ++++++++++++++++++++ .../core/util/VanillaChatCommandSender.java | 35 ++++ 7 files changed, 401 insertions(+), 519 deletions(-) delete mode 100644 src/Java/miscutil/core/util/Benchmark.java delete mode 100644 src/Java/miscutil/core/util/ItemUtils.java delete mode 100644 src/Java/miscutil/core/util/MiningMethods.java create mode 100644 src/Java/miscutil/core/util/UtilsItems.java create mode 100644 src/Java/miscutil/core/util/UtilsMining.java create mode 100644 src/Java/miscutil/core/util/VanillaChatCommandSender.java (limited to 'src/Java/miscutil/core/util') diff --git a/src/Java/miscutil/core/util/Benchmark.java b/src/Java/miscutil/core/util/Benchmark.java deleted file mode 100644 index 1e17175c3b..0000000000 --- a/src/Java/miscutil/core/util/Benchmark.java +++ /dev/null @@ -1,153 +0,0 @@ -package miscutil.core.util; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Random; - -import cpw.mods.fml.common.FMLLog; - -@SuppressWarnings("unused") -public class Benchmark { - - public void math() throws ParseException{ - Random r = new Random(); - - FMLLog.info("Looking at the stars in the sky"); - - // generate some random boolean values - boolean[] booleans = new boolean[10]; - for (int i = 0; i < booleans.length; i++) { - booleans[i] = r.nextBoolean(); - } - - //FMLLog.info(getSha256(booleans.toString())); - - /*for (boolean b : booleans) { - FMLLog.info(b + ", "); - }*/ - - // generate a uniformly distributed int random numbers - int[] integers = new int[10]; - for (int i = 0; i < integers.length; i++) { - integers[i] = r.nextInt(); - } - - FMLLog.info(getSha256(integers.toString())); - - /*for (int i : integers) {s - FMLLog.info(i + ", "); - }*/ - - // generate a uniformly distributed float random numbers - float[] floats = new float[10]; - for (int i = 0; i < floats.length; i++) { - floats[i] = r.nextFloat(); - } - - FMLLog.info(getSha256(floats.toString())); - - /*for (float f : floats) { - FMLLog.info(f + ", "); - }*/ - - // generate a Gaussian normally distributed random numbers - double[] gaussians = new double[10]; - for (int i = 0; i < gaussians.length; i++) { - gaussians[i] = r.nextGaussian(); - } - - FMLLog.info(getSha256(gaussians.toString())); - } - - private String dateTime(){ - DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd - HH:mm:ss"); - //get current date time with Calendar() - Calendar cal = Calendar.getInstance(); - return dateFormat.format(cal.getTime()); - } - - public String superhash(String a){ - FMLLog.info("Calculating the cost of life & the universe"); - int i = 1; - String b = a; - while (i < 3358 && i > 0){ - if (!b.equals(a)){ - b = a; - } - getSha256(b); - a = b; - try { - Thread.sleep(2); - } catch (InterruptedException e) { - FMLLog.info("Hashbrown order failed"); - e.printStackTrace(); - } - if (i == 500 || i == 1000 || i == 1500 || i == 2000 || i == 2500 || i == 3000 || i == 3500 || i == 4000 || i == 5000){ - //FMLLog.info("Calculating orbits around the sun: "+i); - } - i++; - } - return b; - } - - private String getSha256(String message) { - if (message == null || message.isEmpty()) { - return ""; - } - String chiper = generateString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=!@#$%^&*()_+`~[];',./{}:<>?|'", 32); - String key = generateString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=!@#$%^&*()_+`~[];',./{}:<>?|'", 16); // key is used to construct a new SHA-256 key/salt - - // Initialize SHA-256 - MessageDigest digest = null; - try { - digest = MessageDigest.getInstance("SHA-256"); - } catch (NoSuchAlgorithmException e) { - System.err.println(e.getMessage()); - } - - // Hashing entered key to construct a new key/salt - byte[] keyAsSHA256 = digest.digest(key.getBytes()); - - // Encoding the message with CBC - char[] messageAsChars = message.toCharArray(); - messageAsChars[0] ^= keyAsSHA256[0]; // Avoiding buffer underflow - for (int i = 1; i < messageAsChars.length; i++) { - messageAsChars[i] ^= messageAsChars[i - 1]; // XOR with previous character - messageAsChars[i] ^= keyAsSHA256[i % keyAsSHA256.length]; // XOR with keys hash - } - // build cipher from the chars - chiper = new String(messageAsChars); - String cipher = MD5(chiper); - return chiper + "|" + cipher; - } - - public String MD5(String md5) { - try { - java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); - byte[] array = md.digest(md5.getBytes()); - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < array.length; ++i) { - sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3)); - } - return sb.toString(); - } catch (java.security.NoSuchAlgorithmException e) { - } - return null; - } - - public static String generateString(String characters, int length) - { - Random r = new Random(); - char[] text = new char[length]; - for (int i = 0; i < length; i++) - { - text[i] = characters.charAt(r.nextInt(characters.length())); - } - return new String(text); - } - -} \ No newline at end of file diff --git a/src/Java/miscutil/core/util/ItemUtils.java b/src/Java/miscutil/core/util/ItemUtils.java deleted file mode 100644 index fa7fb5f969..0000000000 --- a/src/Java/miscutil/core/util/ItemUtils.java +++ /dev/null @@ -1,186 +0,0 @@ -package miscutil.core.util; - -import gregtech.api.util.GT_OreDictUnificator; - -import java.util.ArrayList; - -import miscutil.core.handler.registration.RegistrationHandler; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.ShapedOreRecipe; -import cpw.mods.fml.common.registry.GameRegistry; - -public class ItemUtils { - - public static ItemStack getItemStackOfItem(Boolean modToCheck, String mod_itemname_meta){ - if (modToCheck){ - try{ - Item em = null; - - Item em1 = Utils.getItem(mod_itemname_meta); - Utils.LOG_WARNING("Found: "+em1.toString()); - if (!em1.equals(null)){ - em = em1; - } - else { - em = null; - return null; - } - if (!em.equals(null)){ - ItemStack returnStack = new ItemStack(em,1,16); - return returnStack; - } - Utils.LOG_WARNING(mod_itemname_meta+" not found."); - return null; - } catch (NullPointerException e) { - Utils.LOG_ERROR(mod_itemname_meta+" not found. [NULL]"); - return null; - } - } - return null; - } - - public static void getItemForOreDict(String FQRN, String oreDictName, String itemName, int meta){ - try { - Item em = null; - Item em1 = Utils.getItem(FQRN); - Utils.LOG_WARNING("Found: "+em1.getUnlocalizedName()+":"+meta); - if (em1 != null){ - em = em1; - } - if (em != null){ - - ItemStack metaStack = new ItemStack(em,1,meta); - GT_OreDictUnificator.registerOre(oreDictName, metaStack); - - /*ItemStack itemStackWithMeta = new ItemStack(em,1,meta); - GT_OreDictUnificator.registerOre(oreDictName, new ItemStack(itemStackWithMeta.getItem()));*/ - } - } catch (NullPointerException e) { - Utils.LOG_ERROR(itemName+" not found. [NULL]"); - } - } - - public static void recipeBuilder(Object slot_1, Object slot_2, Object slot_3, Object slot_4, Object slot_5, Object slot_6, Object slot_7, Object slot_8, Object slot_9, ItemStack resultItem){ - - ArrayList validSlots = new ArrayList(); - - //, String lineFirst, String lineSecond, String lineThird - Utils.LOG_INFO("Trying to add a recipe for "+resultItem.toString()); - String a,b,c,d,e,f,g,h,i; - //ItemStack empty = new ItemStack(Blocks.air); - if (slot_1 == null){ a = " ";} else { a = "1";validSlots.add('1');validSlots.add(slot_1);} - Utils.LOG_WARNING(a); - if (slot_2 == null){ b = " ";} else { b = "2";validSlots.add('2');validSlots.add(slot_2);} - Utils.LOG_WARNING(b); - if (slot_3 == null){ c = " ";} else { c = "3";validSlots.add('3');validSlots.add(slot_3);} - Utils.LOG_WARNING(c); - if (slot_4 == null){ d = " ";} else { d = "4";validSlots.add('4');validSlots.add(slot_4);} - Utils.LOG_WARNING(d); - if (slot_5 == null){ e = " ";} else { e = "5";validSlots.add('5');validSlots.add(slot_5);} - Utils.LOG_WARNING(e); - if (slot_6 == null){ f = " ";} else { f = "6";validSlots.add('6');validSlots.add(slot_6);} - Utils.LOG_WARNING(f); - if (slot_7 == null){ g = " ";} else { g = "7";validSlots.add('7');validSlots.add(slot_7);} - Utils.LOG_WARNING(g); - if (slot_8 == null){ h = " ";} else { h = "8";validSlots.add('8');validSlots.add(slot_8);} - Utils.LOG_WARNING(h); - if (slot_9 == null){ i = " ";} else { i = "9";validSlots.add('9');validSlots.add(slot_9);} - Utils.LOG_WARNING(i); - - - Utils.LOG_ERROR("_______"); - String lineOne = a+b+c; - Utils.LOG_ERROR("|"+a+"|"+b+"|"+c+"|"); - Utils.LOG_ERROR("_______"); - String lineTwo = d+e+f; - Utils.LOG_ERROR("|"+d+"|"+e+"|"+f+"|"); - Utils.LOG_ERROR("_______"); - String lineThree = g+h+i; - Utils.LOG_ERROR("|"+g+"|"+h+"|"+i+"|"); - Utils.LOG_ERROR("_______"); - - validSlots.add(0, lineOne); - validSlots.add(1, lineTwo); - validSlots.add(2, lineThree); - Boolean AadvancedLog = true; - if (AadvancedLog){ - int j = 0; - int l = validSlots.size(); - Utils.LOG_WARNING("l:"+l); - while (j <= l) { - Utils.LOG_WARNING("j:"+j); - if (j <= 2){ - Utils.LOG_WARNING("ArrayList Values: "+validSlots.get(j)); - Utils.LOG_WARNING("Adding 1."); - j++; - } - else if (j >= 3){ - Utils.LOG_WARNING("ArrayList Values: '"+validSlots.get(j)+"' "+validSlots.get(j+1)); - if (j < (l-2)){ - Utils.LOG_WARNING("Adding 2."); - j=j+2; - } - else { - Utils.LOG_WARNING("Done iteration."); - break; - } - } - else if (j == l){ - Utils.LOG_WARNING("Done iteration."); - break; - } - if (validSlots.get(j) instanceof String || validSlots.get(j) instanceof ItemStack){ - //Utils.LOG_WARNING("Is Valid: "+validSlots.get(j)); - } - } - } - - try { - /*Utils.LOG_WARNING("validSlots to array: "+validSlots.toArray()); - Object[] validSlotsArray = (Object[]) validSlots.toArray(); - - for(int j = 0; j < validSlotsArray.length; j++) - { - Utils.LOG_ERROR(""+validSlotsArray[j]); - }*/ - - GameRegistry.addRecipe(new ShapedOreRecipe(resultItem.copy(), (Object[]) validSlots.toArray())); - Utils.LOG_INFO("Success! Added a recipe for "+resultItem.toString()); - RegistrationHandler.recipesSuccess++; - /*try { - try { - try { - //Code - } - catch (NullPointerException | ClassCastException r){ - Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName()); - RegistrationHandler.recipesFailed++; - r.printStackTrace(); - //System.exit(1); - } - } - catch (NullPointerException o){ - - Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName()); - o.printStackTrace(); - RegistrationHandler.recipesFailed++; - //System.exit(1); - } - } - catch (ClassCastException r){ - Utils.LOG_WARNING("@@@: Casting to ObjectArray Failed :("); - }*/ - } - catch(NullPointerException | ClassCastException k){ - k.getMessage(); - k.getClass(); - k.printStackTrace(); - k.getLocalizedMessage(); - Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName()); - RegistrationHandler.recipesFailed++; - //System.exit(1); - } - } - -} diff --git a/src/Java/miscutil/core/util/Log.java b/src/Java/miscutil/core/util/Log.java index 3d0bf73099..90c9dbdf79 100644 --- a/src/Java/miscutil/core/util/Log.java +++ b/src/Java/miscutil/core/util/Log.java @@ -5,7 +5,7 @@ import org.apache.logging.log4j.Logger; public final class Log { - public static final Logger LOGGER = LogManager.getLogger("EnderIO"); + public static final Logger LOGGER = LogManager.getLogger("MiscUtils"); public static void warn(String msg) { diff --git a/src/Java/miscutil/core/util/MiningMethods.java b/src/Java/miscutil/core/util/MiningMethods.java deleted file mode 100644 index 6f8042f800..0000000000 --- a/src/Java/miscutil/core/util/MiningMethods.java +++ /dev/null @@ -1,179 +0,0 @@ -package miscutil.core.util; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -public class MiningMethods { - - private static boolean durabilityDamage = false; - private static ItemStack stack; - - public static Boolean canPickaxeBlock(Block currentBlock, World currentWorld){ - String correctTool = ""; - if (!currentWorld.isRemote){ - try { - correctTool = currentBlock.getHarvestTool(0); - //Utils.LOG_WARNING(correctTool); - if (correctTool.equals("pickaxe")){ - return true;} - } catch (NullPointerException e){ - return false;} - } - return false; - } - - private static void removeBlockAndDropAsItem(World world, int X, int Y, int Z){ - try { - Block block = world.getBlock(X, Y, Z); - if (canPickaxeBlock(block, world)){ - if((block != Blocks.bedrock) && (block.getBlockHardness(world, X, Y, Z) != -1) && (block.getBlockHardness(world, X, Y, Z) <= 100) && (block != Blocks.water) && (block != Blocks.lava)){ - block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0); - world.setBlockToAir(X, Y, Z); - - } - else { - Utils.LOG_WARNING("Incorrect Tool for mining this block."); - } - } - } catch (NullPointerException e){ - - } - } - - public static void customMine(World world, String FACING, EntityPlayer aPlayer){ - - float DURABILITY_LOSS = 0; - if (!world.isRemote){ - int X = 0; - int Y = 0; - int Z = 0; - - if (FACING.equals("below") || FACING.equals("above")){ - - //Set Player Facing - X = (int) aPlayer.posX; - Utils.LOG_WARNING("Setting Variable X: "+X); - if (FACING.equals("above")){ - Z = (int) aPlayer.posY + 1; - Utils.LOG_WARNING("Setting Variable Y: "+Y); - } - else { - Z = (int) aPlayer.posY - 1; - Utils.LOG_WARNING("Setting Variable Y: "+Y);} - Z = (int) aPlayer.posZ; - Utils.LOG_WARNING("Setting Variable Z: "+Z); - - DURABILITY_LOSS = 0; - for(int i = -2; i < 3; i++) { - for(int j = -2; j < 3; j++) { - for(int k = -2; k < 3; k++) { -/*// float dur = calculateDurabilityLoss(world, X + i, Y + k, Z + j); -// DURABILITY_LOSS = (DURABILITY_LOSS + dur); -// Utils.LOG_WARNING("Added Loss: "+dur); -*/ removeBlockAndDropAsItem(world, X + i, Y + k, Z + j); - } - } - } - } - - else if (FACING.equals("facingEast") || FACING.equals("facingWest")){ - - //Set Player Facing - Z = (int) aPlayer.posZ; - Y = (int) aPlayer.posY; - if (FACING.equals("facingEast")){ - X = (int) aPlayer.posX + 1;} - else { - X = (int) aPlayer.posX - 1;} - - - DURABILITY_LOSS = 0; - for(int i = -1; i < 2; i++) { - for(int j = -1; j < 2; j++) { - for(int k = -1; k < 2; k++) { - /*float dur = calculateDurabilityLoss(world, X+k, Y + i, Z + j); - DURABILITY_LOSS = (DURABILITY_LOSS + dur); - Utils.LOG_WARNING("Added Loss: "+dur);*/ - removeBlockAndDropAsItem(world, X+k, Y + i, Z + j); - } - } - } - } - - else if (FACING.equals("facingNorth") || FACING.equals("facingSouth")){ - - //Set Player Facing - X = (int) aPlayer.posX; - Y = (int) aPlayer.posY; - - if (FACING.equals("facingNorth")){ - Z = (int) aPlayer.posZ + 1;} - else { - Z = (int) aPlayer.posZ - 1;} - - DURABILITY_LOSS = 0; - for(int i = -1; i < 2; i++) { - for(int j = -1; j < 2; j++) { - for(int k = -1; k < 2; k++) { - /*float dur = calculateDurabilityLoss(world, X + j, Y + i, Z+k); - DURABILITY_LOSS = (DURABILITY_LOSS + dur); - Utils.LOG_WARNING("Added Loss: "+dur);*/ - removeBlockAndDropAsItem(world, X + j, Y + i, Z+k); - } - } - } - } - - //Set Durability damage to the item - if (durabilityDamage == true){ - Utils.LOG_WARNING("Total Loss: "+(int)DURABILITY_LOSS); - if (stack.getItemDamage() < (stack.getMaxDamage()-DURABILITY_LOSS)){ - stack.damageItem((int) DURABILITY_LOSS, aPlayer); - } - } - DURABILITY_LOSS = 0; - } - } - - - public static boolean getBlockType(Block block){ - final String LIQUID = "liquid"; - final String BLOCK = "block"; - final String ORE = "ore"; - final String AIR = "air"; - String blockClass = ""; - - try { - blockClass = block.getClass().toString().toLowerCase(); - Utils.LOG_WARNING(blockClass); - if (blockClass.toLowerCase().contains(LIQUID)){ - Utils.LOG_WARNING(block.toString()+" is a Liquid."); - return false; - } - else if (blockClass.toLowerCase().contains(ORE)){ - Utils.LOG_WARNING(block.toString()+" is an Ore."); - return true; - } - else if (blockClass.toLowerCase().contains(AIR)){ - Utils.LOG_WARNING(block.toString()+" is Air."); - return false; - } - else if (blockClass.toLowerCase().contains(BLOCK)){ - Utils.LOG_WARNING(block.toString()+" is a block of some kind."); - return false; - } - else { - Utils.LOG_WARNING(block.toString()+" is mystery."); - return false; - } - } - catch(NullPointerException e){ - return false; - } - } - - -} diff --git a/src/Java/miscutil/core/util/UtilsItems.java b/src/Java/miscutil/core/util/UtilsItems.java new file mode 100644 index 0000000000..8d848fc914 --- /dev/null +++ b/src/Java/miscutil/core/util/UtilsItems.java @@ -0,0 +1,186 @@ +package miscutil.core.util; + +import gregtech.api.util.GT_OreDictUnificator; + +import java.util.ArrayList; + +import miscutil.core.handler.registration.RegistrationHandler; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.ShapedOreRecipe; +import cpw.mods.fml.common.registry.GameRegistry; + +public class UtilsItems { + + public static ItemStack getItemStackOfItem(Boolean modToCheck, String mod_itemname_meta){ + if (modToCheck){ + try{ + Item em = null; + + Item em1 = Utils.getItem(mod_itemname_meta); + Utils.LOG_WARNING("Found: "+em1.toString()); + if (!em1.equals(null)){ + em = em1; + } + else { + em = null; + return null; + } + if (!em.equals(null)){ + ItemStack returnStack = new ItemStack(em,1,16); + return returnStack; + } + Utils.LOG_WARNING(mod_itemname_meta+" not found."); + return null; + } catch (NullPointerException e) { + Utils.LOG_ERROR(mod_itemname_meta+" not found. [NULL]"); + return null; + } + } + return null; + } + + public static void getItemForOreDict(String FQRN, String oreDictName, String itemName, int meta){ + try { + Item em = null; + Item em1 = Utils.getItem(FQRN); + Utils.LOG_WARNING("Found: "+em1.getUnlocalizedName()+":"+meta); + if (em1 != null){ + em = em1; + } + if (em != null){ + + ItemStack metaStack = new ItemStack(em,1,meta); + GT_OreDictUnificator.registerOre(oreDictName, metaStack); + + /*ItemStack itemStackWithMeta = new ItemStack(em,1,meta); + GT_OreDictUnificator.registerOre(oreDictName, new ItemStack(itemStackWithMeta.getItem()));*/ + } + } catch (NullPointerException e) { + Utils.LOG_ERROR(itemName+" not found. [NULL]"); + } + } + + public static void recipeBuilder(Object slot_1, Object slot_2, Object slot_3, Object slot_4, Object slot_5, Object slot_6, Object slot_7, Object slot_8, Object slot_9, ItemStack resultItem){ + + ArrayList validSlots = new ArrayList(); + + //, String lineFirst, String lineSecond, String lineThird + Utils.LOG_INFO("Trying to add a recipe for "+resultItem.toString()); + String a,b,c,d,e,f,g,h,i; + //ItemStack empty = new ItemStack(Blocks.air); + if (slot_1 == null){ a = " ";} else { a = "1";validSlots.add('1');validSlots.add(slot_1);} + Utils.LOG_WARNING(a); + if (slot_2 == null){ b = " ";} else { b = "2";validSlots.add('2');validSlots.add(slot_2);} + Utils.LOG_WARNING(b); + if (slot_3 == null){ c = " ";} else { c = "3";validSlots.add('3');validSlots.add(slot_3);} + Utils.LOG_WARNING(c); + if (slot_4 == null){ d = " ";} else { d = "4";validSlots.add('4');validSlots.add(slot_4);} + Utils.LOG_WARNING(d); + if (slot_5 == null){ e = " ";} else { e = "5";validSlots.add('5');validSlots.add(slot_5);} + Utils.LOG_WARNING(e); + if (slot_6 == null){ f = " ";} else { f = "6";validSlots.add('6');validSlots.add(slot_6);} + Utils.LOG_WARNING(f); + if (slot_7 == null){ g = " ";} else { g = "7";validSlots.add('7');validSlots.add(slot_7);} + Utils.LOG_WARNING(g); + if (slot_8 == null){ h = " ";} else { h = "8";validSlots.add('8');validSlots.add(slot_8);} + Utils.LOG_WARNING(h); + if (slot_9 == null){ i = " ";} else { i = "9";validSlots.add('9');validSlots.add(slot_9);} + Utils.LOG_WARNING(i); + + + Utils.LOG_ERROR("_______"); + String lineOne = a+b+c; + Utils.LOG_ERROR("|"+a+"|"+b+"|"+c+"|"); + Utils.LOG_ERROR("_______"); + String lineTwo = d+e+f; + Utils.LOG_ERROR("|"+d+"|"+e+"|"+f+"|"); + Utils.LOG_ERROR("_______"); + String lineThree = g+h+i; + Utils.LOG_ERROR("|"+g+"|"+h+"|"+i+"|"); + Utils.LOG_ERROR("_______"); + + validSlots.add(0, lineOne); + validSlots.add(1, lineTwo); + validSlots.add(2, lineThree); + Boolean AadvancedLog = true; + if (AadvancedLog){ + int j = 0; + int l = validSlots.size(); + Utils.LOG_WARNING("l:"+l); + while (j <= l) { + Utils.LOG_WARNING("j:"+j); + if (j <= 2){ + Utils.LOG_WARNING("ArrayList Values: "+validSlots.get(j)); + Utils.LOG_WARNING("Adding 1."); + j++; + } + else if (j >= 3){ + Utils.LOG_WARNING("ArrayList Values: '"+validSlots.get(j)+"' "+validSlots.get(j+1)); + if (j < (l-2)){ + Utils.LOG_WARNING("Adding 2."); + j=j+2; + } + else { + Utils.LOG_WARNING("Done iteration."); + break; + } + } + else if (j == l){ + Utils.LOG_WARNING("Done iteration."); + break; + } + if (validSlots.get(j) instanceof String || validSlots.get(j) instanceof ItemStack){ + //Utils.LOG_WARNING("Is Valid: "+validSlots.get(j)); + } + } + } + + try { + /*Utils.LOG_WARNING("validSlots to array: "+validSlots.toArray()); + Object[] validSlotsArray = (Object[]) validSlots.toArray(); + + for(int j = 0; j < validSlotsArray.length; j++) + { + Utils.LOG_ERROR(""+validSlotsArray[j]); + }*/ + + GameRegistry.addRecipe(new ShapedOreRecipe(resultItem.copy(), (Object[]) validSlots.toArray())); + Utils.LOG_INFO("Success! Added a recipe for "+resultItem.toString()); + RegistrationHandler.recipesSuccess++; + /*try { + try { + try { + //Code + } + catch (NullPointerException | ClassCastException r){ + Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName()); + RegistrationHandler.recipesFailed++; + r.printStackTrace(); + //System.exit(1); + } + } + catch (NullPointerException o){ + + Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName()); + o.printStackTrace(); + RegistrationHandler.recipesFailed++; + //System.exit(1); + } + } + catch (ClassCastException r){ + Utils.LOG_WARNING("@@@: Casting to ObjectArray Failed :("); + }*/ + } + catch(NullPointerException | ClassCastException k){ + k.getMessage(); + k.getClass(); + k.printStackTrace(); + k.getLocalizedMessage(); + Utils.LOG_WARNING("@@@: Invalid Recipe detected for: "+resultItem.getUnlocalizedName()); + RegistrationHandler.recipesFailed++; + //System.exit(1); + } + } + +} diff --git a/src/Java/miscutil/core/util/UtilsMining.java b/src/Java/miscutil/core/util/UtilsMining.java new file mode 100644 index 0000000000..4c6ef7cda9 --- /dev/null +++ b/src/Java/miscutil/core/util/UtilsMining.java @@ -0,0 +1,179 @@ +package miscutil.core.util; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class UtilsMining { + + private static boolean durabilityDamage = false; + private static ItemStack stack; + + public static Boolean canPickaxeBlock(Block currentBlock, World currentWorld){ + String correctTool = ""; + if (!currentWorld.isRemote){ + try { + correctTool = currentBlock.getHarvestTool(0); + //Utils.LOG_WARNING(correctTool); + if (correctTool.equals("pickaxe")){ + return true;} + } catch (NullPointerException e){ + return false;} + } + return false; + } + + private static void removeBlockAndDropAsItem(World world, int X, int Y, int Z){ + try { + Block block = world.getBlock(X, Y, Z); + if (canPickaxeBlock(block, world)){ + if((block != Blocks.bedrock) && (block.getBlockHardness(world, X, Y, Z) != -1) && (block.getBlockHardness(world, X, Y, Z) <= 100) && (block != Blocks.water) && (block != Blocks.lava)){ + block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0); + world.setBlockToAir(X, Y, Z); + + } + else { + Utils.LOG_WARNING("Incorrect Tool for mining this block."); + } + } + } catch (NullPointerException e){ + + } + } + + public static void customMine(World world, String FACING, EntityPlayer aPlayer){ + + float DURABILITY_LOSS = 0; + if (!world.isRemote){ + int X = 0; + int Y = 0; + int Z = 0; + + if (FACING.equals("below") || FACING.equals("above")){ + + //Set Player Facing + X = (int) aPlayer.posX; + Utils.LOG_WARNING("Setting Variable X: "+X); + if (FACING.equals("above")){ + Z = (int) aPlayer.posY + 1; + Utils.LOG_WARNING("Setting Variable Y: "+Y); + } + else { + Z = (int) aPlayer.posY - 1; + Utils.LOG_WARNING("Setting Variable Y: "+Y);} + Z = (int) aPlayer.posZ; + Utils.LOG_WARNING("Setting Variable Z: "+Z); + + DURABILITY_LOSS = 0; + for(int i = -2; i < 3; i++) { + for(int j = -2; j < 3; j++) { + for(int k = -2; k < 3; k++) { +/*// float dur = calculateDurabilityLoss(world, X + i, Y + k, Z + j); +// DURABILITY_LOSS = (DURABILITY_LOSS + dur); +// Utils.LOG_WARNING("Added Loss: "+dur); +*/ removeBlockAndDropAsItem(world, X + i, Y + k, Z + j); + } + } + } + } + + else if (FACING.equals("facingEast") || FACING.equals("facingWest")){ + + //Set Player Facing + Z = (int) aPlayer.posZ; + Y = (int) aPlayer.posY; + if (FACING.equals("facingEast")){ + X = (int) aPlayer.posX + 1;} + else { + X = (int) aPlayer.posX - 1;} + + + DURABILITY_LOSS = 0; + for(int i = -1; i < 2; i++) { + for(int j = -1; j < 2; j++) { + for(int k = -1; k < 2; k++) { + /*float dur = calculateDurabilityLoss(world, X+k, Y + i, Z + j); + DURABILITY_LOSS = (DURABILITY_LOSS + dur); + Utils.LOG_WARNING("Added Loss: "+dur);*/ + removeBlockAndDropAsItem(world, X+k, Y + i, Z + j); + } + } + } + } + + else if (FACING.equals("facingNorth") || FACING.equals("facingSouth")){ + + //Set Player Facing + X = (int) aPlayer.posX; + Y = (int) aPlayer.posY; + + if (FACING.equals("facingNorth")){ + Z = (int) aPlayer.posZ + 1;} + else { + Z = (int) aPlayer.posZ - 1;} + + DURABILITY_LOSS = 0; + for(int i = -1; i < 2; i++) { + for(int j = -1; j < 2; j++) { + for(int k = -1; k < 2; k++) { + /*float dur = calculateDurabilityLoss(world, X + j, Y + i, Z+k); + DURABILITY_LOSS = (DURABILITY_LOSS + dur); + Utils.LOG_WARNING("Added Loss: "+dur);*/ + removeBlockAndDropAsItem(world, X + j, Y + i, Z+k); + } + } + } + } + + //Set Durability damage to the item + if (durabilityDamage == true){ + Utils.LOG_WARNING("Total Loss: "+(int)DURABILITY_LOSS); + if (stack.getItemDamage() < (stack.getMaxDamage()-DURABILITY_LOSS)){ + stack.damageItem((int) DURABILITY_LOSS, aPlayer); + } + } + DURABILITY_LOSS = 0; + } + } + + + public static boolean getBlockType(Block block){ + final String LIQUID = "liquid"; + final String BLOCK = "block"; + final String ORE = "ore"; + final String AIR = "air"; + String blockClass = ""; + + try { + blockClass = block.getClass().toString().toLowerCase(); + Utils.LOG_WARNING(blockClass); + if (blockClass.toLowerCase().contains(LIQUID)){ + Utils.LOG_WARNING(block.toString()+" is a Liquid."); + return false; + } + else if (blockClass.toLowerCase().contains(ORE)){ + Utils.LOG_WARNING(block.toString()+" is an Ore."); + return true; + } + else if (blockClass.toLowerCase().contains(AIR)){ + Utils.LOG_WARNING(block.toString()+" is Air."); + return false; + } + else if (blockClass.toLowerCase().contains(BLOCK)){ + Utils.LOG_WARNING(block.toString()+" is a block of some kind."); + return false; + } + else { + Utils.LOG_WARNING(block.toString()+" is mystery."); + return false; + } + } + catch(NullPointerException e){ + return false; + } + } + + +} diff --git a/src/Java/miscutil/core/util/VanillaChatCommandSender.java b/src/Java/miscutil/core/util/VanillaChatCommandSender.java new file mode 100644 index 0000000000..76e80204de --- /dev/null +++ b/src/Java/miscutil/core/util/VanillaChatCommandSender.java @@ -0,0 +1,35 @@ +package miscutil.core.util; + +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.IChatComponent; +import net.minecraft.world.World; + +public interface VanillaChatCommandSender { + + /** + * Gets the name of this command sender (usually username, but possibly "Rcon") + */ + String getCommandSenderName(); + + IChatComponent func_145748_c_(); + + /** + * Notifies this sender of some sort of information. This is for messages intended to display to the user. Used + * for typical output (like "you asked for whether or not this game rule is set, so here's your answer"), warnings + * (like "I fetched this block for you by ID, but I'd like you to know that every time you do this, I die a little + * inside"), and errors (like "it's not called iron_pixacke, silly"). + */ + void addChatMessage(IChatComponent p_145747_1_); + + /** + * Returns true if the command sender is allowed to use the given command. + */ + boolean canCommandSenderUseCommand(int p_70003_1_, String p_70003_2_); + + /** + * Return the position for this command sender. + */ + ChunkCoordinates getPlayerCoordinates(); + + World getEntityWorld(); + } -- cgit