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);
}
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;
}
Aggregations