From 40b9e14d931f241d6968d445f3ec27801bda9705 Mon Sep 17 00:00:00 2001 From: DStrand1 Date: Thu, 24 Feb 2022 18:28:03 -0600 Subject: [PATCH] Fix GT Shovels not making paths --- .../items/behaviors/ShovelBehavior.java | 44 +++++++++++++++++++ .../gregtech/common/tools/DamageValues.java | 1 + .../gregtech/common/tools/ToolShovel.java | 7 +++ 3 files changed, 52 insertions(+) create mode 100644 src/main/java/gregtech/common/items/behaviors/ShovelBehavior.java diff --git a/src/main/java/gregtech/common/items/behaviors/ShovelBehavior.java b/src/main/java/gregtech/common/items/behaviors/ShovelBehavior.java new file mode 100644 index 00000000000..488e1a59834 --- /dev/null +++ b/src/main/java/gregtech/common/items/behaviors/ShovelBehavior.java @@ -0,0 +1,44 @@ +package gregtech.common.items.behaviors; + +import gregtech.api.items.metaitem.stats.IItemBehaviour; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.init.SoundEvents; +import net.minecraft.item.ItemStack; +import net.minecraft.util.*; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class ShovelBehavior implements IItemBehaviour { + + private final int cost; + + public ShovelBehavior(int cost) { + this.cost = cost; + } + + @Override + public ActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + ItemStack itemstack = player.getHeldItem(hand); + if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack)) { + return ActionResult.newResult(EnumActionResult.FAIL, itemstack); + } else { + IBlockState iblockstate = world.getBlockState(pos); + Block block = iblockstate.getBlock(); + if (facing != EnumFacing.DOWN && world.getBlockState(pos.up()).getMaterial() == Material.AIR && block == Blocks.GRASS) { + IBlockState state = Blocks.GRASS_PATH.getDefaultState(); + world.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F); + if (!world.isRemote) { + world.setBlockState(pos, state, 11); + itemstack.damageItem(cost, player); + } + return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack); + } else { + return ActionResult.newResult(EnumActionResult.PASS, itemstack); + } + } + } +} diff --git a/src/main/java/gregtech/common/tools/DamageValues.java b/src/main/java/gregtech/common/tools/DamageValues.java index 3f7c2088c7e..5ffe6160339 100644 --- a/src/main/java/gregtech/common/tools/DamageValues.java +++ b/src/main/java/gregtech/common/tools/DamageValues.java @@ -9,4 +9,5 @@ public class DamageValues { public static final int DAMAGE_FOR_HAMMER = 3; public static final int DAMAGE_FOR_HOE = 2; public static final int DAMAGE_FOR_PLUNGER = 1; + public static final int DAMAGE_FOR_SHOVEL = 1; } diff --git a/src/main/java/gregtech/common/tools/ToolShovel.java b/src/main/java/gregtech/common/tools/ToolShovel.java index 75ffd98d268..365ca7cce50 100644 --- a/src/main/java/gregtech/common/tools/ToolShovel.java +++ b/src/main/java/gregtech/common/tools/ToolShovel.java @@ -1,5 +1,7 @@ package gregtech.common.tools; +import gregtech.api.items.metaitem.MetaItem.MetaValueItem; +import gregtech.common.items.behaviors.ShovelBehavior; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.enchantment.Enchantment; @@ -53,6 +55,11 @@ public boolean canMineBlock(IBlockState block, ItemStack stack) { block.getMaterial() == Material.CLAY; } + @Override + public void onStatsAddedToTool(MetaValueItem item) { + item.addComponents(new ShovelBehavior(DamageValues.DAMAGE_FOR_SHOVEL)); + } + @Override public Set getToolClasses(ItemStack stack) { return SHOVEL_TOOL_CLASSES;