-
Notifications
You must be signed in to change notification settings - Fork 497
/
StripesHandlerShears.java
60 lines (49 loc) · 1.76 KB
/
StripesHandlerShears.java
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
package buildcraft.transport.stripes;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.transport.IStripesActivator;
import buildcraft.api.transport.IStripesHandler;
public class StripesHandlerShears implements IStripesHandler {
@Override
public StripesHandlerType getType() {
return StripesHandlerType.ITEM_USE;
}
@Override
public boolean shouldHandle(ItemStack stack) {
return stack.getItem() instanceof ItemShears;
}
@Override
public boolean handle(World world, int x, int y, int z,
ForgeDirection direction, ItemStack stack, EntityPlayer player,
IStripesActivator activator) {
Block block = world.getBlock(x, y, z);
if (block instanceof IShearable) {
IShearable shearableBlock = (IShearable) block;
if (shearableBlock.isShearable(stack, world, x, y, z)) {
world.playSoundEffect(x, y, z, Block.soundTypeGrass.getBreakSound(), 1, 1);
List<ItemStack> drops = shearableBlock.onSheared(stack, world, x, y, z,
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
world.setBlockToAir(x, y, z);
if (stack.attemptDamageItem(1, player.getRNG())) {
stack.stackSize--;
}
if (stack.stackSize > 0) {
activator.sendItem(stack, direction.getOpposite());
}
for (ItemStack dropStack : drops) {
activator.sendItem(dropStack, direction.getOpposite());
}
return true;
}
}
return false;
}
}