Add second-channel support to the Variac, the Panel Meter and the slider

This commit is contained in:
malte0811 2017-08-18 22:41:33 +02:00
parent 2f609e9026
commit f62a13596b
8 changed files with 289 additions and 96 deletions

View file

@ -135,6 +135,11 @@ public class GuiPanelComponent extends GuiContainer {
sync(i, picker.getSelected());
}
if (stopNow) {
for (GuiChannelPicker picker2:rsChannelChoosers) {
if (picker!=picker2&&picker2 instanceof GuiChannelPickerSmall) {
((GuiChannelPickerSmall) picker2).close();
}
}
return;
}
}
@ -192,9 +197,6 @@ public class GuiPanelComponent extends GuiContainer {
this.renderHoveredToolTip(mouseX, mouseY);
GlStateManager.color(1, 1, 1, 1);
RenderHelper.disableStandardItemLighting();
for (GuiChannelPicker pick : rsChannelChoosers) {
pick.drawButton(mc, mouseX, mouseY, partialTicks);
}
for (GuiButtonCheckbox box : boolButtons) {
box.drawButton(mc, mouseX, mouseY, partialTicks);
}
@ -207,12 +209,24 @@ public class GuiPanelComponent extends GuiContainer {
for (GuiSliderIE choose : floatSliders) {
choose.drawButton(mc, mouseX, mouseY, partialTicks);
}
GuiChannelPickerSmall openPicker = null;
for (GuiChannelPicker pick : rsChannelChoosers) {
if (pick instanceof GuiChannelPickerSmall&&((GuiChannelPickerSmall) pick).open) {
openPicker = (GuiChannelPickerSmall) pick;
} else {
pick.drawButton(mc, mouseX, mouseY, partialTicks);
}
}
if (openPicker != null) {
openPicker.drawButton(mc, mouseX, mouseY, partialTicks);
}
//TOOLTIPS
for (int i = 0; i < rsChannelChoosers.size(); i++) {
GuiChannelPicker pick = rsChannelChoosers.get(i);
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.RS_CHANNEL, i);
if (tooltip != null && pick.isHovered(mouseX, mouseY)) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
for (int i = 0; i < boolButtons.size(); i++) {
@ -220,6 +234,7 @@ public class GuiPanelComponent extends GuiContainer {
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.BOOL, i);
if (tooltip != null && box.isMouseOver()) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
for (int i = 0; i < stringTexts.size(); i++) {
@ -228,6 +243,7 @@ public class GuiPanelComponent extends GuiContainer {
if (tooltip != null && mouseX >= field.x && mouseX < field.x + field.width &&
mouseY >= field.y && mouseY < field.y + field.height) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
for (int i = 0; i < intChoosers.size(); i++) {
@ -235,6 +251,7 @@ public class GuiPanelComponent extends GuiContainer {
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.INT, i);
if (tooltip != null && choose.isMouseOver(mouseX, mouseY)) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
for (int i = 0; i < floatSliders.size(); i++) {
@ -242,6 +259,7 @@ public class GuiPanelComponent extends GuiContainer {
String tooltip = confComp.fomatConfigDescription(IConfigurableComponent.ConfigType.FLOAT, i);
if (tooltip != null && choose.isMouseOver()) {
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRenderer);
return;
}
}
}

View file

@ -25,7 +25,7 @@ import net.minecraft.item.EnumDyeColor;
import javax.annotation.Nonnull;
public class GuiChannelPickerSmall extends GuiChannelPicker {
private boolean open = false;
public boolean open = false;
private int offSize, onSize;
public GuiChannelPickerSmall(int id, int x, int y, int offSize, int onSize, byte selectedChannel) {
@ -42,6 +42,7 @@ public class GuiChannelPickerSmall extends GuiChannelPicker {
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
if (open) {
drawRect(x, y, x + width, y + height, 0xff99ff99);
super.drawButton(mc, mouseX, mouseY, partialTicks);
} else {
EnumDyeColor color = EnumDyeColor.byMetadata(selected);
@ -66,10 +67,14 @@ public class GuiChannelPickerSmall extends GuiChannelPicker {
select();
ret = true;
}
open = false;
width = offSize;
height = offSize;
close();
return ret;
}
}
public void close() {
open = false;
width = offSize;
height = offSize;
}
}

View file

@ -24,13 +24,23 @@ public class GuiIntChooser extends Gui {
public void drawChooser() {
int color = 0xE0E0E0;
String val = String.format(format, Integer.toString(value)).replace(' ', '0');
if (value >= 0 && allowNegative) {
val = "+" + val;
String val = String.format(format, Integer.toString(Math.abs(value))).replace(' ', '0');
if (allowNegative) {
if (value > 0) {
val = "+" + val;
} else if (value < 0) {
val = "-" + val;
} else {
val = "0" + val;
}
}
mc.fontRenderer.drawStringWithShadow(val, xPos + mc.fontRenderer.getCharWidth('-') + 1, yPos, color);
mc.fontRenderer.drawStringWithShadow("-", xPos, yPos, color);
mc.fontRenderer.drawStringWithShadow("+", xPlus, yPos, color);
color = 0x9999ff;
if (allowNegative&&value!=0) {
color = value<0?0xff9999:0x99ff99;
}
mc.fontRenderer.drawStringWithShadow(val, xPos + mc.fontRenderer.getCharWidth('-') + 1, yPos, color);
}
public void click(int x, int y) {
@ -41,7 +51,7 @@ public class GuiIntChooser extends Gui {
value++;
}
} else if (x >= xPos && x <= xPos + mc.fontRenderer.getCharWidth('-')) {
if (value > (allowNegative ? -value : 0)) {
if (value > (allowNegative ? -1 : 0)) {
value--;
}
}

View file

@ -58,6 +58,9 @@ public abstract class PanelComponent {
public final static String COLOR = "color";
public final static String RS_CHANNEL = "rsChannel";
public final static String RS_ID = "rsId";
public final static String HAS_SECOND_CHANNEL = "has2ndChannel";
public final static String RS_CHANNEL2 = "rsChannel2";
public final static String RS_ID2 = "rsId2";
public final static String TEXT = "text";
public static final String HORIZONTAL = "horizontal";
public static final String LENGTH = "length";

View file

@ -48,19 +48,23 @@ import java.util.function.Consumer;
public class PanelMeter extends PanelComponent implements IConfigurableComponent {
public static final String WIDE = "wide";
private int rsInputId;
private byte rsInputChannel;
private byte rsInput;
private int rsInputId, rsInputId2 = -1;
private byte rsInputChannel, rsInputChannel2;
private int rsInput;
private boolean wide = true;
private boolean hasSecond;
public PanelMeter() {
super("panel_meter");
}
public PanelMeter(int rsId, byte rsChannel, boolean wide) {
public PanelMeter(int rsId, byte rsChannel, int rsId2, byte rsChannel2, boolean wide, boolean hasSecond) {
this();
rsInputChannel = rsChannel;
rsInputId = rsId;
rsInputChannel2 = rsChannel2;
rsInputId2 = rsId2;
this.hasSecond = hasSecond;
this.wide = wide;
}
@ -68,6 +72,11 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
nbt.setInteger(RS_ID, rsInputId);
nbt.setByte(RS_CHANNEL, rsInputChannel);
nbt.setBoolean(HAS_SECOND_CHANNEL, hasSecond);
if (hasSecond) {
nbt.setInteger(RS_ID2, rsInputId2);
nbt.setByte(RS_CHANNEL2, rsInputChannel2);
}
nbt.setBoolean(WIDE, wide);
if (!toItem) {
nbt.setInteger("rsInput", rsInput);
@ -78,14 +87,22 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
protected void readCustomNBT(NBTTagCompound nbt) {
rsInputId = nbt.getInteger(RS_ID);
rsInputChannel = nbt.getByte(RS_CHANNEL);
rsInput = nbt.getByte("rsInput");
rsInput = nbt.getInteger("rsInput");
wide = nbt.getBoolean(WIDE);
hasSecond = nbt.getBoolean(HAS_SECOND_CHANNEL);
if (hasSecond) {
rsInputId2 = nbt.getInteger(RS_ID2);
rsInputChannel2 = nbt.getByte(RS_CHANNEL2);
} else {
rsInputId2 = -1;
rsInputChannel2 = -1;
}
}
private static final float SIZE = .25F;
private static final float WIDTH = 1.5F*SIZE;
private static final float BORDER = SIZE /20;
private static final float antiZOffset = .0001F;
private static final float antiZOffset = .001F;
private static final float[] BLACK = {0, 0, 0, 1};
private static final float[] WHITE = {1, 1, 1, 1};
@Override
@ -101,7 +118,7 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
RawModelFontRenderer r = fontRenderer();
r.transform = new Matrix4();
for (int i = 0;i<=3;i++) {
transformNumber(r.transform, (byte)(5*i));
transformNumber(r.transform, 5*17*i);
String asString = Integer.toString(5*i);
int lengthHalf = r.getStringWidth(asString)/2;
r.transform.translate(-lengthHalf*r.scale, 0, -3.5*r.scale);
@ -127,7 +144,7 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
return renderer;
}
private void transformNumber(Matrix4 mat, byte value) {
private void transformNumber(Matrix4 mat, int value) {
if (wide) {
transformNeedle(mat, value);
mat.translate(0, 0, getLength()+1.5*BORDER);
@ -135,22 +152,22 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
} else {
mat.setIdentity().translate(0, antiZOffset, SIZE);
mat.translate(SIZE-3*BORDER, 0, -3*BORDER);
float angle = 90*(1-value/15F);
float angle = 90*(1-value/255F);
angle = (float) (angle*Math.PI/180);
float length = getLength()+BORDER;
mat.translate((float)(-Math.sin(angle)*length), 0, (float)(-Math.cos(angle)*length));
}
}
private void transformNeedle(Matrix4 mat, byte value) {
private void transformNeedle(Matrix4 mat, int value) {
mat.setIdentity().translate(0, 2*antiZOffset, SIZE);
float angle;
if (wide) {
mat.translate(WIDTH/2, 0, -2*BORDER);
angle = 50-(100*(value/15F));
angle = 50-(100*(value/255F));
} else {
mat.translate(SIZE-3*BORDER, 0, -3*BORDER);
angle = 90-(90*(value/15F));
angle = 90-(90*(value/255F));
}
angle = (float) ((180+angle)*Math.PI/180);
mat.rotate(angle, 0, 1, 0);
@ -162,7 +179,7 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
@Nonnull
@Override
public PanelComponent copyOf() {
PanelMeter ret = new PanelMeter(rsInputId, rsInputChannel, wide);
PanelMeter ret = new PanelMeter(rsInputId, rsInputChannel, rsInputId2, rsInputChannel2, wide, hasSecond);
ret.rsInput = rsInput;
ret.setX(x);
ret.setY(y);
@ -189,13 +206,27 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
}
private TileEntityPanel panel;
private Consumer<byte[]> handler = (input) -> {
if (input[rsInputChannel] != rsInput) {
rsInput = input[rsInputChannel];
private Consumer<byte[]> handlerSec = (input) -> {
if (input[rsInputChannel2] != (rsInput&0xf)) {
rsInput = (input[rsInputChannel2]&0xf)|(rsInput&0xf0);
panel.markDirty();
panel.triggerRenderUpdate();
}
};
private Consumer<byte[]> handler = (input) -> {
if (input[rsInputChannel] != rsInput>>4) {
if (hasSecond) {
rsInput = (input[rsInputChannel]<<4)|(rsInput&0xf);
} else {
rsInput = input[rsInputChannel]*17;
}
panel.markDirty();
panel.triggerRenderUpdate();
}
if (rsInputId2==rsInputId) {
handlerSec.accept(input);
}
};
@Nullable
@Override
@ -203,6 +234,9 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
if (matchesId(rsInputId, id)) {
this.panel = panel;
return handler;
} else if (matchesId(rsInputId2, id)) {
this.panel = panel;
return handlerSec;
}
return null;
}
@ -221,18 +255,24 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
PanelMeter that = (PanelMeter) o;
if (rsInputId != that.rsInputId) return false;
if (rsInputId2 != that.rsInputId2) return false;
if (rsInputChannel != that.rsInputChannel) return false;
if (rsInputChannel2 != that.rsInputChannel2) return false;
if (rsInput != that.rsInput) return false;
return wide == that.wide;
if (wide != that.wide) return false;
return hasSecond == that.hasSecond;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + rsInputId;
result = 31 * result + rsInputId2;
result = 31 * result + (int) rsInputChannel;
result = 31 * result + (int) rsInput;
result = 31 * result + (int) rsInputChannel2;
result = 31 * result + rsInput;
result = 31 * result + (wide ? 1 : 0);
result = 31 * result + (hasSecond ? 1 : 0);
return result;
}
@ -267,14 +307,23 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
@Override
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
rsInputChannel = ((NBTTagByte) value).getByte();
break;
case INT:
rsInputId = ((NBTTagInt) value).getInt();
break;
case BOOL:
wide = ((NBTTagByte)value).getByte()!=0;
case RS_CHANNEL:
if (id == 0) {
rsInputChannel = ((NBTTagByte) value).getByte();
} else {
rsInputChannel2 = ((NBTTagByte) value).getByte();
}
break;
case INT:
if (id == 0) {
rsInputId = ((NBTTagInt) value).getInt();
} else {
rsInputId2 = ((NBTTagInt) value).getInt();
hasSecond = rsInputId2>=0;
}
break;
case BOOL:
wide = ((NBTTagByte) value).getByte() != 0;
}
}
@ -300,9 +349,9 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
case FLOAT:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info"+(id==1?"2":""));
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info"+(id==1?"2":""));
default:
return null;
}
@ -311,21 +360,23 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsInputChannel)
new RSChannelConfig("channel", 0, 0, rsInputChannel, false),
new RSChannelConfig("channel2", 60, 0, rsInputChannel2, false)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 45, rsInputId, 2, false)
new IntConfig("rsId", 0, 60, rsInputId, 2, false),
new IntConfig("rsId2", 60, 60, rsInputId2, 2, true)
};
}
@Override
public BoolConfig[] getBooleanOptions() {
return new BoolConfig[]{
new BoolConfig("wide", 70, 10, wide)
new BoolConfig("wide", 0, 80, wide)
};
}

View file

@ -34,24 +34,33 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Slider extends PanelComponent implements IConfigurableComponent {
private static final float WIDTH = .0625F;
private float length = .5F;
private int color = 0xffff00;
private boolean horizontal;
private byte out;
private int out;
private byte rsChannel;
private int rsId;
private boolean hasSecond;
private byte rsChannel2;
private int rsId2 = -1;
private Set<TriConsumer<Integer, Byte, PanelComponent>> secOutputs = new HashSet<>();
public Slider(float length, int color, boolean horizontal, int rsId, byte rsChannel) {
public Slider(float length, int color, boolean horizontal, int rsId, byte rsChannel, boolean hasSecond, int rsId2, byte rsChannel2) {
this();
this.color = color;
this.length = length;
this.horizontal = horizontal;
this.rsChannel = rsChannel;
this.rsId = rsId;
this.hasSecond = hasSecond;
this.rsChannel2 = rsChannel2;
this.rsId2 = rsId2;
}
public Slider() {
@ -63,10 +72,13 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
nbt.setInteger(COLOR, color);
nbt.setFloat(LENGTH, length);
if (!toItem) {
nbt.setByte("output", out);
nbt.setInteger("output", out);
}
nbt.setByte(RS_CHANNEL, rsChannel);
nbt.setInteger(RS_ID, rsId);
nbt.setByte(RS_CHANNEL2, rsChannel2);
nbt.setInteger(RS_ID2, rsId2);
nbt.setBoolean(HAS_SECOND_CHANNEL, hasSecond);
nbt.setBoolean(HORIZONTAL, horizontal);
}
@ -74,9 +86,12 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
protected void readCustomNBT(NBTTagCompound nbt) {
color = nbt.getInteger(COLOR);
length = nbt.getFloat(LENGTH);
out = nbt.getByte("output");
out = nbt.getInteger("output");
rsChannel = nbt.getByte(RS_CHANNEL);
rsId = nbt.getInteger(RS_ID);
rsChannel2 = nbt.getByte(RS_CHANNEL2);
rsId2 = nbt.getInteger(RS_ID2);
hasSecond = nbt.getBoolean(HAS_SECOND_CHANNEL);
horizontal = nbt.getBoolean(HORIZONTAL);
}
@ -91,13 +106,13 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
float[] color = new float[4];
color[3] = 1;
for (int i = 0; i < 3; i++) {
color[i] = ((this.color >> (8 * (2 - i))) & 255) / 255F * (.5F + out / 30F);
color[i] = ((this.color >> (8 * (2 - i))) & 255) / 255F * (.5F + out / 255F/2);
}
float val;
if (horizontal) {
val = (out / 15F) * (length - .0625F);
val = (out / 255F) * (length - .0625F);
} else {
val = (1 - out / 15F) * (length - .0625F);
val = (1 - out / 255F) * (length - .0625F);
}
PanelUtils.addColoredBox(color, GRAY, null, new Vector3f(horizontal ? val : 0, 0, horizontal ? 0 : val),
new Vector3f(.0625F, getHeight(), .0625F), ret, false);
@ -110,7 +125,7 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Nonnull
@Override
public PanelComponent copyOf() {
Slider ret = new Slider(length, color, horizontal, rsId, rsChannel);
Slider ret = new Slider(length, color, horizontal, rsId, rsChannel, hasSecond, rsId2, rsChannel2);
ret.out = out;
ret.setX(x);
ret.setY(y);
@ -130,9 +145,9 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
double pos = horizontal ? hitRelative.x : (length - hitRelative.z);
byte newLevel = (byte) (Math.min(pos * 16 / length, 15));
int newLevel = (int) Math.min(pos * 256 / length, 255);
if (newLevel != out) {
setOut(rsChannel, newLevel);
setOut(newLevel);
out = newLevel;
tile.markDirty();
tile.triggerRenderUpdate();
@ -143,8 +158,18 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (matchesId(rsId, id)) {
super.registerRSOutput(id, out);
out.accept((int) rsChannel, this.out, this);
out.accept((int) rsChannel, (byte) (this.out>>4), this);
}
if (matchesId(rsId2, id)) {
secOutputs.add(out);
out.accept((int) rsChannel, (byte) (this.out&0xf), this);
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
super.unregisterRSOutput(id, out);
secOutputs.remove(out);
}
@Override
@ -171,7 +196,16 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public void invalidate(TileEntityPanel te) {
setOut(rsChannel, 0);
setOut(0);
}
public void setOut(int value) {
super.setOut(rsChannel, value>>4);
if (hasSecond) {
for (TriConsumer<Integer, Byte, PanelComponent> cons:secOutputs) {
cons.accept((int) rsChannel2, (byte) (value&0xf), this);
}
}
}
@Override
@ -187,7 +221,10 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
if (horizontal != slider.horizontal) return false;
if (out != slider.out) return false;
if (rsChannel != slider.rsChannel) return false;
return rsId == slider.rsId;
if (rsId != slider.rsId) return false;
if (hasSecond != slider.hasSecond) return false;
if (rsChannel2 != slider.rsChannel2) return false;
return rsId2 == slider.rsId2;
}
@Override
@ -196,9 +233,12 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
result = 31 * result + (length != +0.0f ? Float.floatToIntBits(length) : 0);
result = 31 * result + color;
result = 31 * result + (horizontal ? 1 : 0);
result = 31 * result + (int) out;
result = 31 * result + out;
result = 31 * result + (int) rsChannel;
result = 31 * result + rsId;
result = 31 * result + (hasSecond ? 1 : 0);
result = 31 * result + (int) rsChannel2;
result = 31 * result + rsId2;
return result;
}
@ -209,10 +249,19 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
horizontal = ((NBTTagByte) value).getByte() != 0;
break;
case RS_CHANNEL:
rsChannel = ((NBTTagByte) value).getByte();
if (id==0) {
rsChannel = ((NBTTagByte) value).getByte();
} else {
rsChannel2 = ((NBTTagByte) value).getByte();
}
break;
case INT:
rsId = ((NBTTagInt) value).getInt();
if (id==0) {
rsId = ((NBTTagInt) value).getInt();
} else {
rsId2 = ((NBTTagInt) value).getInt();
hasSecond = rsId2>=0;
}
break;
case FLOAT:
if (id < 3) {
@ -249,9 +298,9 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
case BOOL:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info"+(id==0?"":"2"));
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info"+(id==0?"":"2"));
case FLOAT:
return null;
default:
@ -262,14 +311,16 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsChannel)
new RSChannelConfig("channel", 0, 0, rsChannel, true),
new RSChannelConfig("channel", 30, 0, rsChannel2, true)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 50, rsId, 2, false)
new IntConfig("rsId", 0, 30, rsId, 2, false),
new IntConfig("rsId", 30, 30, rsId2, 2, true)
};
}

View file

@ -39,7 +39,9 @@ import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Variac extends PanelComponent implements IConfigurableComponent {
private static final float SIZE = 3 / 16F;
@ -51,14 +53,21 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
private static final float rodOffset = (SIZE - rodDia) / 2;
private static final float arrowSize = .0625F / 2;
private byte out;
private int out;
private byte rsChannel;
private int rsId;
private boolean hasSecond;
private byte rsChannel2;
private int rsId2 = -1;
private Set<TriConsumer<Integer, Byte, PanelComponent>> secOutputs = new HashSet<>();
public Variac(int rsId, byte rsChannel) {
public Variac(int rsId, byte rsChannel, int rsId2, byte rsChannel2, boolean hasSecond) {
this();
this.rsChannel = rsChannel;
this.rsId = rsId;
this.hasSecond = hasSecond;
this.rsChannel2 = rsChannel2;
this.rsId2 = rsId2;
}
public Variac() {
@ -68,23 +77,29 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
if (!toItem) {
nbt.setByte("output", out);
nbt.setInteger("output", out);
}
nbt.setByte(RS_CHANNEL, rsChannel);
nbt.setInteger(RS_ID, rsId);
nbt.setByte(RS_CHANNEL2, rsChannel2);
nbt.setInteger(RS_ID2, rsId2);
nbt.setBoolean(HAS_SECOND_CHANNEL, hasSecond);
}
@Override
protected void readCustomNBT(NBTTagCompound nbt) {
out = nbt.getByte("output");
out = nbt.getInteger("output");
rsChannel = nbt.getByte(RS_CHANNEL);
rsId = nbt.getInteger(RS_ID);
rsChannel2 = nbt.getByte(RS_CHANNEL2);
rsId2 = nbt.getInteger(RS_ID2);
hasSecond = nbt.getBoolean(HAS_SECOND_CHANNEL);
}
@Override
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
float angle = -(float) (2 * Math.PI * (.5 + out) / 17F);
float angle = -(float) (2 * Math.PI * (8.5 + out) / (17F*16F));
Matrix4 mat = new Matrix4();
mat.translate(SIZE / 2, 0, SIZE / 2);
mat.rotate(angle, 0, 1, 0);
@ -110,7 +125,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
@Nonnull
@Override
public PanelComponent copyOf() {
Variac ret = new Variac(rsId, rsChannel);
Variac ret = new Variac(rsId, rsChannel, rsId2, rsChannel2, hasSecond);
ret.out = out;
ret.setX(x);
ret.setY(y);
@ -137,20 +152,20 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
} else if (angle > 2 * Math.PI) {
angle -= 2 * Math.PI;
}
angle -= .5 * Math.PI / 17;
angle /= 2 * Math.PI;
if (angle < 0 || angle >= 16 / 17D) {
return;
int step = (hasSecond&&player.isSneaking())?1:16;
int newLevel = (int) ((angle-1/34F) * 17 * 16);
int diff = Math.abs(newLevel-out);
if (diff>step) {
if (newLevel > out) {
newLevel = out + step;
} else if (newLevel < out) {
newLevel = out - step;
}
}
byte newLevel = (byte) (angle * 17);
if (newLevel > out) {
newLevel = (byte) (out + 1);
} else if (newLevel < out) {
newLevel = (byte) (out - 1);
}
newLevel = (byte) Math.max(0, Math.min(newLevel, 15));
newLevel = Math.max(0, Math.min(newLevel, 255));
if (newLevel != out) {
setOut(rsChannel, newLevel);
setOut(newLevel);
out = newLevel;
tile.markDirty();
tile.triggerRenderUpdate();
@ -161,8 +176,18 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
public void registerRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
if (matchesId(rsId, id)) {
super.registerRSOutput(id, out);
out.accept((int) rsChannel, this.out, this);
out.accept((int) rsChannel, (byte) (this.out>>4), this);
}
if (matchesId(rsId2, id)) {
secOutputs.add(out);
out.accept((int)rsChannel2, (byte) (this.out&0xf), this);
}
}
@Override
public void unregisterRSOutput(int id, @Nonnull TriConsumer<Integer, Byte, PanelComponent> out) {
super.unregisterRSOutput(id, out);
secOutputs.remove(out);
}
@Override
@ -197,7 +222,16 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
@Override
public void invalidate(TileEntityPanel te) {
setOut(rsChannel, 0);
setOut(0);
}
public void setOut(int level) {
if (hasSecond) {
for (TriConsumer<Integer, Byte, PanelComponent> cons:secOutputs) {
cons.accept((int)rsChannel2, (byte) (level&0xf), this);
}
}
super.setOut(rsChannel, (byte)(level>>4));
}
@Override
@ -209,14 +243,22 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
Variac variac = (Variac) o;
if (out != variac.out) return false;
return rsChannel == variac.rsChannel;
if (rsChannel != variac.rsChannel) return false;
if (rsId != variac.rsId) return false;
if (hasSecond != variac.hasSecond) return false;
if (rsChannel2 != variac.rsChannel2) return false;
return rsId2 == variac.rsId2;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (int) out;
result = 31 * result + out;
result = 31 * result + (int) rsChannel;
result = 31 * result + rsId;
result = 31 * result + (hasSecond ? 1 : 0);
result = 31 * result + (int) rsChannel2;
result = 31 * result + rsId2;
return result;
}
@ -224,10 +266,19 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
public void applyConfigOption(IConfigurableComponent.ConfigType type, int id, NBTBase value) {
switch (type) {
case RS_CHANNEL:
rsChannel = ((NBTTagByte) value).getByte();
if (id==0) {
rsChannel = ((NBTTagByte) value).getByte();
} else {
rsChannel2 = ((NBTTagByte) value).getByte();
}
break;
case INT:
rsId = ((NBTTagInt) value).getInt();
if (id==0) {
rsId = ((NBTTagInt) value).getInt();
} else {
rsId2 = ((NBTTagInt) value).getInt();
hasSecond = rsId2>=0;
}
break;
}
}
@ -240,26 +291,28 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
@Override
public String fomatConfigDescription(IConfigurableComponent.ConfigType type, int id) {
switch (type) {
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
default:
return "INVALID?";
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info" + (id == 1 ? "2" : ""));
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info" + (id == 1 ? "2" : ""));
default:
return "INVALID?";
}
}
@Override
public IConfigurableComponent.RSChannelConfig[] getRSChannelOptions() {
return new IConfigurableComponent.RSChannelConfig[]{
new IConfigurableComponent.RSChannelConfig("channel", 0, 0, rsChannel)
new IConfigurableComponent.RSChannelConfig("channel", 0, 0, rsChannel),
new IConfigurableComponent.RSChannelConfig("channel", 90, 0, rsChannel2)
};
}
@Override
public IConfigurableComponent.IntConfig[] getIntegerOptions() {
return new IConfigurableComponent.IntConfig[]{
new IConfigurableComponent.IntConfig("rsId", 0, 50, rsId, 2, false)
new IConfigurableComponent.IntConfig("rsId", 0, 50, rsId, 2, false),
new IConfigurableComponent.IntConfig("rsId", 90, 50, rsId2, 2, true)
};
}

View file

@ -57,8 +57,10 @@ industrialwires.desc.disable_snap=Allow free placing of components
industrialwires.desc.latching=Latching
industrialwires.desc.latching_info=Does this button stay on indefinitely?
industrialwires.desc.disassemble=Disassemble the panel
industrialwires.desc.rsid_info=The ID of the redstone wire controller to output a signal to
industrialwires.desc.rschannel_info=The color of the channel to output the signal to
industrialwires.desc.rsid_info=The ID of the redstone wire controller to interact with
industrialwires.desc.rschannel_info=The color of the channel to use
industrialwires.desc.rsid_info2=The ID of the redstone wire controller to interact with for the second signal. Set to -1 to disable it.
industrialwires.desc.rschannel_info2=The color of the channel to use for the second signal
industrialwires.desc.label_text=The text in this label
industrialwires.desc.red=Red
industrialwires.desc.green=Green