-
Notifications
You must be signed in to change notification settings - Fork 497
/
BlockTank.java
258 lines (222 loc) · 10.4 KB
/
BlockTank.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
* <p/>
* BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents
* of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */
package buildcraft.factory;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import buildcraft.api.transport.ICustomPipeConnection;
import buildcraft.core.BCCreativeTab;
import buildcraft.core.lib.block.BlockBuildCraft;
import buildcraft.core.lib.block.TileBuildCraft;
public class BlockTank extends BlockBuildCraft implements ICustomPipeConnection {
private static final boolean DEBUG_MODE = false;
public BlockTank() {
super(Material.glass, JOINED_BELOW);
setHardness(0.5F);
setCreativeTab(BCCreativeTab.get("main"));
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
TileEntity tile = world.getTileEntity(pos);
if (tile != null && tile instanceof TileBuildCraft) {
TileTank tank = (TileTank) tile;
tank.onBlockBreak();
}
TileEntity tileAbove = world.getTileEntity(pos.up());
TileEntity tileBelow = world.getTileEntity(pos.down());
super.breakBlock(world, pos, state);
if (tileAbove instanceof TileBuildCraft) {
((TileTank) tileAbove).updateComparators();
world.setBlockState(pos.up(), world.getBlockState(pos.up()).withProperty(JOINED_BELOW, false));
}
if (tileBelow instanceof TileBuildCraft) {
((TileTank) tileBelow).updateComparators();
}
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, entity, stack);
IBlockState stateAbove = world.getBlockState(pos.up());
IBlockState stateBelow = world.getBlockState(pos.down());
if (stateAbove.getBlock() == this) {
world.setBlockState(pos.up(), stateAbove.withProperty(JOINED_BELOW, true));
}
if (stateBelow.getBlock() == this) {
world.setBlockState(pos, state.withProperty(JOINED_BELOW, true));
}
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean isFullCube() {
return false;
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileTank();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityplayer, EnumFacing side, float par7, float par8,
float par9) {
if (super.onBlockActivated(world, pos, state, entityplayer, side, par7, par8, par9)) {
return true;
}
ItemStack current = entityplayer.inventory.getCurrentItem();
if (current != null) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBuildCraft) {
TileTank tank = (TileTank) tile;
if (FluidUtil.interactWithTank(current, entityplayer, tank, side)) {
return true;
}
return false;
// // Handle FluidContainerRegistry
// if (FluidContainerRegistry.isContainer(current)) {
// FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
// // Handle filled containers
// if (liquid != null) {
// int qty = tank.fill(null, liquid, true);
//
// if (qty != 0 && !BuildCraftCore.debugWorldgen && !entityplayer.capabilities.isCreativeMode) {
// if (current.stackSize > 1) {
// if (!entityplayer.inventory.addItemStackToInventory(FluidContainerRegistry.drainFluidContainer(current))) {
// entityplayer.dropPlayerItemWithRandomChoice(FluidContainerRegistry.drainFluidContainer(current), false);
// }
//
// entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current));
// } else {
// entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, FluidContainerRegistry
// .drainFluidContainer(current));
// }
// }
//
// return true;
//
// // Handle empty containers
// } else {
// FluidStack available = tank.getTankInfo(null)[0].fluid;
//
// if (available != null) {
// ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
//
// liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
//
// if (liquid != null) {
// if (!BuildCraftCore.debugWorldgen && !entityplayer.capabilities.isCreativeMode) {
// if (current.stackSize > 1) {
// if (!entityplayer.inventory.addItemStackToInventory(filled)) {
// return false;
// } else {
// entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(
// current));
// }
// } else {
// entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(
// current));
// entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled);
// }
// }
//
// tank.drain(null, liquid.amount, true);
//
// return true;
// }
// }
// }
// } else if (current.getItem() instanceof IFluidContainerItem) {
// if (current.stackSize != 1) {
// return false;
// }
//
// if (!world.isRemote) {
// IFluidContainerItem container = (IFluidContainerItem) current.getItem();
// FluidStack liquid = container.getFluid(current);
// FluidStack tankLiquid = tank.getTankInfo(null)[0].fluid;
// boolean mustDrain = liquid == null || liquid.amount == 0;
// boolean mustFill = tankLiquid == null || tankLiquid.amount == 0;
// if (mustDrain && mustFill) {
// // Both are empty, do nothing
// } else if (mustDrain || !entityplayer.isSneaking()) {
// liquid = tank.drain(null, 1000, false);
// int qtyToFill = container.fill(current, liquid, true);
// tank.drain(null, qtyToFill, true);
// } else if (mustFill || entityplayer.isSneaking()) {
// if (liquid != null && liquid.amount > 0) {
// int qty = tank.fill(null, liquid, false);
// tank.fill(null, container.drain(current, qty, true), true);
// }
// }
// }
//
// return true;
// }
}
} else if (DEBUG_MODE) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBuildCraft) {
TileTank tank = (TileTank) tile;
if (tank.getTankInfo(null)[0].fluid != null) {
entityplayer.addChatComponentMessage(new ChatComponentText("Amount: " + tank.getTankInfo(null)[0].fluid.amount + " mB"));
}
}
}
return false;
}
@Override
public boolean shouldSideBeRendered(IBlockAccess world, BlockPos pos, EnumFacing side) {
if (side.getAxis() == EnumFacing.Axis.Y) {
return world.getBlockState(pos).getBlock() != this;
} else {
return super.shouldSideBeRendered(world, pos, side);
}
}
@Override
public int getLightValue(IBlockAccess world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBuildCraft) {
TileTank tank = (TileTank) tile;
return tank.getFluidLightLevel();
}
return super.getLightValue(world, pos);
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileBuildCraft) {
TileTank tank = (TileTank) tile;
return tank.getComparatorInputOverride();
}
return 0;
}
@Override
@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer() {
return EnumWorldBlockLayer.CUTOUT;
}
@Override
public AxisAlignedBB getBox(IBlockAccess world, BlockPos pos, IBlockState state) {
return new AxisAlignedBB(2 / 16f, 0F, 2 / 16f, 14 / 16f, 1F, 14 / 16f);
}
@Override
public float getExtension(World world, BlockPos pos, EnumFacing face, IBlockState state) {
return face.getAxis() != Axis.Y ? 2 / 16f : 0;
}
}