use of buildcraft.api.transport.pipe.IFlowItems 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.api.transport.pipe.IFlowItems 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.api.transport.pipe.IFlowItems in project BuildCraft by BuildCraft.
the class PipeBehaviourObsidian method trySuckEntity.
/**
* @return The left over power
*/
protected long trySuckEntity(Entity entity, EnumFacing faceFrom, long power, boolean simulate) {
if (entity.isDead || entity instanceof EntityLivingBase) {
return power;
}
Long tickPickupObj = entityDropTime.get(entity);
if (tickPickupObj != null) {
long tickPickup = tickPickupObj;
long tickNow = pipe.getHolder().getPipeWorld().getTotalWorldTime();
if (tickNow < tickPickup) {
return power;
} else {
entityDropTime.remove(entity);
}
}
PipeFlow flow = pipe.getFlow();
IFlowItems flowItem = flow instanceof IFlowItems ? (IFlowItems) flow : null;
IFlowFluid flowFluid = flow instanceof IFlowFluid ? (IFlowFluid) flow : null;
IItemTransactor transactor = ItemTransactorHelper.getTransactorForEntity(entity, faceFrom.getOpposite());
if (flowItem != null) {
double distance = Math.sqrt(entity.getDistanceSqToCenter(pipe.getHolder().getPipePos()));
long powerReqPerItem = (long) (distance * POWER_PER_METRE + POWER_PER_ITEM);
int max = power == 0 ? 1 : (int) (power / powerReqPerItem);
ItemStack extracted = transactor.extract(StackFilter.ALL, 1, max, simulate);
if (!extracted.isEmpty()) {
if (!simulate) {
flowItem.insertItemsForce(extracted, faceFrom, null, INSERT_SPEED);
}
return power - powerReqPerItem * extracted.getCount();
}
}
if (flowFluid != null) {
// TODO: Fluid extraction!
}
return power;
}
use of buildcraft.api.transport.pipe.IFlowItems in project BuildCraft by BuildCraft.
the class ItemPluggableLens method onPlace.
@Override
public PipePluggable onPlace(@Nonnull ItemStack stack, IPipeHolder holder, EnumFacing side, EntityPlayer player, EnumHand hand) {
IPipe pipe = holder.getPipe();
if (pipe == null || !(pipe.getFlow() instanceof IFlowItems)) {
return null;
}
LensData data = getData(stack);
SoundUtil.playBlockPlace(holder.getPipeWorld(), holder.getPipePos(), Blocks.STONE.getDefaultState());
PluggableDefinition def = BCTransportPlugs.lens;
return new PluggableLens(def, holder, side, data.colour, data.isFilter);
}
use of buildcraft.api.transport.pipe.IFlowItems in project LogisticsPipes by RS485.
the class BCPipeInformationProvider method acceptItem.
@Override
public boolean acceptItem(LPTravelingItem item, TileEntity from) {
if (pipe != null && pipe.getPipe() != null && pipe.getPipe().getDefinition().flowType == PipeApi.flowItems) {
if (!(item instanceof LPTravelingItemServer)) {
return true;
}
ItemRoutingInformation routingInformation = ((LPTravelingItemServer) item).getInfo();
NBTTagCompound routingData = new NBTTagCompound();
routingInformation.storeToNBT(routingData);
ItemStack transportStack = item.getItemIdentifierStack().makeNormalStack();
if (!transportStack.hasTagCompound()) {
transportStack.setTagCompound(new NBTTagCompound());
}
final NBTTagCompound tag = Objects.requireNonNull(transportStack.getTagCompound());
tag.setTag("logisticspipes:routingdata_buildcraft", routingData);
IFlowItems itemPipe = (IFlowItems) pipe.getPipe().getFlow();
itemPipe.insertItemsForce(transportStack, item.output.getOpposite(), null, item.getSpeed());
return true;
}
return false;
}
Aggregations