Search in sources :

Example 1 with FacadeState

use of buildcraft.transport.ItemFacade.FacadeState in project BuildCraft by BuildCraft.

the class FacadeItemModel method handleItemState.

@Override
public FacadeItemModel handleItemState(ItemStack stack) {
    FacadeState[] states = ItemFacade.getFacadeStates(stack);
    if (states.length == 0)
        return this;
    if (states.length == 1) {
        if (!map.containsKey(states[0])) {
            map.put(states[0], createFacadeItemModel(states[0]));
        }
        return map.get(states[0]);
    }
    int length = states.length;
    long millis = System.currentTimeMillis() / 2500;
    int index = (int) (millis % length);
    FacadeState state = states[index];
    if (!map.containsKey(state)) {
        map.put(state, createFacadeItemModel(state));
    }
    return map.get(state);
}
Also used : FacadeState(buildcraft.transport.ItemFacade.FacadeState)

Example 2 with FacadeState

use of buildcraft.transport.ItemFacade.FacadeState in project BuildCraft by BuildCraft.

the class TileGenericPipe method refreshRenderState.

/**
 * PRECONDITION: worldObj must not be null
 *
 * @return <code>True</code> if any part of the render state changed
 */
protected boolean refreshRenderState() {
    renderState.setGlassColor((byte) glassColor);
    // Pipe connections;
    for (EnumFacing o : EnumFacing.VALUES) {
        renderState.pipeConnectionMatrix.setConnected(o, this.pipeConnectionsBuffer[o.ordinal()]);
        if (pipeConnectionsBuffer[o.ordinal()]) {
            BlockPos connected = getPos().offset(o);
            IBlockState state = worldObj.getBlockState(connected);
            Block block = state.getBlock();
            ICustomPipeConnection connection = PipeConnectionAPI.getCustomConnection(block);
            if (connection == null) {
                connection = DefaultPipeConnection.INSTANCE;
            }
            renderState.setExtension(o, connection.getExtension(worldObj, connected, o, state));
        }
    }
    // Pipe Textures
    renderState.textureMatrix.setIconIndex(null, pipe.getIconIndex(null));
    for (EnumFacing o : EnumFacing.values()) {
        renderState.textureMatrix.setIconIndex(o, pipe.getIconIndex(o));
    }
    // WireState
    for (PipeWire color : PipeWire.values()) {
        renderState.wireMatrix.setWire(color, pipe.wireSet[color.ordinal()]);
        for (EnumFacing direction : EnumFacing.VALUES) {
            renderState.wireMatrix.setWireConnected(color, direction, pipe.isWireConnectedTo(this.getTile(direction), color, direction));
        }
        boolean lit = pipe.signalStrength[color.ordinal()] > 0;
        renderState.wireMatrix.setWireLit(color, lit);
    }
    // Facades
    for (EnumFacing direction : EnumFacing.VALUES) {
        PipePluggable pluggable = sideProperties.pluggables[direction.ordinal()];
        if (!(pluggable instanceof FacadePluggable)) {
            continue;
        }
        FacadeState[] states = ((FacadePluggable) pluggable).states;
        // Iterate over all states and activate first proper
        int defaultState = -1;
        int activeState = -1;
        for (int i = 0; i < states.length; i++) {
            FacadeState state = states[i];
            if (state.wire == null) {
                defaultState = i;
                continue;
            }
            if (pipe != null && pipe.isWireActive(state.wire)) {
                activeState = i;
                break;
            }
        }
        if (activeState < 0) {
            activeState = defaultState;
        }
        ((FacadePluggable) pluggable).setActiveState(activeState);
    }
    pluggableState.setPluggables(sideProperties.pluggables);
    boolean isDirty = renderState.isDirty() || pluggableState.isDirty();
    if (isDirty) {
        sendNetworkUpdate();
        renderState.clean();
    }
    return isDirty;
}
Also used : IFacadePluggable(buildcraft.api.transport.pluggable.IFacadePluggable) FacadeState(buildcraft.transport.ItemFacade.FacadeState) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

FacadeState (buildcraft.transport.ItemFacade.FacadeState)2 IFacadePluggable (buildcraft.api.transport.pluggable.IFacadePluggable)1 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1