Search in sources :

Example 16 with EnumPipePart

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

the class ActionWrapper method getPossible.

@Override
public ActionWrapper[] getPossible() {
    IStatement[] possible = delegate.getPossible();
    boolean andSides = sourcePart != EnumPipePart.CENTER;
    List<ActionWrapper> list = new ArrayList<>(possible.length + 5);
    for (int i = 0; i < possible.length; i++) {
        list.add(wrap(possible[i], sourcePart.face));
    }
    if (andSides) {
        EnumPipePart part = sourcePart;
        for (int j = 0; j < 5; j++) {
            int i = j + possible.length;
            part = part.next();
            ActionWrapper action = wrap(delegate, part.face);
            if (true) {
                // TODO: Check the gui container to see if this is a valid action!
                list.add(action);
            }
        }
    }
    return list.toArray(new ActionWrapper[0]);
}
Also used : ArrayList(java.util.ArrayList) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement)

Example 17 with EnumPipePart

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

the class PipeItemsStripes method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    if (container.getWorld().isRemote) {
        return;
    }
    if (battery.getEnergyStored() >= 10) {
        EnumPipePart o = actionDir;
        if (o == EnumPipePart.CENTER) {
            o = EnumPipePart.fromFacing(getOpenOrientation());
        }
        if (o != EnumPipePart.CENTER) {
            Vec3d vec = Utils.convert(container.getPos()).add(Utils.convert(o.face));
            BlockPos veci = Utils.convertFloor(vec);
            if (!BlockUtil.isUnbreakableBlock(getWorld(), Utils.convertFloor(vec))) {
                IBlockState state = getWorld().getBlockState(Utils.convertFloor(vec));
                Block block = state.getBlock();
                if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
                    return;
                }
                ItemStack stack = new ItemStack(block, 1, block.getMetaFromState(state));
                EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(), veci).get();
                if (battery.useEnergy(10, 10, false) != 10) {
                    return;
                }
                for (IStripesHandler handler : PipeManager.stripesHandlers) {
                    if (handler.getType() == StripesHandlerType.BLOCK_BREAK && handler.shouldHandle(stack)) {
                        if (handler.handle(getWorld(), veci, o.face, stack, player, this)) {
                            return;
                        }
                    }
                }
                List<ItemStack> stacks = block.getDrops(getWorld(), veci, state, 0);
                if (stacks != null) {
                    for (ItemStack s : stacks) {
                        if (s != null) {
                            sendItem(s, o.opposite().face);
                        }
                    }
                }
                getWorld().setBlockToAir(veci);
            }
        }
        return;
    }
}
Also used : IStripesHandler(buildcraft.api.transport.IStripesHandler) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EnumPipePart(buildcraft.api.core.EnumPipePart) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 18 with EnumPipePart

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

the class PipeLogicWood method switchSource.

private void switchSource() {
    int meta = pipe.container.getBlockMetadata();
    EnumPipePart oldFacing = EnumPipePart.fromMeta(meta);
    EnumPipePart newFacing = oldFacing.next();
    if (oldFacing == EnumPipePart.CENTER) {
        oldFacing = oldFacing.next();
    }
    boolean first = true;
    while (oldFacing != newFacing || first) {
        first = false;
        if (setSource(newFacing)) {
            return;
        }
        newFacing = newFacing.next();
    }
    setSource(EnumPipePart.CENTER);
}
Also used : EnumPipePart(buildcraft.api.core.EnumPipePart)

Example 19 with EnumPipePart

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

the class PipeFlowFluids method writeToNbt.

@Override
public NBTTagCompound writeToNbt() {
    NBTTagCompound nbt = super.writeToNbt();
    if (currentFluid != null) {
        NBTTagCompound fluidTag = new NBTTagCompound();
        currentFluid.writeToNBT(fluidTag);
        nbt.setTag("fluid", fluidTag);
        for (EnumPipePart part : EnumPipePart.VALUES) {
            int direction = part.getIndex();
            NBTTagCompound subTag = new NBTTagCompound();
            sections.get(part).writeToNbt(subTag);
            nbt.setTag("tank[" + direction + "]", subTag);
        }
    }
    return nbt;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnumPipePart(buildcraft.api.core.EnumPipePart)

Example 20 with EnumPipePart

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

the class PipeFlowFluids method onTick.

@Override
public void onTick() {
    World world = pipe.getHolder().getPipeWorld();
    if (world.isRemote) {
        for (EnumPipePart part : EnumPipePart.VALUES) {
            sections.get(part).tickClient();
        }
        return;
    }
    if (currentFluid != null) {
        // int timeSlot = (int) (world.getTotalWorldTime() % currentDelay);
        int totalFluid = 0;
        boolean canOutput = false;
        for (EnumPipePart part : EnumPipePart.VALUES) {
            Section section = sections.get(part);
            section.currentTime = (section.currentTime + 1) % currentDelay;
            section.advanceForMovement();
            totalFluid += section.amount;
            if (section.getCurrentDirection().canOutput()) {
                canOutput = true;
            }
        }
        if (totalFluid == 0) {
            setFluid(null);
        } else {
            if (canOutput) {
                moveFromPipe();
            }
            moveFromCenter();
            moveToCenter();
        }
        // tick cooldowns
        for (EnumPipePart part : EnumPipePart.VALUES) {
            Section section = sections.get(part);
            if (section.ticksInDirection > 0) {
                section.ticksInDirection--;
            } else if (section.ticksInDirection < 0) {
                section.ticksInDirection++;
            }
        }
    }
    boolean send = false;
    for (EnumPipePart part : EnumPipePart.VALUES) {
        Section section = sections.get(part);
        if (section.amount != section.lastSentAmount) {
            send = true;
            break;
        } else {
            Dir should = Dir.get(section.ticksInDirection);
            if (section.lastSentDirection != should) {
                send = true;
                break;
            }
        }
    }
    if (send && tracker.markTimeIfDelay(world)) {
        // send a net update
        sendPayload(NET_FLUID_AMOUNTS);
    }
}
Also used : EnumPipePart(buildcraft.api.core.EnumPipePart) World(net.minecraft.world.World)

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