diff options
Diffstat (limited to 'src/Java')
-rw-r--r-- | src/Java/miscutil/MiscUtils.java | 2 | ||||
-rw-r--r-- | src/Java/miscutil/core/handler/DebugRenderManager.java | 46 | ||||
-rw-r--r-- | src/Java/miscutil/core/item/tool/Loader_TOOLS.java | 26 | ||||
-rw-r--r-- | src/Java/miscutil/core/item/tool/staballoy/StaballoyPickaxe.java | 285 | ||||
-rw-r--r-- | src/Java/miscutil/core/lib/CORE.java | 2 | ||||
-rw-r--r-- | src/Java/miscutil/core/util/MiningMethods.java | 179 | ||||
-rw-r--r-- | src/Java/miscutil/core/util/Utils.java | 196 |
7 files changed, 590 insertions, 146 deletions
diff --git a/src/Java/miscutil/MiscUtils.java b/src/Java/miscutil/MiscUtils.java index 1a26e1add9..eb28d31d87 100644 --- a/src/Java/miscutil/MiscUtils.java +++ b/src/Java/miscutil/MiscUtils.java @@ -6,6 +6,7 @@ import java.awt.event.ActionListener; import miscutil.core.commands.CommandMath; import miscutil.core.common.CommonProxy; import miscutil.core.creativetabs.AddToCreativeTab; +import miscutil.core.handler.DebugRenderManager; import miscutil.core.handler.XEventHandler; import miscutil.core.lib.CORE; import miscutil.core.lib.LoadedMods; @@ -56,6 +57,7 @@ implements ActionListener proxy.registerOreDict(); MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new XEventHandler()); + MinecraftForge.EVENT_BUS.register(new DebugRenderManager()); FMLCommonHandler.instance().bus().register(this); proxy.registerNetworkStuff(); } diff --git a/src/Java/miscutil/core/handler/DebugRenderManager.java b/src/Java/miscutil/core/handler/DebugRenderManager.java new file mode 100644 index 0000000000..451d465e5e --- /dev/null +++ b/src/Java/miscutil/core/handler/DebugRenderManager.java @@ -0,0 +1,46 @@ +package miscutil.core.handler; + +import miscutil.core.item.tool.staballoy.StaballoyPickaxe; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.item.Item; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class DebugRenderManager extends Gui { + + int width, height; + Minecraft mc = Minecraft.getMinecraft(); + + @SubscribeEvent + public void eventHandler(RenderGameOverlayEvent.Text event) + { + + //if (mc.thePlayer.getHeldItem().equals(ModItems.itemStaballoyPickaxe)){ + ScaledResolution res = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight); + FontRenderer fontRender = mc.fontRenderer; + this.width = res.getScaledWidth(); + this.height = res.getScaledHeight(); + Minecraft.getMinecraft().entityRenderer.setupOverlayRendering(); + String str = "Words"; + Item heldItem = null; + + try{heldItem = mc.thePlayer.getHeldItem().getItem(); + + if (heldItem != null){ + if (heldItem instanceof StaballoyPickaxe){ + + int dmg =((StaballoyPickaxe) heldItem).getDamage(((StaballoyPickaxe) heldItem).thisPickaxe); + + ((StaballoyPickaxe) heldItem).checkFacing(((StaballoyPickaxe) heldItem).localWorld); + str = "DAMAGE: "+ dmg +" | FACING: "+((StaballoyPickaxe) heldItem).FACING+" | FACING_HORIZONTAL: "+((StaballoyPickaxe) heldItem).FACING_HORIZONTAL+" | LOOKING DIRECTION: "+((StaballoyPickaxe) heldItem).lookingDirection; + + drawString(fontRender, str, (this.width - fontRender.getStringWidth(str)) / 2, this.height / 10, 0xFFAA00); + } + } + }catch(NullPointerException e){} + + } +}
\ No newline at end of file diff --git a/src/Java/miscutil/core/item/tool/Loader_TOOLS.java b/src/Java/miscutil/core/item/tool/Loader_TOOLS.java new file mode 100644 index 0000000000..c88c39cb35 --- /dev/null +++ b/src/Java/miscutil/core/item/tool/Loader_TOOLS.java @@ -0,0 +1,26 @@ +package miscutil.core.item.tool; + +import miscutil.core.item.ModItems; +import net.minecraft.item.Item; + +public class Loader_TOOLS { + + private static //Tools + Item RECIPE_StaballoyPickaxe = ModItems.itemStaballoyPickaxe; + + //Dirt + //ItemStack dirtStack = new ItemStack(Block.dirt); + + //Materials + + + + public static final void run(){ + + } + + private static void registerPickaxes(){ + //Utils.recipeBuilderItem("plateStaballoy", "plateStaballoy", "ingotStaballoy", null, "plateStaballoy", null, null, null, null, RECIPE_StaballoyPickaxe); + } + +} diff --git a/src/Java/miscutil/core/item/tool/staballoy/StaballoyPickaxe.java b/src/Java/miscutil/core/item/tool/staballoy/StaballoyPickaxe.java index d797ceb67f..7e5db8691d 100644 --- a/src/Java/miscutil/core/item/tool/staballoy/StaballoyPickaxe.java +++ b/src/Java/miscutil/core/item/tool/staballoy/StaballoyPickaxe.java @@ -3,6 +3,7 @@ package miscutil.core.item.tool.staballoy; import java.util.List; import miscutil.core.lib.CORE; +import miscutil.core.util.MiningMethods; import miscutil.core.util.Utils; import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; @@ -10,15 +11,29 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; public class StaballoyPickaxe extends ItemPickaxe{ - private Boolean FACING_HORIZONTAL = true; - private String FACING = "north"; - private EntityPlayer localPlayer; + /* (non-Javadoc) + * @see net.minecraft.item.Item#getDurabilityForDisplay(net.minecraft.item.ItemStack) + */ + @Override + public double getDurabilityForDisplay(ItemStack stack) { + if (super.getDurabilityForDisplay(stack) > 0){ + return super.getDurabilityForDisplay(stack);} + return 0; + } + + public Boolean FACING_HORIZONTAL = true; + public String FACING = "north"; + public EntityPlayer localPlayer; + public String lookingDirection; + public World localWorld; + public ItemStack thisPickaxe = null; /* * @@ -33,7 +48,8 @@ public class StaballoyPickaxe extends ItemPickaxe{ @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer aPlayer) { localPlayer = aPlayer; - checkFacing(world); + localWorld = world; + thisPickaxe = stack; return super.onItemRightClick(stack, world, aPlayer); } @@ -42,80 +58,214 @@ public class StaballoyPickaxe extends ItemPickaxe{ @Override public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int X, int Y, int Z, EntityLivingBase entity) { //super.onBlockDestroyed(stack, world, block, X, Y, Z, entity); - - GetDestroyOrientation("FLAT, TOPDOWN OR BOTTOMUP", world, X, Y, Z); + localWorld = world; + thisPickaxe = stack; + //checkFacing(world); + if (!world.isRemote){ + GetDestroyOrientation(lookingDirection, world, X, Y, Z, stack); + } return super.onBlockDestroyed(stack, world, block, X, Y, Z, entity); } - - private void GetDestroyOrientation(String FACING, World world, int X, int Y, int Z){ - for(int i = -1; i < 2; i++) { - for(int j = -1; j < 2; j++) { - removeBlockAndDropAsItem(world, X + i, Y, Z + j, i, j); + + private float calculateDurabilityLoss(World world, int X, int Y, int Z){ + float bDurabilityLoss = 0; + Boolean correctTool = false; + float bHardness = 0; + if (!world.isRemote){ + try { + Block removalist = world.getBlock(X, Y, Z); + //Utils.LOG_WARNING(removalist.toString()); + + bHardness = removalist.getBlockHardness(world, X, Y, Z); + Utils.LOG_WARNING("Hardness: "+bHardness); + + bDurabilityLoss = (bDurabilityLoss + bHardness); + //Utils.LOG_WARNING("Durability Loss: "+bDurabilityLoss); + + correctTool = canPickaxeBlock(removalist, world); + Utils.LOG_WARNING(""+correctTool); + + if (!correctTool){ + return 0; + } + + } catch (NullPointerException e){ + } } + return bDurabilityLoss; + } + + public static Boolean canPickaxeBlock(Block currentBlock, World currentWorld){ + String correctTool = ""; + if (!currentWorld.isRemote){ + try { + correctTool = currentBlock.getHarvestTool(0); + //Utils.LOG_WARNING(correctTool); + if (MiningMethods.getBlockType(currentBlock) || correctTool.equals("pickaxe")){ + return true;} + } catch (NullPointerException e){ + return false;} + } + return false; + } + + private void GetDestroyOrientation(String FACING, World world, int X, int Y, int Z, ItemStack heldItem){ + localWorld = world; + float DURABILITY_LOSS = 0; + if (!world.isRemote){ + + if (FACING.equals("below") || FACING.equals("above")){ + DURABILITY_LOSS = 0; + for(int i = -2; i < 3; i++) { + for(int j = -2; j < 3; j++) { + float dur = calculateDurabilityLoss(world, X + i, Y, Z + j); + DURABILITY_LOSS = (DURABILITY_LOSS + calculateDurabilityLoss(world, X + i, Y, Z + j)); + Utils.LOG_WARNING("Added Loss: "+dur); + removeBlockAndDropAsItem(world, X + i, Y, Z + j, heldItem); + } + } + } + + else if (FACING.equals("facingEast") || FACING.equals("facingWest")){ + DURABILITY_LOSS = 0; + for(int i = -1; i < 2; i++) { + for(int j = -1; j < 2; j++) { + float dur = calculateDurabilityLoss(world, X, Y + i, Z + j); + DURABILITY_LOSS = (DURABILITY_LOSS + calculateDurabilityLoss(world, X, Y + i, Z + j)); + Utils.LOG_WARNING("Added Loss: "+dur); + removeBlockAndDropAsItem(world, X , Y + i, Z + j, heldItem); + } + } + } + + else if (FACING.equals("facingNorth") || FACING.equals("facingSouth")){ + DURABILITY_LOSS = 0; + for(int i = -1; i < 2; i++) { + for(int j = -1; j < 2; j++) { + float dur = calculateDurabilityLoss(world, X + j, Y + i, Z); + DURABILITY_LOSS = (DURABILITY_LOSS + dur); + Utils.LOG_WARNING("Added Loss: "+dur); + removeBlockAndDropAsItem(world, X + j, Y + i, Z, heldItem); + } + } + } + + //int heldItemDurability = heldItem.getDamage(1); + Utils.LOG_WARNING("Total Loss: "+(int)DURABILITY_LOSS); + //heldItem.setDamage(heldStack, DURABILITY_LOSS); + //Utils.LOG_WARNING("|GID|Durability: "+heldItem.getItemDamage()); + //Utils.LOG_WARNING("Durability: "+heldStack.getDamage(heldStack)); + if (heldItem.getItemDamage() < (heldItem.getMaxDamage()-DURABILITY_LOSS)){ + heldItem.damageItem((int) DURABILITY_LOSS, localPlayer); + } + //Utils.LOG_WARNING("|GID|Durability: "+heldItem.getItemDamage()); + DURABILITY_LOSS = 0; + + } + } + + public static int doDurabilityDamage(int x){ + + + return x; } //Should clear up blocks quicker if I chain it. @SuppressWarnings("static-method") - private void removeBlockAndDropAsItem(World world, int X, int Y, int Z, int i, int j){ - Block block = world.getBlock(X, Y, Z); - if((block != Blocks.bedrock) && (block.getBlockHardness(world, X, Y, Z) != -1)){ - block.dropBlockAsItem(world, X, Y, Z, world.getBlockMetadata(X, Y, Z), 0); - world.setBlockToAir(X, Y, Z); + private void removeBlockAndDropAsItem(World world, int X, int Y, int Z, ItemStack heldItem){ + localWorld = world; + try { + Block block = world.getBlock(X, Y, Z); + float dur = calculateDurabilityLoss(world, X, Y, Z); + Utils.LOG_WARNING(block.toString()); + String removalTool = ""; + removalTool = block.getHarvestTool(1); + + if (removalTool.equals("pickaxe") || MiningMethods.getBlockType(block)){ + 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)){ + + if (heldItem.getItemDamage() <= (heldItem.getMaxDamage()-dur)){ + + 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){ + } } - private boolean checkFacing(World world){ - if (!localPlayer.equals(null) || localPlayer != null || (!localPlayer.equals(null) && localPlayer != null)){ + public boolean checkFacing(World world){ + localWorld = world; + if (localPlayer != null){ int direction = MathHelper.floor_double((double)((localPlayer.rotationYaw * 4F) / 360F) + 0.5D) & 3; - //Utils.LOG_INFO("Player - F: "+direction); - Utils.LOG_INFO("Player - getLookVec(): "+localPlayer.getLookVec().yCoord); + //Utils.LOG_WARNING("Player - F: "+direction); + //Utils.LOG_WARNING("Player - getLookVec(): "+localPlayer.getLookVec().yCoord); /*if (localPlayer.getLookVec().yCoord > 0){ localPlayer.getLookVec().yCoord; }*/ MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, (EntityPlayer) localPlayer, false); - int sideHit = movingobjectposition.sideHit; - String playerStandingPosition; - if (movingobjectposition != null) { - System.out.println("Side Hit: "+movingobjectposition.sideHit); - } + if (movingobjectposition != null){ + int sideHit = movingobjectposition.sideHit; + String playerStandingPosition = ""; + if (movingobjectposition != null) { + //System.out.println("Side Hit: "+movingobjectposition.sideHit); + } - if (sideHit == 0){ - playerStandingPosition = "below"; - } - else if (sideHit == 1){ - playerStandingPosition = "above"; - } - else if (sideHit == 2){ - playerStandingPosition = "facingSouth"; - } - else if (sideHit == 3){ - playerStandingPosition = "facingNorth"; - } - else if (sideHit == 4){ - playerStandingPosition = "facingEast"; - } - else if (sideHit == 5){ - playerStandingPosition = "facingWest"; - } + if (sideHit == 0){ + playerStandingPosition = "above"; + FACING_HORIZONTAL = false; + } + else if (sideHit == 1){ + playerStandingPosition = "below"; + FACING_HORIZONTAL = false; + } + else if (sideHit == 2){ + playerStandingPosition = "facingSouth"; + FACING_HORIZONTAL = true; + } + else if (sideHit == 3){ + playerStandingPosition = "facingNorth"; + FACING_HORIZONTAL = true; + } + else if (sideHit == 4){ + playerStandingPosition = "facingEast"; + FACING_HORIZONTAL = true; + } + else if (sideHit == 5){ + playerStandingPosition = "facingWest"; + FACING_HORIZONTAL = true; + } + lookingDirection = playerStandingPosition; - if (direction == 0){ - FACING = "south"; - } - else if (direction == 1){ - FACING = "west"; - } - else if (direction == 2){ - FACING = "north"; - } - else if (direction == 3){ - FACING = "east"; + if (direction == 0){ + FACING = "south"; + } + else if (direction == 1){ + FACING = "west"; + } + else if (direction == 2){ + FACING = "north"; + } + else if (direction == 3){ + FACING = "east"; + } } - - + + + return true; } return false; } @@ -124,37 +274,32 @@ public class StaballoyPickaxe extends ItemPickaxe{ @Override public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) { String facing; + thisPickaxe = stack; + if (FACING_HORIZONTAL){ facing = "Horizontal"; } else { facing = "Vertical"; } - list.add("Mines a 3x3 area on the "+facing+" axis."); - - + list.add(EnumChatFormatting.GOLD+"Mines a 3x3 area on an axis. Currently Facing:"+facing); super.addInformation(stack, aPlayer, list, bool); } + @Override public boolean onBlockStartBreak(ItemStack itemstack, int X, int Y, int Z, EntityPlayer aPlayer) { - - localPlayer = aPlayer; - + thisPickaxe = itemstack; + localPlayer = aPlayer; + checkFacing(localPlayer.worldObj); return super.onBlockStartBreak(itemstack, X, Y, Z, aPlayer); } - public StaballoyPickaxe(String unlocalizedName, ToolMaterial material) { super(material); this.setUnlocalizedName(unlocalizedName); this.setTextureName(CORE.MODID + ":" + unlocalizedName); this.FACING_HORIZONTAL=true; + this.setMaxStackSize(1); + this.setMaxDamage(3200); } - - /*public boolean onBlockDestroyed(ItemStack stack, World w, int id, int x, int y, int z, EntityLiving entity){ - super.onBlockDestroyed(stack, w, , x, y, z, entity); - Block block = this. - - }*/ - } diff --git a/src/Java/miscutil/core/lib/CORE.java b/src/Java/miscutil/core/lib/CORE.java index 05e8fa75a3..d7b8ce9919 100644 --- a/src/Java/miscutil/core/lib/CORE.java +++ b/src/Java/miscutil/core/lib/CORE.java @@ -9,7 +9,7 @@ public class CORE { public static final String name = "Misc. Utils"; public static final String MODID = "miscutils"; public static final String VERSION = "0.9.8"; - public static final boolean DEBUG = false; + public static final boolean DEBUG = true; public static final boolean LOAD_ALL_CONTENT = false; public static final int GREG_FIRST_ID = 760; public static Map PlayerCache; diff --git a/src/Java/miscutil/core/util/MiningMethods.java b/src/Java/miscutil/core/util/MiningMethods.java new file mode 100644 index 0000000000..6f8042f800 --- /dev/null +++ b/src/Java/miscutil/core/util/MiningMethods.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 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/Utils.java b/src/Java/miscutil/core/util/Utils.java index ab60de8557..10375f3f8e 100644 --- a/src/Java/miscutil/core/util/Utils.java +++ b/src/Java/miscutil/core/util/Utils.java @@ -6,9 +6,12 @@ import java.awt.Graphics; import java.util.Random; import miscutil.core.lib.CORE; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import cpw.mods.fml.common.FMLLog; @@ -17,7 +20,7 @@ import cpw.mods.fml.common.registry.GameRegistry; public class Utils { public static final int WILDCARD_VALUE = Short.MAX_VALUE; - + /** * Returns a psuedo-random number between min and max, inclusive. * The difference between min and max can be at most @@ -30,90 +33,90 @@ public class Utils { */ public static int randInt(int min, int max) { - // Usually this can be a field rather than a method variable - Random rand = new Random(); + // Usually this can be a field rather than a method variable + Random rand = new Random(); - // nextInt is normally exclusive of the top value, - // so add 1 to make it inclusive - int randomNum = rand.nextInt((max - min) + 1) + min; + // nextInt is normally exclusive of the top value, + // so add 1 to make it inclusive + int randomNum = rand.nextInt((max - min) + 1) + min; - return randomNum; + return randomNum; } - + public static long randLong(long min, long max) { - // Usually this can be a field rather than a method variable - Random rand = new Random(); + // Usually this can be a field rather than a method variable + Random rand = new Random(); - // nextInt is normally exclusive of the top value, - // so add 1 to make it inclusive - long randomNum = nextLong(rand,(max - min) + 1) + min; + // nextInt is normally exclusive of the top value, + // so add 1 to make it inclusive + long randomNum = nextLong(rand,(max - min) + 1) + min; - return randomNum; + return randomNum; } - + private static long nextLong(Random rng, long n) { - // error checking and 2^x checking removed for simplicity. - long bits, val; - do { - bits = (rng.nextLong() << 1) >>> 1; - val = bits % n; - } while (bits-val+(n-1) < 0L); - return val; + // error checking and 2^x checking removed for simplicity. + long bits, val; + do { + bits = (rng.nextLong() << 1) >>> 1; + val = bits % n; + } while (bits-val+(n-1) < 0L); + return val; + } + + public static boolean containsMatch(boolean strict, ItemStack[] inputs, ItemStack... targets) + { + for (ItemStack input : inputs) + { + for (ItemStack target : targets) + { + if (itemMatches(target, input, strict)) + { + return true; + } + } } - - public static boolean containsMatch(boolean strict, ItemStack[] inputs, ItemStack... targets) - { - for (ItemStack input : inputs) - { - for (ItemStack target : targets) - { - if (itemMatches(target, input, strict)) - { - return true; - } - } - } - return false; - } - - public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict) - { - if (input == null && target != null || input != null && target == null) - { - return false; - } - return (target.getItem() == input.getItem() && ((target.getItemDamage() == WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage())); - } - - //Non-Dev Comments - public static void LOG_INFO(String s){ - //if (CORE.DEBUG){ - FMLLog.info("MiscUtils: "+s); + return false; + } + + public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict) + { + if (input == null && target != null || input != null && target == null) + { + return false; + } + return (target.getItem() == input.getItem() && ((target.getItemDamage() == WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage())); + } + + //Non-Dev Comments + public static void LOG_INFO(String s){ + //if (CORE.DEBUG){ + FMLLog.info("MiscUtils: "+s); //} - } - - //Developer Comments - public static void LOG_WARNING(String s){ - if (CORE.DEBUG){ + } + + //Developer Comments + public static void LOG_WARNING(String s){ + if (CORE.DEBUG){ FMLLog.warning("MiscUtils: "+s); } - } - - //Errors - public static void LOG_ERROR(String s){ - if (CORE.DEBUG){ + } + + //Errors + public static void LOG_ERROR(String s){ + if (CORE.DEBUG){ FMLLog.severe("MiscUtils: "+s); } - } - - public static void paintBox(Graphics g, int MinA, int MinB, int MaxA, int MaxB){ - g.drawRect (MinA, MinB, MaxA, MaxB); - } - - public static void messagePlayer(EntityPlayer P, String S){ - gregtech.api.util.GT_Utility.sendChatToPlayer(P, S); - } - + } + + public static void paintBox(Graphics g, int MinA, int MinB, int MaxA, int MaxB){ + g.drawRect (MinA, MinB, MaxA, MaxB); + } + + public static void messagePlayer(EntityPlayer P, String S){ + gregtech.api.util.GT_Utility.sendChatToPlayer(P, S); + } + /** * Returns if that Liquid is IC2Steam. */ @@ -121,7 +124,7 @@ public class Utils { if (aFluid == null) return F; return aFluid.isFluidEqual(getIC2Steam(1)); } - + /** * Returns a Liquid Stack with given amount of IC2Steam. */ @@ -131,9 +134,52 @@ public class Utils { public static Item getItem(String fqrn) // fqrn = fully qualified resource name { - String[] fqrnSplit = fqrn.split(":"); - return GameRegistry.findItem(fqrnSplit[0], fqrnSplit[1]); + String[] fqrnSplit = fqrn.split(":"); + return GameRegistry.findItem(fqrnSplit[0], fqrnSplit[1]); + } + + public static Item getItemInPlayersHand(){ + Minecraft mc = Minecraft.getMinecraft(); + Item heldItem = null; + + try{heldItem = mc.thePlayer.getHeldItem().getItem(); + }catch(NullPointerException e){return null;} + + if (heldItem != null){ + return heldItem; + } + + return null; + } + + public static void recipeBuilderBlock(ItemStack slot_1, ItemStack slot_2, ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Block resultBlock){ + GameRegistry.addRecipe( + new ItemStack(resultBlock), + slot_1, slot_2, slot_3, + slot_4, slot_5, slot_6, + slot_7, slot_8, slot_9); + } + + public static void recipeBuilderItem(ItemStack slot_1, ItemStack slot_2, ItemStack slot_3, ItemStack slot_4, ItemStack slot_5, ItemStack slot_6, ItemStack slot_7, ItemStack slot_8, ItemStack slot_9, Item resultItem){ + GameRegistry.addRecipe( + new ItemStack(resultItem), + slot_1, slot_2, slot_3, + slot_4, slot_5, slot_6, + slot_7, slot_8, slot_9); } - + public static String checkCorrectMiningToolForBlock(Block currentBlock, World currentWorld){ + String correctTool = ""; + if (!currentWorld.isRemote){ + try { + correctTool = currentBlock.getHarvestTool(0); + Utils.LOG_WARNING(correctTool); + + } catch (NullPointerException e){ + + } + } + + return correctTool; + } } |