Search in sources :

Example 6 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class PipeFlowFluids method getDebugInfo.

// IDebuggable
@Override
public void getDebugInfo(List<String> left, List<String> right, EnumFacing side) {
    boolean isRemote = pipe.getHolder().getPipeWorld().isRemote;
    FluidStack fluid = isRemote ? getFluidStackForRender() : currentFluid;
    left.add(" - FluidType = " + (fluid == null ? "empty" : fluid.getLocalizedName()));
    for (EnumPipePart part : EnumPipePart.VALUES) {
        Section section = sections.get(part);
        if (section == null) {
            continue;
        }
        StringBuilder line = new StringBuilder(" - " + LocaleUtil.localizeFacing(part.face) + " = ");
        int amount = isRemote ? section.target : section.amount;
        line.append(amount > 0 ? TextFormatting.GREEN : "");
        line.append(amount).append("").append(TextFormatting.RESET).append("mB");
        line.append(" ").append(section.getCurrentDirection()).append(" (").append(section.ticksInDirection).append(")");
        line.append(" [");
        int last = -1;
        int skipped = 0;
        for (int i : section.incoming) {
            if (i != last) {
                if (skipped > 0) {
                    line.append("...").append(skipped).append("... ");
                    skipped = 0;
                }
                last = i;
                line.append(i).append(", ");
            } else {
                skipped++;
            }
        }
        if (skipped > 0) {
            line.append("...").append(skipped).append("... ");
            skipped = 0;
        }
        line.append("0]");
        left.add(line.toString());
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumPipePart(buildcraft.api.core.EnumPipePart)

Example 7 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class ActionType method readFromBuffer.

@Override
public ActionWrapper readFromBuffer(PacketBufferBC buffer) throws IOException {
    if (buffer.readBoolean()) {
        String name = buffer.readString();
        EnumPipePart part = buffer.readEnumValue(EnumPipePart.class);
        IStatement statement = StatementManager.statements.get(name);
        if (statement instanceof IAction) {
            return ActionWrapper.wrap(statement, part.face);
        } else {
            throw new InvalidInputDataException("Unknown action '" + name + "'");
        }
    } else {
        return null;
    }
}
Also used : InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) IAction(buildcraft.api.statements.IAction) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement)

Example 8 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class TriggerType method readFromBuffer.

@Override
public TriggerWrapper readFromBuffer(PacketBufferBC buffer) throws IOException {
    if (buffer.readBoolean()) {
        String name = buffer.readString();
        EnumPipePart part = buffer.readEnumValue(EnumPipePart.class);
        IStatement statement = StatementManager.statements.get(name);
        if (statement instanceof ITrigger) {
            return TriggerWrapper.wrap(statement, part.face);
        } else {
            throw new InvalidInputDataException("Unknown trigger '" + name + "'");
        }
    } else {
        return null;
    }
}
Also used : InvalidInputDataException(buildcraft.api.core.InvalidInputDataException) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement) ITrigger(buildcraft.api.statements.ITrigger)

Example 9 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class BlockPipeHolder method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    TilePipeHolder tile = getPipe(world, pos, false);
    if (tile == null) {
        return false;
    }
    RayTraceResult trace = rayTrace(world, pos, player);
    if (trace == null) {
        return false;
    }
    EnumFacing realSide = getPartSideHit(trace);
    if (realSide == null) {
        realSide = side;
    }
    if (trace.subHit > 6 && trace.subHit <= 12) {
        PipePluggable existing = tile.getPluggable(realSide);
        if (existing != null) {
            return existing.onPluggableActivate(player, trace, hitX, hitY, hitZ);
        }
    }
    EnumPipePart part = trace.subHit == 0 ? EnumPipePart.CENTER : EnumPipePart.fromFacing(realSide);
    ItemStack held = player.getHeldItem(hand);
    Item item = held.isEmpty() ? null : held.getItem();
    PipePluggable existing = tile.getPluggable(realSide);
    if (item instanceof IItemPluggable && existing == null) {
        IItemPluggable itemPlug = (IItemPluggable) item;
        PipePluggable plug = itemPlug.onPlace(held, tile, realSide, player, hand);
        if (plug == null) {
            return false;
        } else {
            tile.replacePluggable(realSide, plug);
            if (!player.capabilities.isCreativeMode) {
                held.shrink(1);
            }
            return true;
        }
    }
    if (item instanceof ItemWire) {
        EnumWirePart wirePartHit = getWirePartHit(trace);
        EnumWirePart wirePart;
        TilePipeHolder attachTile = tile;
        if (wirePartHit != null) {
            WireNode node = new WireNode(pos, wirePartHit);
            node = node.offset(trace.sideHit);
            wirePart = node.part;
            if (!node.pos.equals(pos)) {
                attachTile = getPipe(world, node.pos, false);
            }
        } else {
            wirePart = EnumWirePart.get((trace.hitVec.x % 1 + 1) % 1 > 0.5, (trace.hitVec.y % 1 + 1) % 1 > 0.5, (trace.hitVec.z % 1 + 1) % 1 > 0.5);
        }
        if (wirePart != null && attachTile != null) {
            boolean attached = attachTile.getWireManager().addPart(wirePart, EnumDyeColor.byMetadata(held.getMetadata()));
            attachTile.scheduleNetworkUpdate(IPipeHolder.PipeMessageReceiver.WIRES);
            if (attached && !player.capabilities.isCreativeMode) {
                held.shrink(1);
            }
            if (attached) {
                return true;
            }
        }
    }
    Pipe pipe = tile.getPipe();
    if (pipe == null) {
        return false;
    }
    if (pipe.behaviour.onPipeActivate(player, trace, hitX, hitY, hitZ, part)) {
        return true;
    }
    if (pipe.flow.onFlowActivate(player, trace, hitX, hitY, hitZ, part)) {
        return true;
    }
    return false;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) IItemPluggable(buildcraft.api.transport.IItemPluggable) RayTraceResult(net.minecraft.util.math.RayTraceResult) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Pipe(buildcraft.transport.pipe.Pipe) TilePipeHolder(buildcraft.transport.tile.TilePipeHolder) Item(net.minecraft.item.Item) ItemWire(buildcraft.transport.item.ItemWire) EnumWirePart(buildcraft.api.transport.EnumWirePart) WireNode(buildcraft.api.transport.WireNode) EnumPipePart(buildcraft.api.core.EnumPipePart) ItemStack(net.minecraft.item.ItemStack)

Example 10 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class PipeTransportFluids method computeCurrentConnectionStatesAndTickFlows.

private int computeCurrentConnectionStatesAndTickFlows(short newTimeSlot) {
    int outputCount = 0;
    int fluidAmount = 0;
    // Processes all internal tanks
    for (EnumPipePart direction : EnumPipePart.values()) {
        int dirI = direction.ordinal();
        PipeSection section = sections[dirI];
        fluidAmount += section.amount;
        section.setTime(newTimeSlot);
        section.moveFluids();
        // Input processing
        if (direction == EnumPipePart.CENTER) {
            continue;
        }
        if (transferState[dirI] == TransferState.Input) {
            inputTTL[dirI]--;
            if (inputTTL[dirI] <= 0) {
                transferState[dirI] = TransferState.None;
            }
            continue;
        }
        if (!container.pipe.outputOpen(direction.face)) {
            transferState[dirI] = TransferState.None;
            continue;
        }
        if (outputCooldown[dirI] > 0) {
            outputCooldown[dirI]--;
            continue;
        }
        if (outputTTL[dirI] <= 0) {
            transferState[dirI] = TransferState.None;
            outputCooldown[dirI] = OUTPUT_COOLDOWN;
            outputTTL[dirI] = OUTPUT_TTL;
            continue;
        }
        if (canReceiveCache[dirI] && container.pipe.outputOpen(direction.face)) {
            transferState[dirI] = TransferState.Output;
            outputCount++;
        }
    }
    if (fluidAmount == 0) {
        setFluidType(null);
    }
    return outputCount;
}
Also used : EnumPipePart(buildcraft.api.core.EnumPipePart)

Aggregations

EnumPipePart (buildcraft.api.core.EnumPipePart)24 IStatement (buildcraft.api.statements.IStatement)6 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)3 StatementWrapper (buildcraft.lib.statement.StatementWrapper)3 ArrayList (java.util.ArrayList)3 InvalidInputDataException (buildcraft.api.core.InvalidInputDataException)2 ISprite (buildcraft.api.core.render.ISprite)2 IAction (buildcraft.api.statements.IAction)2 IStatementParameter (buildcraft.api.statements.IStatementParameter)2 ITrigger (buildcraft.api.statements.ITrigger)2 GuiIcon (buildcraft.lib.gui.GuiIcon)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 ITriggerExternalOverride (buildcraft.api.statements.ITriggerExternalOverride)1 StatementManager (buildcraft.api.statements.StatementManager)1 EnumWirePart (buildcraft.api.transport.EnumWirePart)1 IItemPluggable (buildcraft.api.transport.IItemPluggable)1 IStripesHandler (buildcraft.api.transport.IStripesHandler)1 WireNode (buildcraft.api.transport.WireNode)1 PipeEventFluid (buildcraft.api.transport.pipe.PipeEventFluid)1 OnMoveToCentre (buildcraft.api.transport.pipe.PipeEventFluid.OnMoveToCentre)1