From 6e1b608113017817bbaf4161c942439cadf590a5 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 29 Mar 2018 11:29:01 +0100 Subject: [PATCH] Improve power handling with drill and chainsaw --- .../items/tools/ItemAdvancedChainsaw.java | 5 ++++- .../items/tools/ItemAdvancedDrill.java | 16 +++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/techreborn/items/tools/ItemAdvancedChainsaw.java b/src/main/java/techreborn/items/tools/ItemAdvancedChainsaw.java index fb40f7fea..6824c7f5e 100644 --- a/src/main/java/techreborn/items/tools/ItemAdvancedChainsaw.java +++ b/src/main/java/techreborn/items/tools/ItemAdvancedChainsaw.java @@ -79,7 +79,6 @@ public class ItemAdvancedChainsaw extends ItemChainsaw { return Items.DIAMOND_AXE.canHarvestBlock(blockIn); } - @SuppressWarnings("deprecation") public void breakBlock(BlockPos pos, ItemStack stack, World world, EntityLivingBase entityLiving, BlockPos oldPos) { if (oldPos == pos) { @@ -95,6 +94,10 @@ public class ItemAdvancedChainsaw extends ItemChainsaw { if(!(entityLiving instanceof EntityPlayer)){ return; } + if(!PoweredItem.canUseEnergy(cost, stack)){ + return; + } + PoweredItem.useEnergy(cost, stack); blockState.getBlock().harvestBlock(world, (EntityPlayer) entityLiving, pos, blockState, world.getTileEntity(pos), stack); world.setBlockToAir(pos); world.removeTileEntity(pos); diff --git a/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java b/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java index 559dad068..5ed9f4915 100644 --- a/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java +++ b/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java @@ -49,7 +49,7 @@ import java.util.Set; public class ItemAdvancedDrill extends ItemDrill { public ItemAdvancedDrill() { - super(ToolMaterial.DIAMOND, "techreborn.advancedDrill", ConfigTechReborn.AdvancedDrillCharge, 4.0F, 10F); + super(ToolMaterial.DIAMOND, "techreborn.advancedDrill", ConfigTechReborn.AdvancedDrillCharge, 2.0F, 10F); this.cost = 250; } @@ -110,6 +110,10 @@ public class ItemAdvancedDrill extends ItemDrill { if(blockState.getMaterial() == Material.AIR){ return; } + if(!PoweredItem.canUseEnergy(cost, drill)){ + return; + } + PoweredItem.useEnergy(cost, drill); blockState.getBlock().harvestBlock(world, playerIn, pos, blockState, world.getTileEntity(pos), drill); world.setBlockToAir(pos); world.removeTileEntity(pos); @@ -118,12 +122,10 @@ public class ItemAdvancedDrill extends ItemDrill { // ItemDrill @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) { - if (PoweredItem.canUseEnergy(cost, stack)) { - EntityPlayer playerIn = (EntityPlayer) entityLiving; - float originalHardness = blockIn.getPlayerRelativeBlockHardness(playerIn, worldIn, pos); - for (BlockPos additionalPos : getTargetBlocks(worldIn, pos, entityLiving)) { - breakBlock(additionalPos, worldIn, playerIn, pos, originalHardness, stack); - } + EntityPlayer playerIn = (EntityPlayer) entityLiving; + float originalHardness = blockIn.getPlayerRelativeBlockHardness(playerIn, worldIn, pos); + for (BlockPos additionalPos : getTargetBlocks(worldIn, pos, entityLiving)) { + breakBlock(additionalPos, worldIn, playerIn, pos, originalHardness, stack); } // Use energy only once no matter how many blocks were broken, e.g. energy used per application of a drill return super.onBlockDestroyed(stack, worldIn, blockIn, pos, entityLiving);