Cleanup of the cleanup, standard panels should work now

This commit is contained in:
malte0811 2018-07-30 21:51:58 +02:00
parent 1cef97f260
commit bd26b2b358
13 changed files with 109 additions and 67 deletions

View file

@ -35,22 +35,24 @@ public abstract class TileEntityGeneralCP extends TileEntityIWBase implements IO
@Override
public void onLoad() {
super.onLoad();
boolean isFinalNet = false;
for (EnumFacing side:EnumFacing.VALUES) {
BlockPos posSide = pos.offset(side);
TileEntityGeneralCP neighbour = MiscUtils.getExistingTE(world, posSide, TileEntityGeneralCP.class);
if (neighbour!=null) {
if (!isFinalNet) {
panelNetwork = neighbour.panelNetwork;
panelNetwork.addMember(this);
isFinalNet = true;
} else {
neighbour.panelNetwork.replaceWith(panelNetwork, world);
if (!world.isRemote) {
boolean isFinalNet = false;
for (EnumFacing side : EnumFacing.VALUES) {
BlockPos posSide = pos.offset(side);
TileEntityGeneralCP neighbour = MiscUtils.getExistingTE(world, posSide, TileEntityGeneralCP.class);
if (neighbour != null) {
if (!isFinalNet) {
panelNetwork = neighbour.panelNetwork;
panelNetwork.addMember(this);
isFinalNet = true;
} else {
neighbour.panelNetwork.replaceWith(panelNetwork, world);
}
}
}
}
if (!isFinalNet) {
panelNetwork.addMember(this);
if (!isFinalNet) {
panelNetwork.addMember(this);
}
}
}

View file

@ -74,12 +74,17 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
components.add(lbl);
components.add(btn);
}
for (PanelComponent pc:components) {
pc.setPanel(this);
}
}
@Override
public void update() {
for (PanelComponent pc : components) {
pc.update();
if (!world.isRemote) {
for (PanelComponent pc : components) {
pc.update();
}
}
}
@ -87,7 +92,7 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
public void setNetworkAndInit(ControlPanelNetwork newNet) {
super.setNetworkAndInit(newNet);
for (PanelComponent pc : components) {
pc.setNetwork(newNet, this);
pc.setNetwork(newNet);
}
}
@ -126,6 +131,11 @@ public class TileEntityPanel extends TileEntityGeneralCP implements IDirectional
if (nbt != null) {
NBTTagList l = nbt.getTagList("components", 10);
PanelUtils.readListFromNBT(l, components);
panelNetwork.removeIOFor(this);
for (PanelComponent pc:components) {
pc.setPanel(this);
pc.setNetwork(panelNetwork);
}
components.setHeight(nbt.getFloat("height"));
components.setAngle(nbt.getFloat("angle"));
}

View file

@ -149,12 +149,14 @@ public class ControlPanelNetwork {
OutputValue oldSecMax = secondActiveOutputs.get(channel);
OutputValue newMax = null;
OutputValue newSecMax = null;
for (OutputValue v : allOutputs.get(channel)) {
if (v.isStrongerThan(newMax)) {
newSecMax = newMax;
newMax = v;
} else if (v.isStrongerThan(newSecMax)) {
newSecMax = v;
if (allOutputs.containsKey(channel)) {
for (OutputValue v : allOutputs.get(channel)) {
if (v.isStrongerThan(newMax)) {
newSecMax = newMax;
newMax = v;
} else if (v.isStrongerThan(newSecMax)) {
newSecMax = v;
}
}
}
if (newMax == null) {
@ -185,6 +187,9 @@ public class ControlPanelNetwork {
}
private <T extends Owned> boolean removeForChannel(IOwner owner, List<T> l, Iterator<?> it) {
if (l==null) {
return false;
}
l.removeIf(val -> val.isOwnedBy(owner));
if (l.isEmpty()) {
if (it!=null) {
@ -295,7 +300,8 @@ public class ControlPanelNetwork {
}
public static class RSChannel {
public static final RSChannel INVALID_CHANNEL = new RSChannel(-1, (byte)-1);
public static final RSChannel INVALID_CHANNEL = new RSChannel(-1, (byte)0);
public static final RSChannel DEFAULT_CHANNEL = new RSChannel(0, (byte)0);
private final int controller;
private final byte color;

View file

@ -68,8 +68,6 @@ public class CoveredToggleSwitch extends ToggleSwitch {
state = state.next();
}
setOut(state.active);
panel.markDirty();
panel.triggerRenderUpdate();
}
@Override
@ -84,7 +82,7 @@ public class CoveredToggleSwitch extends ToggleSwitch {
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
super.writeCustomNBT(nbt, toItem);
if (!toItem) {
nbt.setInteger("active", state.ordinal());
nbt.setInteger("state", state.ordinal());
}
nbt.setInteger(COLOR, color);
}

View file

@ -16,7 +16,6 @@
package malte0811.industrialWires.controlpanel;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.controlpanel.ControlPanelNetwork.RSChannel;
@ -41,7 +40,7 @@ import static malte0811.industrialWires.util.NBTKeys.*;
public class IndicatorLight extends PanelComponent implements IConfigurableComponent {
@Nonnull
private RSChannel inputChannel = RSChannel.INVALID_CHANNEL;
private RSChannel inputChannel = RSChannel.DEFAULT_CHANNEL;
private int colorA = 0xff00;
private byte rsInput;
@ -131,8 +130,8 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
@Override
public void setNetwork(ControlPanelNetwork net, TileEntityPanel panel) {
super.setNetwork(net, panel);
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
net.addListener(this, handler, inputChannel);
}

View file

@ -16,7 +16,6 @@
package malte0811.industrialWires.controlpanel;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.controlpanel.ControlPanelNetwork.RSChannel;
@ -43,7 +42,7 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
private boolean active;
private boolean latching;
@Nonnull
private RSChannel outputChannel = RSChannel.INVALID_CHANNEL;
private RSChannel outputChannel = RSChannel.DEFAULT_CHANNEL;
private int ticksTillOff;
LightedButton() {
@ -141,8 +140,8 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
public void setNetwork(ControlPanelNetwork net, TileEntityPanel te) {
super.setNetwork(net, te);
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
net.setOutputs(this, new RSChannelState(outputChannel, (byte) (active?15:0)));
}

View file

@ -54,7 +54,7 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
private boolean turned;
private boolean latching = false;
@Nonnull
private RSChannel outputChannel = RSChannel.INVALID_CHANNEL;
private RSChannel outputChannel = RSChannel.DEFAULT_CHANNEL;
private int ticksTillOff;
private int lockID;
@ -104,6 +104,12 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
outputChannel = new RSChannel(rsController, rsColor);
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
net.setOutputs(this, new RSChannelState(outputChannel, (byte) (turned?15:0)));
}
private final static float size = .0625F;
private final static float keyWidth = .125F * size;
private final static float yOffset = size / 2 + Y_DELTA;

View file

@ -105,8 +105,7 @@ public abstract class PanelComponent implements IOwner {
public abstract float getHeight();
public void setNetwork(ControlPanelNetwork net, TileEntityPanel panel) {
this.panel = panel;
public void setNetwork(ControlPanelNetwork net) {
this.network = net;
}
@ -246,4 +245,8 @@ public abstract class PanelComponent implements IOwner {
result = 31 * result + type.hashCode();
return result;
}
public void setPanel(TileEntityPanel tile) {
panel = tile;
}
}

View file

@ -17,7 +17,6 @@ package malte0811.industrialWires.controlpanel;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.client.panelmodel.RawModelFontRenderer;
@ -47,7 +46,7 @@ import static malte0811.industrialWires.util.NBTKeys.*;
public class PanelMeter extends PanelComponent implements IConfigurableComponent {
@Nonnull
private RSChannel primary = RSChannel.INVALID_CHANNEL;
private RSChannel primary = RSChannel.DEFAULT_CHANNEL;
@Nonnull
private RSChannel secondary = RSChannel.INVALID_CHANNEL;
private int rsInput;
@ -191,8 +190,8 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
}
@Override
public void setNetwork(ControlPanelNetwork net, TileEntityPanel panel) {
super.setNetwork(net, panel);
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
Consumer<RSChannelState> listenerPrimary = (input) -> {
byte strength = input.getStrength();
if (strength != rsInput >> 4) {

View file

@ -16,7 +16,6 @@
package malte0811.industrialWires.controlpanel;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.controlpanel.ControlPanelNetwork.RSChannel;
@ -85,7 +84,7 @@ public class SevenSegDisplay extends PanelComponent implements IConfigurableComp
private int color = 0xff00;
private byte input = 0;
@Nonnull
private RSChannel inputChannel = RSChannel.INVALID_CHANNEL;
private RSChannel inputChannel = RSChannel.DEFAULT_CHANNEL;
public SevenSegDisplay() {
super(NAME);
@ -118,8 +117,8 @@ public class SevenSegDisplay extends PanelComponent implements IConfigurableComp
@Override
public void setNetwork(ControlPanelNetwork net, TileEntityPanel panel) {
super.setNetwork(net, panel);
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
Consumer<RSChannelState> handler = (inputNew) -> {
if (inputNew.getStrength() != input) {
input = inputNew.getStrength();

View file

@ -47,7 +47,7 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
private boolean horizontal;
private int out;
@Nonnull
private RSChannel primary = RSChannel.INVALID_CHANNEL;
private RSChannel primary = RSChannel.DEFAULT_CHANNEL;
@Nonnull
private RSChannel secondary = RSChannel.INVALID_CHANNEL;
@ -149,9 +149,6 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
int newLevel = (int) Math.min(pos * 256 / length, 255);
if (newLevel != out) {
setOut(newLevel);
out = newLevel;
panel.markDirty();
panel.triggerRenderUpdate();
}
}
@ -160,6 +157,13 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
network.setOutputs(this, new RSChannelState(primary, (byte) (out>>4)));
network.setOutputs(this, new RSChannelState(secondary, (byte) (out&0xf)));
}
@Override
public float getHeight() {
return .0625F / 2;
@ -181,6 +185,9 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
public void setOut(int value) {
network.setOutputs(this, new RSChannelState(primary, (byte) (value>>4)));
network.setOutputs(this, new RSChannelState(secondary, (byte) (value&0xf)));
out = value;
panel.markDirty();
panel.triggerRenderUpdate();
}
@Override
@ -281,23 +288,23 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{
new RSColorConfig("channel", 0, 0, primary.getColor(), false),
new RSColorConfig("channel2", 60, 0, secondary.getColor(), false)
new RSColorConfig("channel", 0, 0, primary.getColor(), true),
new RSColorConfig("channel2", 30, 0, secondary.getColor(), true)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 60, primary.getController(), 2, false),
new IntConfig("rsId2", 60, 60, secondary.getController(), 2, true)
new IntConfig("rsId", 0, 30, primary.getController(), 2, false),
new IntConfig("rsId2", 30, 30, secondary.getController(), 2, true)
};
}
@Override
public BoolConfig[] getBooleanOptions() {
return new BoolConfig[]{
new BoolConfig("horizontal", 0, 70, horizontal)
new BoolConfig("horizontal", 0, 40, horizontal)
};
}

View file

@ -43,7 +43,7 @@ import static malte0811.industrialWires.util.NBTKeys.RS_ID;
public class ToggleSwitch extends PanelComponent implements IConfigurableComponent {
protected boolean active;
@Nonnull
protected RSChannel outputChannel = RSChannel.INVALID_CHANNEL;
protected RSChannel outputChannel = RSChannel.DEFAULT_CHANNEL;
public ToggleSwitch() {
super("toggle_switch");
@ -76,6 +76,12 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
outputChannel = new RSChannel(rsController, rsColor);
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
network.setOutputs(this, new RSChannelState(outputChannel, (byte) (active ? 15 : 0)));
}
protected float sizeX = .0625F;
protected float sizeY = 1.5F * sizeX;
protected float rodRadius = sizeX * .25F;
@ -152,9 +158,9 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
protected void setOut(boolean on) {
active = on;
network.setOutputs(this, new RSChannelState(outputChannel, (byte) (active ? 15 : 0)));
panel.markDirty();
panel.triggerRenderUpdate();
network.setOutputs(this, new RSChannelState(outputChannel, (byte) (active ? 15 : 0)));
}
@Override

View file

@ -20,6 +20,7 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.controlpanel.ControlPanelNetwork.RSChannel;
import malte0811.industrialWires.controlpanel.ControlPanelNetwork.RSChannelState;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
@ -51,7 +52,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
private int out;
@Nonnull
private RSChannel primary = RSChannel.INVALID_CHANNEL;
private RSChannel primary = RSChannel.DEFAULT_CHANNEL;
@Nonnull
private RSChannel secondary = RSChannel.INVALID_CHANNEL;
@ -162,9 +163,6 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
newLevel = Math.max(0, Math.min(newLevel, 255));
if (newLevel != out) {
setOut(newLevel);
out = newLevel;
panel.markDirty();
panel.triggerRenderUpdate();
}
}
@ -173,6 +171,13 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
@Override
public void setNetwork(ControlPanelNetwork net) {
super.setNetwork(net);
network.setOutputs(this, new RSChannelState(primary, (byte) (out>>4)));
network.setOutputs(this, new RSChannelState(secondary, (byte) (out&0xf)));
}
@Override
public float getHeight() {
return .0625F;
@ -200,8 +205,11 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
public void setOut(int value) {
network.setOutputs(this, new ControlPanelNetwork.RSChannelState(primary, (byte) (value>>4)));
network.setOutputs(this, new ControlPanelNetwork.RSChannelState(secondary, (byte) (value&0xf)));
network.setOutputs(this, new RSChannelState(primary, (byte) (value>>4)));
network.setOutputs(this, new RSChannelState(secondary, (byte) (value&0xf)));
out = value;
panel.markDirty();
panel.triggerRenderUpdate();
}
@Override
@ -267,16 +275,16 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
@Override
public RSColorConfig[] getRSChannelOptions() {
return new RSColorConfig[]{
new RSColorConfig("channel", 0, 0, primary.getColor(), false),
new RSColorConfig("channel2", 60, 0, secondary.getColor(), false)
new RSColorConfig("channel", 0, 0, primary.getColor()),
new RSColorConfig("channel2", 90, 0, secondary.getColor())
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 60, primary.getController(), 2, false),
new IntConfig("rsId2", 60, 60, secondary.getController(), 2, true)
new IntConfig("rsId", 0, 50, primary.getController(), 2, false),
new IntConfig("rsId2", 90, 50, secondary.getController(), 2, true)
};
}