diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-03-25 01:47:09 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-03-25 01:47:09 +1000 |
commit | 6e2d7b787d2338fd6e35532f91e6ff6a48eed682 (patch) | |
tree | 664c2caeb0a6b9fcc18bfd53a9d7a4afd7bee74b /src/Java/miscutil/core/item | |
parent | 46590e0c7b1f874c368f9ac335b4333222723c1e (diff) | |
download | GT5-Unofficial-6e2d7b787d2338fd6e35532f91e6ff6a48eed682.tar.gz GT5-Unofficial-6e2d7b787d2338fd6e35532f91e6ff6a48eed682.tar.bz2 GT5-Unofficial-6e2d7b787d2338fd6e35532f91e6ff6a48eed682.zip |
Pickaxe should be rather 100% now.
Final commit before new builds.
Diffstat (limited to 'src/Java/miscutil/core/item')
-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 |
2 files changed, 241 insertions, 70 deletions
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. - - }*/ - } |