From 7347b3f58bdf1db5a7e6bf62344ba6b95bdcf567 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Fri, 16 Apr 2021 23:51:17 +0200 Subject: [PATCH] force pick and shovel now have area mode --- .../dartcraft/item/tool/ItemForcePickaxe.java | 46 +++++++++ .../dartcraft/item/tool/ItemForceShovel.java | 96 +++++++++++++++---- 2 files changed, 121 insertions(+), 21 deletions(-) diff --git a/src/main/java/ley/modding/dartcraft/item/tool/ItemForcePickaxe.java b/src/main/java/ley/modding/dartcraft/item/tool/ItemForcePickaxe.java index b844413..7ce69c5 100644 --- a/src/main/java/ley/modding/dartcraft/item/tool/ItemForcePickaxe.java +++ b/src/main/java/ley/modding/dartcraft/item/tool/ItemForcePickaxe.java @@ -10,6 +10,7 @@ import ley.modding.dartcraft.item.DartItems; import ley.modding.dartcraft.util.ForceConsumerUtils; import ley.modding.dartcraft.util.ForceUpgradeManager; import ley.modding.dartcraft.util.Util; +import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; @@ -123,4 +124,49 @@ public class ItemForcePickaxe extends ItemPickaxe implements IBreakable, IForceC return new int[] { ForceUpgradeManager.HEAT.getID(), ForceUpgradeManager.SPEED.getID(), ForceUpgradeManager.LUCK.getID(), ForceUpgradeManager.TOUCH.getID(), ForceUpgradeManager.STURDY.getID(), ForceUpgradeManager.GRINDING.getID(), ForceUpgradeManager.REPAIR.getID(), ForceUpgradeManager.IMPERVIOUS.getID() }; } + @Override + public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) { + World world = player.worldObj; + Block tempBlock = world.getBlock(x, y, z); + boolean force = false; + if(!this.canHarvestBlock(tempBlock, stack)) { + return false; + } else { + if(stack.hasTagCompound() && stack.getTagCompound().getBoolean("active")) { + force = true; + } + + if(force) { + for(int i = -1; i < 2; ++i) { + for(int j = -1; j < 2; ++j) { + for(int k = -1; k < 2; ++k) { + if(i != 0 || j != 0 || k != 0) { + if(stack == null || stack.getItemDamage() >= stack.getMaxDamage()) { + return false; + } + + this.tryBlock(stack, x + i, y + j, z + k, player); + } + } + } + } + } + + if (stack != null && stack.getItemDamage() < stack.getMaxDamage()) + this.tryBlock(stack, x, y, z, player); + + return false; + } + } + + public void tryBlock(ItemStack stack, int x, int y, int z, EntityPlayer player) { + World world = player.worldObj; + Block block = world.getBlock(x, y, z); + + if (this.canHarvestBlock(block, stack) && block.getBlockHardness(world, x, y, z) > 0F & world.getTileEntity(x, y, z) == null) { + world.getBlock(x, y, z).harvestBlock(world, player, x, y, z, world.getBlockMetadata(x, y, z)); + world.setBlockToAir(x, y, z); + stack.damageItem(1, player); + } + } } diff --git a/src/main/java/ley/modding/dartcraft/item/tool/ItemForceShovel.java b/src/main/java/ley/modding/dartcraft/item/tool/ItemForceShovel.java index 1001c69..6624dcf 100644 --- a/src/main/java/ley/modding/dartcraft/item/tool/ItemForceShovel.java +++ b/src/main/java/ley/modding/dartcraft/item/tool/ItemForceShovel.java @@ -6,6 +6,8 @@ import ley.modding.dartcraft.api.IForceConsumer; import ley.modding.dartcraft.item.DartItems; import ley.modding.dartcraft.util.ForceConsumerUtils; import ley.modding.dartcraft.util.Util; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemSpade; import net.minecraft.item.ItemStack; @@ -20,10 +22,10 @@ public class ItemForceShovel extends ItemSpade implements IBreakable, IForceCons private static int toolLevel = 10; public static ToolMaterial material = EnumHelper.addToolMaterial("FORCE", toolLevel, 512, efficiency, (float) damage, 0); - public ItemForceShovel() { - super(material); + public ItemForceShovel() { + super(material); Util.configureItem(this, "forceshovel"); - } + } @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { @@ -43,33 +45,85 @@ public class ItemForceShovel extends ItemSpade implements IBreakable, IForceCons return stack; } - @Override - public int getStored(ItemStack stack) { + @Override + public int getStored(ItemStack stack) { return ForceConsumerUtils.getStoredForce(stack); - } + } - @Override - public int getMaxStored(ItemStack var1) { - return 10000; - } + @Override + public int getMaxStored(ItemStack var1) { + return 10000; + } - @Override - public int amountUsedBase(ItemStack var1) { - return 0; - } + @Override + public int amountUsedBase(ItemStack var1) { + return 0; + } - @Override - public boolean useForce(ItemStack var1, int var2, boolean var3) { - return false; - } + @Override + public boolean useForce(ItemStack var1, int var2, boolean var3) { + return false; + } - @Override - public boolean attemptRepair(ItemStack stack) { + @Override + public boolean attemptRepair(ItemStack stack) { return ForceConsumerUtils.attemptRepair(stack); - } + } @Override public ItemStack itemReturned() { return new ItemStack(DartItems.forceshard); } + + @Override + public boolean canHarvestBlock(Block block, ItemStack itemStack) { + return block.getMaterial() == Material.clay || block.getMaterial() == Material.craftedSnow || block.getMaterial() == Material.ground || block.getMaterial() == Material.sand || block.getMaterial() == Material.snow || block.getMaterial() == Material.grass; + } + + @Override + public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) { + World world = player.worldObj; + Block tempBlock = world.getBlock(x, y, z); + boolean force = false; + + if(!this.canHarvestBlock(tempBlock, stack)) { + return false; + } else { + if(stack.hasTagCompound() && stack.getTagCompound().getBoolean("active")) { + force = true; + } + + if(force) { + for(int i = -1; i < 2; ++i) { + for(int j = -1; j < 2; ++j) { + for(int k = -1; k < 2; ++k) { + if(i != 0 || j != 0 || k != 0) { + if(stack == null || stack.getItemDamage() >= stack.getMaxDamage()) { + return false; + } + + this.tryBlock(stack, x + i, y + j, z + k, player); + } + } + } + } + } + + if (stack != null && stack.getItemDamage() < stack.getMaxDamage()) + this.tryBlock(stack, x, y, z, player); + + return false; + } + } + + public void tryBlock(ItemStack stack, int x, int y, int z, EntityPlayer player) { + World world = player.worldObj; + Block block = world.getBlock(x, y, z); + + if (this.canHarvestBlock(block, stack) && block.getBlockHardness(world, x, y, z) > 0F & world.getTileEntity(x, y, z) == null) { + world.getBlock(x, y, z).harvestBlock(world, player, x, y, z, world.getBlockMetadata(x, y, z)); + world.setBlockToAir(x, y, z); + stack.damageItem(1, player); + } + } }