Search in sources :

Example 1 with IFlowItems

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;
        }
    }
}
Also used : InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IItemPipe(buildcraft.api.transport.pipe.IItemPipe) IPipe(buildcraft.api.transport.pipe.IPipe) Pipe(buildcraft.transport.pipe.Pipe) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 2 with IFlowItems

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);
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) IItemPipe(buildcraft.api.transport.pipe.IItemPipe) IPipe(buildcraft.api.transport.pipe.IPipe) Pipe(buildcraft.transport.pipe.Pipe) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 3 with IFlowItems

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;
}
Also used : IItemTransactor(buildcraft.api.inventory.IItemTransactor) PipeFlow(buildcraft.api.transport.pipe.PipeFlow) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IFlowItems

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);
}
Also used : PluggableLens(buildcraft.transport.plug.PluggableLens) PluggableDefinition(buildcraft.api.transport.pluggable.PluggableDefinition) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) IPipe(buildcraft.api.transport.pipe.IPipe)

Example 5 with IFlowItems

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;
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Aggregations

IFlowItems (buildcraft.api.transport.pipe.IFlowItems)10 IPipe (buildcraft.api.transport.pipe.IPipe)5 IFlowFluid (buildcraft.api.transport.pipe.IFlowFluid)3 IItemPipe (buildcraft.api.transport.pipe.IItemPipe)3 Pipe (buildcraft.transport.pipe.Pipe)3 ItemStack (net.minecraft.item.ItemStack)3 EnumFacing (net.minecraft.util.EnumFacing)3 IItemTransactor (buildcraft.api.inventory.IItemTransactor)2 PipeFlow (buildcraft.api.transport.pipe.PipeFlow)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 InvalidInputDataException (buildcraft.api.core.InvalidInputDataException)1 IMjRedstoneReceiver (buildcraft.api.mj.IMjRedstoneReceiver)1 IInjectable (buildcraft.api.transport.IInjectable)1 ConnectedType (buildcraft.api.transport.pipe.IPipe.ConnectedType)1 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)1 PipeDefinition (buildcraft.api.transport.pipe.PipeDefinition)1 PipeEventItem (buildcraft.api.transport.pipe.PipeEventItem)1 PluggableDefinition (buildcraft.api.transport.pluggable.PluggableDefinition)1 GuiImageButton (buildcraft.lib.gui.button.GuiImageButton)1 PluggableLens (buildcraft.transport.plug.PluggableLens)1