use of buildcraft.transport.pipe.Pipe in project BuildCraft by BuildCraft.
the class TilePipeHolder method readFromNBT.
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
if (nbt.hasKey("pipe")) {
try {
pipe = new Pipe(this, nbt.getCompoundTag("pipe"));
eventBus.registerHandler(pipe.behaviour);
eventBus.registerHandler(pipe.flow);
if (pipe.flow instanceof IFlowItems) {
eventBus.registerHandler(FilterEventHandler.class);
}
} catch (InvalidInputDataException e) {
// Unfortunately we can't throw an exception because then this tile won't persist :/
e.printStackTrace();
unknownData = nbt.copy();
}
}
NBTTagCompound plugs = nbt.getCompoundTag("plugs");
for (EnumFacing face : EnumFacing.VALUES) {
pluggables.get(face).readFromNbt(plugs.getCompoundTag(face.getName()));
}
wireManager.readFromNbt(nbt.getCompoundTag("wireManager"));
if (nbt.hasKey("redstone")) {
int[] temp = nbt.getIntArray("redstone");
if (temp.length == 6) {
redstoneValues = temp;
}
}
}
use of buildcraft.transport.pipe.Pipe in project BuildCraft by BuildCraft.
the class TilePipeHolder method readPayload.
@Override
public void readPayload(int id, PacketBufferBC buffer, Side side, MessageContext ctx) throws IOException {
super.readPayload(id, buffer, side, ctx);
if (side == Side.CLIENT) {
if (id == NET_RENDER_DATA) {
if (buffer.readBoolean()) {
pipe = new Pipe(this, buffer, ctx);
eventBus.registerHandler(pipe.behaviour);
eventBus.registerHandler(pipe.flow);
if (pipe.flow instanceof IFlowItems) {
eventBus.registerHandler(FilterEventHandler.class);
}
} else if (pipe != null) {
eventBus.unregisterHandler(pipe.behaviour);
eventBus.unregisterHandler(pipe.flow);
pipe = null;
}
for (EnumFacing face : EnumFacing.VALUES) {
pluggables.get(face).readCreationPayload(buffer);
}
wireManager.readPayload(buffer, side, ctx);
} else if (id == NET_UPDATE_MULTI) {
int total = buffer.readUnsignedByte();
for (PipeMessageReceiver type : PipeMessageReceiver.VALUES) {
if (((total >> type.ordinal()) & 1) == 1) {
readPayload(getReceiverId(type), buffer, side, ctx);
}
}
} else if (id == NET_UPDATE_PIPE_BEHAVIOUR) {
if (buffer.readBoolean()) {
if (pipe == null) {
throw new IllegalStateException("Pipe was null when it shouldn't have been!");
} else {
pipe.readPayload(buffer, side, ctx);
}
}
} else if (id == NET_UPDATE_WIRES) {
wireManager.readPayload(buffer, side, ctx);
}
}
if (id == NET_UPDATE_PIPE_FLOW) {
if (buffer.readBoolean()) {
if (pipe == null) {
throw new IllegalStateException("Pipe was null when it shouldn't have been!");
} else {
int fId = buffer.readShort();
pipe.flow.readPayload(fId, buffer, side);
}
}
} else if (id == NET_UPDATE_PLUG_DOWN)
pluggables.get(EnumFacing.DOWN).readPayload(buffer, side, ctx);
else if (id == NET_UPDATE_PLUG_UP)
pluggables.get(EnumFacing.UP).readPayload(buffer, side, ctx);
else if (id == NET_UPDATE_PLUG_NORTH)
pluggables.get(EnumFacing.NORTH).readPayload(buffer, side, ctx);
else if (id == NET_UPDATE_PLUG_SOUTH)
pluggables.get(EnumFacing.SOUTH).readPayload(buffer, side, ctx);
else if (id == NET_UPDATE_PLUG_WEST)
pluggables.get(EnumFacing.WEST).readPayload(buffer, side, ctx);
else if (id == NET_UPDATE_PLUG_EAST)
pluggables.get(EnumFacing.EAST).readPayload(buffer, side, ctx);
}
use of buildcraft.transport.pipe.Pipe in project BuildCraft by BuildCraft.
the class BlockPipeHolder method getDrops.
@Override
public void getDrops(NonNullList<ItemStack> toDrop, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
TilePipeHolder tile = getPipe(world, pos, false);
for (EnumFacing face : EnumFacing.VALUES) {
PipePluggable pluggable = tile.getPluggable(face);
if (pluggable != null) {
pluggable.addDrops(toDrop, fortune);
}
}
for (EnumDyeColor color : tile.wireManager.parts.values()) {
toDrop.add(new ItemStack(BCTransportItems.wire, 1, color.getMetadata()));
}
Pipe pipe = tile.getPipe();
if (pipe != null) {
pipe.addDrops(toDrop, fortune);
}
}
use of buildcraft.transport.pipe.Pipe in project BuildCraft by BuildCraft.
the class BlockPipeHolder method rayTrace.
@Nullable
public RayTraceResult rayTrace(World world, BlockPos pos, Vec3d start, Vec3d end) {
TilePipeHolder tile = getPipe(world, pos, false);
if (tile == null) {
return computeTrace(null, pos, start, end, FULL_BLOCK_AABB, 400);
}
RayTraceResult best = null;
Pipe pipe = tile.getPipe();
boolean computed = false;
if (pipe != null) {
computed = true;
best = computeTrace(best, pos, start, end, BOX_CENTER, 0);
for (EnumFacing face : EnumFacing.VALUES) {
float conSize = pipe.getConnectedDist(face);
if (conSize > 0) {
AxisAlignedBB aabb = BOX_FACES[face.ordinal()];
if (conSize != 0.25f) {
Vec3d center = VecUtil.offset(new Vec3d(0.5, 0.5, 0.5), face, 0.25 + (conSize / 2));
Vec3d radius = new Vec3d(0.25, 0.25, 0.25);
radius = VecUtil.replaceValue(radius, face.getAxis(), conSize / 2);
Vec3d min = center.subtract(radius);
Vec3d max = center.add(radius);
aabb = BoundingBoxUtil.makeFrom(min, max);
}
best = computeTrace(best, pos, start, end, aabb, face.ordinal() + 1);
}
}
}
for (EnumFacing face : EnumFacing.VALUES) {
PipePluggable pluggable = tile.getPluggable(face);
if (pluggable != null) {
AxisAlignedBB bb = pluggable.getBoundingBox();
best = computeTrace(best, pos, start, end, bb, face.ordinal() + 1 + 6);
computed = true;
}
}
for (EnumWirePart part : tile.getWireManager().parts.keySet()) {
best = computeTrace(best, pos, start, end, part.boundingBox, part.ordinal() + 1 + 6 + 6);
computed = true;
}
for (EnumWireBetween between : tile.getWireManager().betweens.keySet()) {
best = computeTrace(best, pos, start, end, between.boundingBox, between.ordinal() + 1 + 6 + 6 + 8);
computed = true;
}
if (!computed) {
return computeTrace(null, pos, start, end, FULL_BLOCK_AABB, 400);
}
return best;
}
use of buildcraft.transport.pipe.Pipe in project BuildCraft by BuildCraft.
the class BlockPipeHolder method addCollisionBoxToList.
// Collisions
@Override
public void addCollisionBoxToList(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, Entity entityIn, boolean isPistonMoving) {
TilePipeHolder tile = getPipe(world, pos, false);
if (tile == null) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, FULL_BLOCK_AABB);
return;
}
boolean added = false;
Pipe pipe = tile.getPipe();
if (pipe != null) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, BOX_CENTER);
added = true;
for (EnumFacing face : EnumFacing.VALUES) {
float conSize = pipe.getConnectedDist(face);
if (conSize > 0) {
AxisAlignedBB aabb = BOX_FACES[face.ordinal()];
if (conSize != 0.25f) {
Vec3d center = VecUtil.offset(new Vec3d(0.5, 0.5, 0.5), face, 0.25 + (conSize / 2));
Vec3d radius = new Vec3d(0.25, 0.25, 0.25);
radius = VecUtil.replaceValue(radius, face.getAxis(), conSize / 2);
Vec3d min = center.subtract(radius);
Vec3d max = center.add(radius);
aabb = BoundingBoxUtil.makeFrom(min, max);
}
addCollisionBoxToList(pos, entityBox, collidingBoxes, aabb);
}
}
}
for (EnumFacing face : EnumFacing.VALUES) {
PipePluggable pluggable = tile.getPluggable(face);
if (pluggable != null) {
AxisAlignedBB bb = pluggable.getBoundingBox();
addCollisionBoxToList(pos, entityBox, collidingBoxes, bb);
added = true;
}
}
for (EnumWirePart part : tile.getWireManager().parts.keySet()) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, part.boundingBox);
added = true;
}
for (EnumWireBetween between : tile.getWireManager().betweens.keySet()) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, between.boundingBox);
added = true;
}
if (!added) {
addCollisionBoxToList(pos, entityBox, collidingBoxes, FULL_BLOCK_AABB);
}
}
Aggregations