Skip to content

Commit

Permalink
Fix GT Shovels not making paths
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Feb 25, 2022
1 parent b432f7e commit 40b9e14
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/main/java/gregtech/common/items/behaviors/ShovelBehavior.java
Original file line number Diff line number Diff line change
@@ -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<ItemStack> 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);
}
}
}
}
1 change: 1 addition & 0 deletions src/main/java/gregtech/common/tools/DamageValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions src/main/java/gregtech/common/tools/ToolShovel.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<String> getToolClasses(ItemStack stack) {
return SHOVEL_TOOL_CLASSES;
Expand Down

0 comments on commit 40b9e14

Please sign in to comment.