-
Notifications
You must be signed in to change notification settings - Fork 497
/
StripesHandlerBucket.java
82 lines (68 loc) · 2.46 KB
/
StripesHandlerBucket.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package buildcraft.transport.stripes;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.transport.IStripesActivator;
import buildcraft.api.transport.IStripesHandler;
import buildcraft.core.lib.utils.BlockUtils;
public class StripesHandlerBucket implements IStripesHandler {
private static final ItemStack emptyBucket = new ItemStack(Items.bucket, 1);
private ItemStack getFilledBucket(FluidStack fluidStack, Block underblock) {
if (underblock == Blocks.lava) {
return new ItemStack(Items.lava_bucket, 1);
} else if (underblock == Blocks.water) {
return new ItemStack(Items.water_bucket, 1);
} else {
return FluidContainerRegistry.fillFluidContainer(fluidStack, emptyBucket);
}
}
@Override
public StripesHandlerType getType() {
return StripesHandlerType.ITEM_USE;
}
@Override
public boolean shouldHandle(ItemStack stack) {
return stack.getItem() instanceof ItemBucket;
}
@Override
public boolean handle(World world, int x, int y, int z,
ForgeDirection direction, ItemStack stack, EntityPlayer player,
IStripesActivator activator) {
if (world.isAirBlock(x, y, z)) {
Block underblock = world.getBlock(x, y - 1, z);
if (((ItemBucket) stack.getItem()).tryPlaceContainedLiquid(world, x, y - 1, z)) {
activator.sendItem(emptyBucket, direction.getOpposite());
stack.stackSize--;
if (stack.stackSize > 0) {
activator.sendItem(stack, direction.getOpposite());
}
return true;
} else {
if (!FluidContainerRegistry.isEmptyContainer(stack)) {
activator.sendItem(stack, direction.getOpposite());
return true;
}
FluidStack fluidStack = BlockUtils.drainBlock(underblock, world, x, y - 1, z, true);
ItemStack filledBucket = getFilledBucket(fluidStack, underblock);
if (fluidStack == null || filledBucket == null) {
activator.sendItem(stack, direction.getOpposite());
return true;
}
activator.sendItem(filledBucket, direction.getOpposite());
stack.stackSize--;
if (stack.stackSize > 0) {
activator.sendItem(stack, direction.getOpposite());
}
return true;
}
}
return false;
}
}