Fix Gate lit state

This commit is contained in:
CovertJaguar 2014-01-04 07:42:53 -08:00
parent 23a3a7004d
commit f87e5c0add
3 changed files with 36 additions and 28 deletions

View file

@ -23,6 +23,7 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import com.google.common.collect.HashMultiset; import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset; import com.google.common.collect.Multiset;
import java.util.BitSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -42,7 +43,8 @@ public final class Gate {
public ITrigger[] triggers = new ITrigger[8]; public ITrigger[] triggers = new ITrigger[8];
public ITriggerParameter[] triggerParameters = new ITriggerParameter[8]; public ITriggerParameter[] triggerParameters = new ITriggerParameter[8];
public IAction[] actions = new IAction[8]; public IAction[] actions = new IAction[8];
public boolean broadcastSignal[] = new boolean[4]; public BitSet broadcastSignal = new BitSet(PipeWire.VALUES.length);
public BitSet prevBroadcastSignal = new BitSet(PipeWire.VALUES.length);
public int redstoneOutput = 0; public int redstoneOutput = 0;
// / CONSTRUCTOR // / CONSTRUCTOR
@ -108,8 +110,8 @@ public final class Gate {
} }
} }
for (int i = 0; i < 4; ++i) { for (PipeWire wire : PipeWire.VALUES) {
data.setBoolean("wireState[" + i + "]", broadcastSignal[i]); data.setBoolean("wireState[" + wire.ordinal() + "]", broadcastSignal.get(wire.ordinal()));
} }
data.setByte("redstoneOutput", (byte) redstoneOutput); data.setByte("redstoneOutput", (byte) redstoneOutput);
} }
@ -126,8 +128,8 @@ public final class Gate {
} }
} }
for (int i = 0; i < 4; ++i) { for (PipeWire wire : PipeWire.VALUES) {
broadcastSignal[i] = data.getBoolean("wireState[" + i + "]"); broadcastSignal.set(wire.ordinal(), data.getBoolean("wireState[" + wire.ordinal() + "]"));
} }
redstoneOutput = data.getByte("redstoneOutput"); redstoneOutput = data.getByte("redstoneOutput");
} }
@ -162,11 +164,12 @@ public final class Gate {
} }
public boolean isGateActive() { public boolean isGateActive() {
for (boolean b : broadcastSignal) { for (GateExpansionController expansion : expansions.values()) {
if (b) if (expansion.isActive())
return true; return true;
} }
return redstoneOutput > 0; return redstoneOutput > 0 || !broadcastSignal.isEmpty();
} }
public int getRedstoneOutput() { public int getRedstoneOutput() {
@ -181,10 +184,12 @@ public final class Gate {
public void resolveActions() { public void resolveActions() {
int oldRedstoneOutput = redstoneOutput; int oldRedstoneOutput = redstoneOutput;
boolean[] oldBroadcastSignal = broadcastSignal;
redstoneOutput = 0; redstoneOutput = 0;
broadcastSignal = new boolean[4];
BitSet temp = prevBroadcastSignal;
temp.clear();
prevBroadcastSignal = broadcastSignal;
broadcastSignal = temp;
// Tell the gate to prepare for resolving actions. (Disable pulser) // Tell the gate to prepare for resolving actions. (Disable pulser)
startResolution(); startResolution();
@ -225,7 +230,7 @@ public final class Gate {
} else if (action instanceof ActionRedstoneFaderOutput) { } else if (action instanceof ActionRedstoneFaderOutput) {
redstoneOutput = ((ActionRedstoneFaderOutput) action).level; redstoneOutput = ((ActionRedstoneFaderOutput) action).level;
} else if (action instanceof ActionSignalOutput) { } else if (action instanceof ActionSignalOutput) {
broadcastSignal[((ActionSignalOutput) action).color.ordinal()] = true; broadcastSignal.set(((ActionSignalOutput) action).color.ordinal());
} else { } else {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = pipe.container.getTile(side); TileEntity tile = pipe.container.getTile(side);
@ -246,12 +251,9 @@ public final class Gate {
pipe.updateNeighbors(true); pipe.updateNeighbors(true);
} }
for (int i = 0; i < oldBroadcastSignal.length; ++i) { if (!prevBroadcastSignal.equals(broadcastSignal)) {
if (oldBroadcastSignal[i] != broadcastSignal[i]) { pipe.container.scheduleRenderUpdate();
pipe.container.scheduleRenderUpdate(); pipe.updateSignalState();
pipe.updateSignalState();
break;
}
} }
} }

View file

@ -277,30 +277,30 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
} }
} }
private void updateSignalStateForColor(PipeWire color) { private void updateSignalStateForColor(PipeWire wire) {
if (!wireSet[color.ordinal()]) if (!wireSet[wire.ordinal()])
return; return;
// STEP 1: compute internal signal strength // STEP 1: compute internal signal strength
if (gate != null && gate.broadcastSignal[color.ordinal()]) { if (gate != null && gate.broadcastSignal.get(wire.ordinal())) {
receiveSignal(255, color); receiveSignal(255, wire);
} else { } else {
readNearbyPipesSignal(color); readNearbyPipesSignal(wire);
} }
// STEP 2: transmit signal in nearby blocks // STEP 2: transmit signal in nearby blocks
if (signalStrength[color.ordinal()] > 1) { if (signalStrength[wire.ordinal()] > 1) {
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = container.getTile(o); TileEntity tile = container.getTile(o);
if (tile instanceof TileGenericPipe) { if (tile instanceof TileGenericPipe) {
TileGenericPipe tilePipe = (TileGenericPipe) tile; TileGenericPipe tilePipe = (TileGenericPipe) tile;
if (BlockGenericPipe.isFullyDefined(tilePipe.pipe) && tilePipe.pipe.wireSet[color.ordinal()]) if (BlockGenericPipe.isFullyDefined(tilePipe.pipe) && tilePipe.pipe.wireSet[wire.ordinal()])
if (isWireConnectedTo(tile, color)) { if (isWireConnectedTo(tile, wire)) {
tilePipe.pipe.receiveSignal(signalStrength[color.ordinal()] - 1, color); tilePipe.pipe.receiveSignal(signalStrength[wire.ordinal()] - 1, wire);
} }
} }
} }

View file

@ -458,7 +458,13 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
bindTexture(TextureMap.locationBlocksTexture); bindTexture(TextureMap.locationBlocksTexture);
renderGate(pipe, pipe.pipe.gate.logic.getIconDark(), 0); Icon iconLogic;
if (pipe.pipe.gate.isGateActive())
iconLogic = pipe.pipe.gate.logic.getIconLit();
else
iconLogic = pipe.pipe.gate.logic.getIconDark();
renderGate(pipe, iconLogic, 0);
Icon materialIcon = pipe.pipe.gate.material.getIconBlock(); Icon materialIcon = pipe.pipe.gate.material.getIconBlock();
if (materialIcon != null) if (materialIcon != null)