Search in sources :

Example 6 with IFlowItems

use of buildcraft.api.transport.pipe.IFlowItems in project BuildCraft by BuildCraft.

the class GuiDiamondWoodPipe method initGui.

@Override
public void initGui() {
    super.initGui();
    this.whiteListButton = new GuiImageButton(mainGui, WHITE_LIST_BUTTON_ID, this.guiLeft + 7, this.guiTop + 41, 18, TEXTURE_BUTTON, 19, 19);
    this.whiteListButton.setToolTip(ToolTip.createLocalized("tip.PipeItemsEmerald.whitelist"));
    this.whiteListButton.registerListener(this);
    this.mainGui.shownElements.add(this.whiteListButton);
    this.blackListButton = new GuiImageButton(mainGui, BLACK_LIST_BUTTON_ID, this.guiLeft + 7 + 18, this.guiTop + 41, 18, TEXTURE_BUTTON, 37, 19);
    this.blackListButton.setToolTip(ToolTip.createLocalized("tip.PipeItemsEmerald.blacklist"));
    this.blackListButton.registerListener(this);
    this.mainGui.shownElements.add(this.blackListButton);
    if (pipe.pipe.getFlow() instanceof IFlowItems) {
        // Don't show round robin for the fluid pipe - its not yet implemented
        this.roundRobinButton = new GuiImageButton(mainGui, ROUND_ROBIN_BUTTON_ID, this.guiLeft + 7 + 36, this.guiTop + 41, 18, TEXTURE_BUTTON, 55, 19);
        this.roundRobinButton.setToolTip(ToolTip.createLocalized("tip.PipeItemsEmerald.roundrobin"));
        this.roundRobinButton.registerListener(this);
        this.mainGui.shownElements.add(this.roundRobinButton);
        IButtonBehaviour.createAndSetRadioButtons(whiteListButton, blackListButton, roundRobinButton);
    } else {
        IButtonBehaviour.createAndSetRadioButtons(whiteListButton, blackListButton);
    }
    switch(pipe.filterMode) {
        case WHITE_LIST:
            this.whiteListButton.activate();
            break;
        case BLACK_LIST:
            this.blackListButton.activate();
            break;
        case ROUND_ROBIN:
            if (roundRobinButton != null) {
                this.roundRobinButton.activate();
            }
            break;
    }
}
Also used : GuiImageButton(buildcraft.lib.gui.button.GuiImageButton) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 7 with IFlowItems

use of buildcraft.api.transport.pipe.IFlowItems in project BuildCraft by BuildCraft.

the class TilePipeHolder method onPlacedBy.

// Misc
@Override
public void onPlacedBy(EntityLivingBase placer, ItemStack stack) {
    super.onPlacedBy(placer, stack);
    Item item = stack.getItem();
    if (item instanceof IItemPipe) {
        PipeDefinition definition = ((IItemPipe) item).getDefinition();
        this.pipe = new Pipe(this, definition);
        eventBus.registerHandler(pipe.behaviour);
        eventBus.registerHandler(pipe.flow);
        if (pipe.flow instanceof IFlowItems) {
            eventBus.registerHandler(FilterEventHandler.class);
        }
        int meta = stack.getMetadata();
        if (meta > 0 && meta <= 16) {
            pipe.setColour(EnumDyeColor.byMetadata(meta - 1));
        }
    }
    scheduleRenderUpdate();
}
Also used : Item(net.minecraft.item.Item) IItemPipe(buildcraft.api.transport.pipe.IItemPipe) PipeDefinition(buildcraft.api.transport.pipe.PipeDefinition) IItemPipe(buildcraft.api.transport.pipe.IItemPipe) IPipe(buildcraft.api.transport.pipe.IPipe) Pipe(buildcraft.transport.pipe.Pipe) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 8 with IFlowItems

use of buildcraft.api.transport.pipe.IFlowItems in project BuildCraft by BuildCraft.

the class PluggablePulsar method onTick.

@Override
public void onTick() {
    if (holder.getPipeWorld().isRemote) {
        if (isPulsing) {
            pulseStage++;
            if (pulseStage == PULSE_STAGE) {
                pulseStage = 0;
            }
        } else {
            // pulseStage--;
            // if (pulseStage < 0) {
            pulseStage = 0;
        // }
        }
        setModelVariables(1);
        clientModelData.tick();
        return;
    }
    boolean isOn = isPulsing();
    if (isOn) {
        pulseStage++;
    } else {
        // pulseStage--;
        // if (pulseStage < 0) {
        pulseStage = 0;
    // }
    }
    if (gateEnabledTicks > 0) {
        gateEnabledTicks--;
    }
    if (pulseStage == PULSE_STAGE) {
        pulseStage = 0;
        IMjRedstoneReceiver rsRec = (IMjRedstoneReceiver) holder.getPipe().getBehaviour();
        if (gateSinglePulses > 0) {
            long power = MjAPI.MJ;
            if (holder.getPipe().getFlow() instanceof IFlowFluid) {
                // Special extration logic for fluids:
                // Always extract either 1 bucket, or nothing.
                power = BCTransportConfig.mjPerMillibucket * 1000;
            } else if (holder.getPipe().getFlow() instanceof IFlowItems) {
                power = BCTransportConfig.mjPerItem;
            } else {
                power = MjAPI.MJ;
            }
            long excess = rsRec.receivePower(power, true);
            if (excess == 0) {
                rsRec.receivePower(power, false);
            } else {
                // Nothing was extracted, so lets extract in the future
                gateSinglePulses++;
            // ParticleUtil.spawnFailureParticles
            }
        } else {
            rsRec.receivePower(MjAPI.MJ, false);
        }
        if (gateSinglePulses > 0) {
            gateSinglePulses--;
        }
    }
    if (isOn != lastPulsing) {
        lastPulsing = isOn;
        scheduleNetworkUpdate();
    }
}
Also used : IMjRedstoneReceiver(buildcraft.api.mj.IMjRedstoneReceiver) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 9 with IFlowItems

use of buildcraft.api.transport.pipe.IFlowItems in project BuildCraft by BuildCraft.

the class PipeBehaviourWood method extract.

protected long extract(long power, boolean simulate) {
    if (power > 0) {
        if (pipe.getFlow() instanceof IFlowItems) {
            IFlowItems flow = (IFlowItems) pipe.getFlow();
            int maxItems = (int) (power / BCTransportConfig.mjPerItem);
            if (maxItems > 0) {
                int extracted = extractItems(flow, getCurrentDir(), maxItems, simulate);
                if (extracted > 0) {
                    return power - extracted * BCTransportConfig.mjPerItem;
                }
            }
        } else if (pipe.getFlow() instanceof IFlowFluid) {
            IFlowFluid flow = (IFlowFluid) pipe.getFlow();
            int maxMillibuckets = (int) (power / BCTransportConfig.mjPerMillibucket);
            if (maxMillibuckets > 0) {
                FluidStack extracted = extractFluid(flow, getCurrentDir(), maxMillibuckets, simulate);
                if (extracted != null && extracted.amount > 0) {
                    return power - extracted.amount * BCTransportConfig.mjPerMillibucket;
                }
            }
        }
    }
    return power;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) IFlowFluid(buildcraft.api.transport.pipe.IFlowFluid) IFlowItems(buildcraft.api.transport.pipe.IFlowItems)

Example 10 with IFlowItems

use of buildcraft.api.transport.pipe.IFlowItems in project BuildCraft by BuildCraft.

the class PipeFlowItems method onItemReachEnd.

private void onItemReachEnd(TravellingItem item) {
    IPipeHolder holder = pipe.getHolder();
    PipeEventItem.ReachEnd reachEnd = new PipeEventItem.ReachEnd(holder, this, item.colour, item.stack, item.side);
    holder.fireEvent(reachEnd);
    item.colour = reachEnd.colour;
    item.stack = reachEnd.getStack();
    ItemStack excess = item.stack;
    if (excess.isEmpty()) {
        return;
    }
    if (pipe.isConnected(item.side)) {
        ConnectedType type = pipe.getConnectedType(item.side);
        EnumFacing oppositeSide = item.side.getOpposite();
        switch(type) {
            case PIPE:
                {
                    IPipe oPipe = pipe.getConnectedPipe(item.side);
                    if (oPipe == null) {
                        break;
                    }
                    PipeFlow flow = oPipe.getFlow();
                    if (flow instanceof IFlowItems) {
                        IFlowItems oFlow = (IFlowItems) flow;
                        ItemStack before = excess;
                        excess = oFlow.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
                        if (!excess.isEmpty()) {
                            before.shrink(excess.getCount());
                        }
                        excess = fireEventEjectIntoPipe(oFlow, item.side, before, excess);
                    }
                    break;
                }
            case TILE:
                {
                    TileEntity tile = pipe.getConnectedTile(item.side);
                    IInjectable injectable = ItemTransactorHelper.getInjectable(tile, oppositeSide);
                    ItemStack before = excess;
                    excess = injectable.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
                    if (!excess.isEmpty()) {
                        IItemTransactor transactor = ItemTransactorHelper.getTransactor(tile, oppositeSide);
                        excess = transactor.insert(excess, false, false);
                    }
                    excess = fireEventEjectIntoTile(tile, item.side, before, excess);
                    break;
                }
        }
    }
    if (excess.isEmpty()) {
        return;
    }
    item.tried.add(item.side);
    item.toCenter = true;
    item.stack = excess;
    item.genTimings(holder.getPipeWorld().getTotalWorldTime(), getPipeLength(item.side));
    items.add(item.timeToDest, item);
    sendItemDataToClient(item);
}
Also used : IPipeHolder(buildcraft.api.transport.pipe.IPipeHolder) EnumFacing(net.minecraft.util.EnumFacing) PipeFlow(buildcraft.api.transport.pipe.PipeFlow) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) ConnectedType(buildcraft.api.transport.pipe.IPipe.ConnectedType) TileEntity(net.minecraft.tileentity.TileEntity) IItemTransactor(buildcraft.api.inventory.IItemTransactor) IInjectable(buildcraft.api.transport.IInjectable) PipeEventItem(buildcraft.api.transport.pipe.PipeEventItem) ItemStack(net.minecraft.item.ItemStack) IPipe(buildcraft.api.transport.pipe.IPipe)

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