-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHoeItem.java
More file actions
63 lines (53 loc) · 2.3 KB
/
HoeItem.java
File metadata and controls
63 lines (53 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package gregtech.common.tools;
import alexiil.mc.lib.attributes.Simulation;
import com.mojang.datafixers.util.Pair;
import gregtech.api.capability.item.CustomDamageItem;
import gregtech.api.items.toolitem.MiningToolItem;
import gregtech.api.items.toolitem.ToolItemSettings;
import gregtech.api.items.toolitem.ToolItemType;
import gregtech.api.unification.material.Material;
import gregtech.mixin.accessor.HoeItemAccessor;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.Items;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.tag.BlockTags;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.function.Consumer;
import java.util.function.Predicate;
public class HoeItem extends MiningToolItem {
public HoeItem(ToolItemSettings settings, ToolItemType toolItemType, Material material) {
super(settings, toolItemType, material, BlockTags.HOE_MINEABLE);
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
BlockPos blockPos = context.getBlockPos();
BlockState blockState = world.getBlockState(blockPos);
PlayerEntity playerEntity = context.getPlayer();
if (!canDamageItem(context.getStack(), this.damagePerSpecialAction, playerEntity)) {
return ActionResult.PASS;
}
if (playerEntity == null) {
return ActionResult.PASS;
}
Pair<Predicate<ItemUsageContext>, Consumer<ItemUsageContext>> pair =
((HoeItemAccessor) Items.IRON_HOE).getTilledBlocks().get(blockState.getBlock());
if (pair == null) {
return ActionResult.PASS;
}
if (pair.getFirst().test(context)) {
world.playSound(playerEntity, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (!world.isClient) {
pair.getSecond().accept(context);
CustomDamageItem.damageItem(playerEntity, context.getHand(), damagePerSpecialAction, Simulation.ACTION);
}
return ActionResult.SUCCESS;
}
return ActionResult.PASS;
}
}