Added a seven-segment display for control panels

This commit is contained in:
malte0811 2017-10-31 16:29:38 +01:00
parent e21684818f
commit 09161bce5f
21 changed files with 500 additions and 73 deletions

View file

@ -31,6 +31,7 @@ import malte0811.industrialWires.blocks.hv.TileEntityJacobsLadder;
import malte0811.industrialWires.blocks.hv.TileEntityMarx;
import malte0811.industrialWires.blocks.wire.*;
import malte0811.industrialWires.compat.Compat;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.crafting.Recipes;
import malte0811.industrialWires.hv.MarxOreHandler;
@ -212,6 +213,7 @@ public class IndustrialWires {
IWPotions.init();
Compat.init();
MarxOreHandler.init();
PanelComponent.init();
}
@EventHandler

View file

@ -231,7 +231,8 @@ public class ClientProxy extends CommonProxy {
new ManualPages.Crafting(m, "industrialwires.variac", new ItemStack(IndustrialWires.panelComponent, 1, 4)),
new ManualPages.CraftingMulti(m, "industrialwires.lock", new ItemStack(IndustrialWires.panelComponent, 1, 7), new ItemStack(IndustrialWires.key)),
new ManualPages.Crafting(m, "industrialwires.lock1", new ItemStack(IndustrialWires.key, 1, 2)),
new ManualPages.Crafting(m, "industrialwires.panel_meter", new ItemStack(IndustrialWires.panelComponent, 1, 8))
new ManualPages.Crafting(m, "industrialwires.panel_meter", new ItemStack(IndustrialWires.panelComponent, 1, 8)),
new ManualPages.Crafting(m, "industrialwires.7seg", new ItemStack(IndustrialWires.panelComponent, 1, 9))
);
List<MarxOreHandler.OreInfo> ores = MarxOreHandler.getRecipes();
String text = I18n.format("ie.manual.entry.industrialwires.marx");

View file

@ -41,7 +41,7 @@ public class RawModelFontRenderer extends FontRenderer {
float[] colorA = new float[4];
private ImmutableList.Builder<RawQuad> builder = ImmutableList.builder();
private final Vector3f normal = new Vector3f(0, 1, 0);
public final float scale;
private float scale;
public Matrix4 transform = null;
private static TextureAtlasSprite sprite = null;
@ -60,6 +60,10 @@ public class RawModelFontRenderer extends FontRenderer {
onResourceManagerReload(null);
}
public void setScale(float scale) {
this.scale = scale / (9 * 16);
}
@Override
protected float renderDefaultChar(int pos, boolean italic) {
float x = (pos % 16);
@ -124,4 +128,8 @@ public class RawModelFontRenderer extends FontRenderer {
protected void bindTexture(@Nonnull ResourceLocation location) {
//NO-OP
}
public float getScale() {
return scale;
}
}

View file

@ -28,6 +28,8 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -43,6 +45,7 @@ public class CoveredToggleSwitch extends ToggleSwitch {
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
float[] color = PanelUtils.getFloatColor(true, this.color);
active = state.active;
@ -72,6 +75,7 @@ public class CoveredToggleSwitch extends ToggleSwitch {
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
super.renderInGUIDefault(gui, 0xff000000 | this.color);
super.renderInGUI(gui);

View file

@ -31,6 +31,8 @@ import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -77,6 +79,7 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
private static final float size = .0625F;
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
float[] color = new float[4];
color[3] = 1;
@ -165,6 +168,7 @@ public class IndicatorLight extends PanelComponent implements IConfigurableCompo
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, colorA);
}

View file

@ -33,6 +33,7 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -65,8 +66,10 @@ public class Label extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
RawModelFontRenderer render = RawModelFontRenderer.get();
render.setScale(1);
render.drawString(text, 0, 0, 0xff000000 | color);
return render.build();
}
@ -87,8 +90,8 @@ public class Label extends PanelComponent implements IConfigurableComponent {
if (aabb == null) {
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
RawModelFontRenderer fr = RawModelFontRenderer.get();
float width = fr.getStringWidth(text) * fr.scale;
float height = fr.FONT_HEIGHT * fr.scale;
float width = fr.getStringWidth(text) * fr.getScale();
float height = fr.FONT_HEIGHT * fr.getScale();
aabb = new AxisAlignedBB(getX(), 0, getY(), getX() + width, 0, getY() + height);
} else {
aabb = new AxisAlignedBB(getX(), 0, getY(), getX() + .001, 0, getY() + .001);
@ -117,6 +120,7 @@ public class Label extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
int left = (int) (gui.getX0() + getX() * gui.panelSize);
int top = (int) (gui.getY0() + getY() * gui.panelSize);

View file

@ -31,6 +31,8 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -83,6 +85,7 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
private final static float size = .0625F;
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
float[] color = PanelUtils.getFloatColor(active, this.color);
List<RawQuad> ret = new ArrayList<>(5);
@ -152,6 +155,7 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, 0xff000000 | color);
}

View file

@ -38,6 +38,8 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -105,7 +107,7 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
private final static float size = .0625F;
private final static float keyWidth = .125F * size;
private final static float yOffset = size / 2 + .0001F;
private final static float yOffset = size / 2 + Y_DELTA;
private final static float xOffset = (size - keyWidth) / 2;
private final static float[] DARK_GRAY = {.4F, .4F, .4F};
private final static int DARK_GRAY_INT = 0xFF686868;
@ -115,6 +117,7 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>(5);
PanelUtils.addColoredBox(GRAY, GRAY, null, new Vector3f(0, 0, 0), new Vector3f(size, size / 2, size), ret, false);
@ -229,6 +232,7 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, GRAY_INT);
AxisAlignedBB aabb = getBlockRelativeAABB();

View file

@ -22,7 +22,6 @@ import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import malte0811.industrialWires.util.MiscUtils;
import malte0811.industrialWires.util.TriConsumer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
@ -33,7 +32,6 @@ import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.Level;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -42,12 +40,15 @@ import java.util.function.Consumer;
import java.util.function.Supplier;
public abstract class PanelComponent {
public static final float Y_DELTA = .001F;
protected float panelHeight;
protected AxisAlignedBB aabb = null;
protected float x, y;
private final String type;
protected final static float[] GRAY = {.8F, .8F, .8F};
protected final static int GRAY_INT = 0xFFD0D0D0;
protected static final float[] BLACK = {0, 0, 0, 1};
private Set<TriConsumer<Integer, Byte, PanelComponent>> outputs = new HashSet<>();
protected PanelComponent(String type) {
@ -58,7 +59,6 @@ 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";
@ -66,7 +66,7 @@ public abstract class PanelComponent {
public static final String LENGTH = "length";
public static final String LATCHING = "latching";
static {
public static void init() {
baseCreaters.put("lighted_button", LightedButton::new);
baseCreaters.put("label", Label::new);
baseCreaters.put("indicator_light", IndicatorLight::new);
@ -76,6 +76,20 @@ public abstract class PanelComponent {
baseCreaters.put("toggle_switch_covered", CoveredToggleSwitch::new);
baseCreaters.put("lock", Lock::new);
baseCreaters.put("panel_meter", PanelMeter::new);
baseCreaters.put(SevenSegDisplay.NAME, SevenSegDisplay::new);
//Check that all components implement equals+hashCode if in a dev env
boolean isDevEnv = "NBTTagCompound".equals(NBTTagCompound.class.getSimpleName());
if (isDevEnv) {
for (Supplier<PanelComponent> sup:baseCreaters.values()) {
PanelComponent comp = sup.get();
try {
comp.getClass().getDeclaredMethod("equals", Object.class);
comp.getClass().getDeclaredMethod("hashCode");
} catch (NoSuchMethodException e) {
throw new RuntimeException(comp.getClass()+" lacks equals or hasCode! This will break the cache!", e);
}
}
}
}
protected abstract void writeCustomNBT(NBTTagCompound nbt, boolean toItem);
@ -83,6 +97,7 @@ public abstract class PanelComponent {
protected abstract void readCustomNBT(NBTTagCompound nbt);
// DON'T OFFSET BY x, y IN THIS METHOD!
@SideOnly(Side.CLIENT)
public abstract List<RawQuad> getQuads();
@Nonnull
@ -189,8 +204,10 @@ public abstract class PanelComponent {
GlStateManager.popMatrix();
}
@SideOnly(Side.CLIENT)
public abstract void renderInGUI(GuiPanelCreator gui);
@SideOnly(Side.CLIENT)
public void renderInGUIDefault(GuiPanelCreator gui, int color) {
color |= 0xff000000;
AxisAlignedBB aabb = getBlockRelativeAABB();

View file

@ -35,6 +35,8 @@ import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -100,26 +102,27 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
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 = .001F;
private static final float[] BLACK = {0, 0, 0, 1};
private static final float[] WHITE = {1, 1, 1, 1};
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
float width = wide?WIDTH:SIZE;
//main panel
PanelUtils.addColoredQuad(ret, new Vector3f(), new Vector3f(0, 0, SIZE), new Vector3f(width, 0, SIZE),
new Vector3f(width, 0, 0), EnumFacing.UP, BLACK);
PanelUtils.addColoredQuad(ret, new Vector3f(BORDER, antiZOffset, BORDER), new Vector3f(BORDER, antiZOffset, SIZE-BORDER),
new Vector3f(width-BORDER, antiZOffset, SIZE-BORDER), new Vector3f(width-BORDER, antiZOffset, BORDER), EnumFacing.UP, WHITE);
PanelUtils.addColoredQuad(ret, new Vector3f(BORDER, Y_DELTA, BORDER), new Vector3f(BORDER, Y_DELTA, SIZE-BORDER),
new Vector3f(width-BORDER, Y_DELTA, SIZE-BORDER), new Vector3f(width-BORDER, Y_DELTA, BORDER), EnumFacing.UP, WHITE);
RawModelFontRenderer r = RawModelFontRenderer.get();
r.setScale(.5F);
r.transform = new Matrix4();
for (int i = 0;i<=3;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);
r.transform.translate(-lengthHalf*r.getScale(), 0, -3.5*r.getScale());
r.drawString(asString, 0, 0, 0xff000000);
ret.addAll(r.build());
}
@ -139,7 +142,7 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
mat.translate(0, 0, getLength()+1.5*BORDER);
mat.scale(-1, 1, -1);
} else {
mat.setIdentity().translate(0, antiZOffset, SIZE);
mat.setIdentity().translate(0, Y_DELTA, SIZE);
mat.translate(SIZE-3*BORDER, 0, -3*BORDER);
float angle = 90*(1-value/255F);
angle = (float) (angle*Math.PI/180);
@ -149,7 +152,7 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
}
private void transformNeedle(Matrix4 mat, int value) {
mat.setIdentity().translate(0, 2*antiZOffset, SIZE);
mat.setIdentity().translate(0, 2*Y_DELTA, SIZE);
float angle;
if (wide) {
mat.translate(WIDTH/2, 0, -2*BORDER);
@ -266,6 +269,7 @@ public class PanelMeter extends PanelComponent implements IConfigurableComponent
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, 0);
AxisAlignedBB aabb = getBlockRelativeAABB();

View file

@ -83,7 +83,7 @@ public final class PanelUtils {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < components.size(); i++) {
PanelComponent pc = components.get(i);
Matrix4 m4Here = m4.copy().translate(pc.getX(), .0001, pc.getY());
Matrix4 m4Here = m4.copy().translate(pc.getX(), PanelComponent.Y_DELTA, pc.getY());
List<RawQuad> compQuads = pc.getQuads();
for (RawQuad bq : compQuads) {
ret.add(bakeQuad(bq, m4Here, m4RotOnly));
@ -277,52 +277,54 @@ public final class PanelUtils {
public static void addInfo(ItemStack stack, List<String> list, NBTTagCompound data) {
switch (stack.getMetadata()) {
case 0: //button
addCommonInfo(data, list, true, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
case 1: //label
if (data.hasKey(TEXT)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.text", data.getString(TEXT)));
}
addCommonInfo(data, list, true, false);
break;
case 2: //indicator light
addCommonInfo(data, list, true, true);
break;
case 3: //slider
addCommonInfo(data, list, true, true);
if (data.hasKey(HORIZONTAL)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(HORIZONTAL) ? "horizontal" : "vertical")));
}
if (data.hasKey(LENGTH)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.length", data.getFloat(LENGTH)));
}
case 0: //button
addCommonInfo(data, list, true, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
case 1: //label
if (data.hasKey(TEXT)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.text", data.getString(TEXT)));
}
addCommonInfo(data, list, true, false);
break;
case 2: //indicator light
addCommonInfo(data, list, true, true);
break;
case 3: //slider
addCommonInfo(data, list, true, true);
if (data.hasKey(HORIZONTAL)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(HORIZONTAL) ? "horizontal" : "vertical")));
}
if (data.hasKey(LENGTH)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.length", data.getFloat(LENGTH)));
}
break;
case 4://variac
addCommonInfo(data, list, false, true);
break;
case 5://Toggle switch
addCommonInfo(data, list, false, true);
break;
case 6://Covered toggle switch
addCommonInfo(data, list, true, true);
break;
case 7://Lock
addCommonInfo(data, list, false, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
case 8://Panel meter
addCommonInfo(data, list, false, true);
if (data.hasKey(PanelMeter.WIDE)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(PanelMeter.WIDE) ? "wide" : "narrow")));
}
break;
break;
case 4://variac
addCommonInfo(data, list, false, true);
break;
case 5://Toggle switch
addCommonInfo(data, list, false, true);
break;
case 6://Covered toggle switch
addCommonInfo(data, list, true, true);
break;
case 7://Lock
addCommonInfo(data, list, false, true);
if (data.hasKey(LATCHING)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(LATCHING) ? "latching" : "instantaneous")));
}
break;
case 8://Panel meter
addCommonInfo(data, list, false, true);
if (data.hasKey(PanelMeter.WIDE)) {
list.add(I18n.format(IndustrialWires.MODID + ".tooltip." + (data.getBoolean(PanelMeter.WIDE) ? "wide" : "narrow")));
}
break;
case 9://7-digit display
addCommonInfo(data, list, true, true);
}
}

View file

@ -0,0 +1,330 @@
/*
* This file is part of Industrial Wires.
* Copyright (C) 2016-2017 malte0811
* Industrial Wires is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Industrial Wires is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
*/
package malte0811.industrialWires.controlpanel;
import com.sun.javafx.geom.Vec2f;
import malte0811.industrialWires.IndustrialWires;
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.client.RawQuad;
import malte0811.industrialWires.client.gui.GuiPanelCreator;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import static malte0811.industrialWires.util.MiscUtils.*;
public class SevenSegDisplay extends PanelComponent implements IConfigurableComponent {
public static final String NAME = "7seg";
private static final float sizeX = 1.5F/16;
private static final float sizeY = 3.0F/16;
/*
0
1 2
3
4 5
6
*/
private static final boolean[][] numbers = {
{true, true, true, false, true, true, true},//0
{false, false, true, false, false, true, false},//1
{true, false, true, true, true, false, true},//2
{true, false, true, true, false, true, true},//3
{false, true, true, true, false, true, false},//4
{true, true, false, true, false, true, true},//5
{true, true, false, true, true, true, true},//6
{true, false, true, false, false, true, false},//7
{true, true, true, true, true, true, true},//8
{true, true, true, true, false, true, true},//9
{true, true, true, true, true, true, false},//A
{false, true, false, true, true, true, true},//b
{true, true, false, false, true, false, true},//C
{false, false, true, true, true, true, true},//d
{true, true, false, true, true, false, true},//E
{true, true, false, true, true, false, false}//F
};
/*
0 1
2 3
4 5
*/
@SideOnly(Side.CLIENT)
private static Vec2f[][] positions;
private int color = 0xff00;
private byte input = 0;
private int rsInputId;
private byte rsInputChannel;
public SevenSegDisplay() {
super(NAME);
}
public SevenSegDisplay(int rsId, byte rsChannel, int color) {
this();
this.color = color;
rsInputChannel = rsChannel;
rsInputId = rsId;
}
@Override
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
nbt.setInteger(RS_ID, rsInputId);
nbt.setByte(RS_CHANNEL, rsInputChannel);
nbt.setInteger(COLOR, color);
if (!toItem) {
nbt.setInteger("rsInput", input);
}
}
@Override
protected void readCustomNBT(NBTTagCompound nbt) {
rsInputId = nbt.getInteger(RS_ID);
rsInputChannel = nbt.getByte(RS_CHANNEL);
color = nbt.getInteger(COLOR);
input = nbt.getByte("rsInput");
}
private TileEntityPanel panel;
private Consumer<byte[]> handler = (inputNew) -> {
if (inputNew[rsInputChannel] != input) {
input = inputNew[rsInputChannel];
panel.markDirty();
panel.triggerRenderUpdate();
}
};
@Nullable
@Override
public Consumer<byte[]> getRSInputHandler(int id, TileEntityPanel panel) {
if (matchesId(rsInputId, id)) {
this.panel = panel;
return handler;
}
return null;
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
if (positions==null) {
positions = new Vec2f[7][6];
Vec2f[][] startAndEnd = {
{new Vec2f(1F/4*sizeX, 2F/8*sizeY), new Vec2f(3F/4*sizeX, 2F/8*sizeY)},
{new Vec2f(1F/4*sizeX, 2F/8*sizeY), new Vec2f(1F/4*sizeX, 4F/8*sizeY)},
{new Vec2f(3F/4*sizeX, 2F/8*sizeY), new Vec2f(3F/4*sizeX, 4F/8*sizeY)},
{new Vec2f(1F/4*sizeX, 4F/8*sizeY), new Vec2f(3F/4*sizeX, 4F/8*sizeY)},
{new Vec2f(1F/4*sizeX, 4F/8*sizeY), new Vec2f(1F/4*sizeX, 6F/8*sizeY)},
{new Vec2f(3F/4*sizeX, 4F/8*sizeY), new Vec2f(3F/4*sizeX, 6F/8*sizeY)},
{new Vec2f(1F/4*sizeX, 6F/8*sizeY), new Vec2f(3F/4*sizeX, 6F/8*sizeY)}
};
for (int i = 0;i<7;i++) {
positions[i][2] = startAndEnd[i][0];
positions[i][3] = startAndEnd[i][1];
Vec2f dir = scale(subtract(startAndEnd[i][0], startAndEnd[i][1]), 1F/8);
Vec2f perpend = rotate90(dir);
positions[i][1] = add(add(startAndEnd[i][1], perpend), dir);
positions[i][5] = add(subtract(startAndEnd[i][1], perpend), dir);
positions[i][0] = subtract(add(startAndEnd[i][0], perpend), dir);
positions[i][4] = subtract(subtract(startAndEnd[i][0], perpend), dir);
}
}
List<RawQuad> ret = new ArrayList<>();
PanelUtils.addColoredQuad(ret, new Vector3f(0, 0, 0), new Vector3f(0, 0, sizeY), new Vector3f(sizeX, 0, sizeY),
new Vector3f(sizeX, 0, 0), EnumFacing.UP, BLACK);
float[] colorOn = PanelUtils.getFloatColor(true, this.color);
float[] colorOff = PanelUtils.getFloatColor(false, this.color);
for (int i = 0;i<7;i++) {
float[] colorToUse = numbers[input][i]?colorOn:colorOff;
Vec2f[] pointsForSegment = positions[i];
PanelUtils.addColoredQuad(ret,
withNewY(pointsForSegment[1], Y_DELTA),
withNewY(pointsForSegment[0], Y_DELTA),
withNewY(pointsForSegment[2], Y_DELTA),
withNewY(pointsForSegment[3], Y_DELTA),
EnumFacing.UP, colorToUse);
PanelUtils.addColoredQuad(ret,
withNewY(pointsForSegment[3], Y_DELTA),
withNewY(pointsForSegment[2], Y_DELTA),
withNewY(pointsForSegment[4], Y_DELTA),
withNewY(pointsForSegment[5], Y_DELTA),
EnumFacing.UP, colorToUse);
}
return ret;
}
@Nonnull
@Override
public PanelComponent copyOf() {
SevenSegDisplay ret = new SevenSegDisplay(rsInputId, rsInputChannel, color);
ret.input = input;
ret.setX(x);
ret.setY(y);
ret.panelHeight = panelHeight;
return ret;
}
@Nonnull
@Override
public AxisAlignedBB getBlockRelativeAABB() {
if (aabb == null) {
aabb = new AxisAlignedBB(x, 0, y, x + sizeX, 0, y + sizeY);
}
return aabb;
}
@Override
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
//NOP
}
@Override
public void update(TileEntityPanel tile) {
//NOP
}
@Override
public int getColor() {
return color;
}
@Override
public float getHeight() {
return 0;
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
color |= 0xff000000;
renderInGUIDefault(gui, 0xff000000);
AxisAlignedBB aabb = getBlockRelativeAABB();
int left = (int) (gui.getX0() + (aabb.minX+sizeX/4) * gui.panelSize);
int top = (int) (gui.getY0() + (aabb.minZ+sizeY/4) * gui.panelSize);
int sizeX = (int) (SevenSegDisplay.sizeX/2 * gui.panelSize);
int sizeY = (int) (SevenSegDisplay.sizeY/2 * gui.panelSize);
Gui.drawRect(left, top, left+sizeX, top+sizeY, color);
final int width = 1;
Gui.drawRect(left+width, top+width, left+sizeX-width, top+sizeY/2-width, 0xff000000);
Gui.drawRect(left+width, top+sizeY/2+width, left+sizeX-width, top+sizeY-width, 0xff000000);
}
@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 FLOAT:
color = PanelUtils.setColor(color, id, value);
break;
}
}
@Nullable
@Override
public String fomatConfigName(ConfigType type, int id) {
switch (type) {
case FLOAT:
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
case RS_CHANNEL:
case INT:
default:
return null;
}
}
@Nullable
@Override
public String fomatConfigDescription(ConfigType type, int id) {
switch (type) {
case FLOAT:
return null;
case RS_CHANNEL:
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
case INT:
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
default:
return null;
}
}
@Override
public RSChannelConfig[] getRSChannelOptions() {
return new RSChannelConfig[]{
new RSChannelConfig("channel", 0, 0, rsInputChannel)
};
}
@Override
public IntConfig[] getIntegerOptions() {
return new IntConfig[]{
new IntConfig("rsId", 0, 45, rsInputId, 2, false)
};
}
@Override
public FloatConfig[] getFloatOptions() {
float[] color = PanelUtils.getFloatColor(true, this.color);
int x = 70;
int yOffset = 10;
return new FloatConfig[]{
new FloatConfig("red", x, yOffset, color[0], 60),
new FloatConfig("green", x, yOffset + 20, color[1], 60),
new FloatConfig("blue", x, yOffset + 40, color[2], 60)
};
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
SevenSegDisplay that = (SevenSegDisplay) o;
if (color != that.color) return false;
return input == that.input;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + color;
result = 31 * result + (int) input;
return result;
}
}

View file

@ -30,6 +30,8 @@ import net.minecraft.nbt.*;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -99,13 +101,13 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
final float yOff = .001F;
float xSize = horizontal ? length : WIDTH;
float ySize = horizontal ? WIDTH : length;
PanelUtils.addColoredQuad(ret, new Vector3f(0, yOff, 0), new Vector3f(0, yOff, ySize), new Vector3f(xSize, yOff, ySize), new Vector3f(xSize, yOff, 0),
EnumFacing.UP, GRAY);
PanelUtils.addColoredQuad(ret, new Vector3f(0, 0, 0), new Vector3f(0, 0, ySize), new Vector3f(xSize, 0, ySize),
new Vector3f(xSize, 0, 0), EnumFacing.UP, GRAY);
float[] color = new float[4];
color[3] = 1;
for (int i = 0; i < 3; i++) {
@ -186,6 +188,7 @@ public class Slider extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
renderInGUIDefault(gui, GRAY_INT);
double middleX = (getX() + (horizontal ? length : .0625) / 2);

View file

@ -34,6 +34,8 @@ import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -80,15 +82,15 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
protected float sizeY = 1.5F * sizeX;
protected float rodRadius = sizeX * .25F;
protected float rodLength = 3 / 32F;
protected float yOffset = .0001F;
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
PanelUtils.addColoredQuad(ret, new Vector3f(sizeX, yOffset, (sizeY - sizeX) / 2),
new Vector3f(0, yOffset, (sizeY - sizeX) / 2),
new Vector3f(0, yOffset, (sizeY + sizeX) / 2),
new Vector3f(sizeX, yOffset, (sizeY + sizeX) / 2), EnumFacing.UP, GRAY);
PanelUtils.addColoredQuad(ret, new Vector3f(sizeX, 0, (sizeY - sizeX) / 2),
new Vector3f(0, 0, (sizeY - sizeX) / 2),
new Vector3f(0, 0, (sizeY + sizeX) / 2),
new Vector3f(sizeX, 0, (sizeY + sizeX) / 2), EnumFacing.UP, GRAY);
Matrix4 rot = new Matrix4();
rot.translate((sizeX) / 2, -.01F, sizeY / 2);
rot.rotate(Math.PI * 1 / 16 * (active ? -1 : 1), 1, 0, 0);
@ -142,6 +144,7 @@ public class ToggleSwitch extends PanelComponent implements IConfigurableCompone
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
AxisAlignedBB aabb = getBlockRelativeAABB();
double zOffset = (aabb.maxZ - aabb.minZ - sizeX) / 2;

View file

@ -35,6 +35,8 @@ import net.minecraft.nbt.NBTTagInt;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.Vec3d;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
@ -100,6 +102,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public List<RawQuad> getQuads() {
List<RawQuad> ret = new ArrayList<>();
float angle = -(float) (2 * Math.PI * (8.5 + out) / (17F*16F));
@ -118,7 +121,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
new Vector3f(innerSize, getHeight() / 2, innerSize), ret, false, mat);
mat.translate(SIZE / 2, 0, SIZE / 2);
mat.rotate(Math.PI / 2, 0, 1, 0);
mat.translate(-SIZE / 2, .0001, -SIZE / 2);
mat.translate(-SIZE / 2, Y_DELTA, -SIZE / 2);
PanelUtils.addColoredQuad(ret, new Vector3f(offset, getHeight(), offset), new Vector3f(offset, getHeight(), offset),
new Vector3f(offset + arrowSize / 2, getHeight(), offset + arrowSize),
new Vector3f(offset + arrowSize, getHeight(), offset + arrowSize / 2), EnumFacing.UP, white, mat);
@ -204,6 +207,7 @@ public class Variac extends PanelComponent implements IConfigurableComponent {
}
@Override
@SideOnly(Side.CLIENT)
public void renderInGUI(GuiPanelCreator gui) {
AxisAlignedBB aabb = getBlockRelativeAABB();
int left = (int) Math.ceil(gui.getX0() + (offset + aabb.minX) * gui.panelSize);

View file

@ -27,6 +27,7 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.controlpanel.PanelUtils;
import malte0811.industrialWires.controlpanel.SevenSegDisplay;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.state.IBlockState;
@ -55,7 +56,7 @@ import java.util.List;
public class ItemPanelComponent extends Item implements INetGUIItem {
public static final String[] types = {
"lighted_button", "label", "indicator_light", "slider", "variac", "toggle_switch", "toggle_switch_covered",
"lock", "panel_meter"
"lock", "panel_meter", SevenSegDisplay.NAME
};
public static final String TYPE = "type";
public static final String ID = "cfgId";

View file

@ -23,10 +23,10 @@ import blusunrize.immersiveengineering.api.ApiUtils;
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
import blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler;
import blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces;
import blusunrize.immersiveengineering.common.util.IELogger;
import blusunrize.immersiveengineering.common.util.Utils;
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
import com.google.common.collect.ImmutableSet;
import com.sun.javafx.geom.Vec2f;
import malte0811.industrialWires.IndustrialWires;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@ -40,6 +40,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.common.property.IExtendedBlockState;
import org.lwjgl.util.vector.Vector3f;
import javax.annotation.Nonnull;
import java.util.ArrayList;
@ -221,4 +222,26 @@ public final class MiscUtils {
return false;
}
//End of code from TEImmersiveConnectable
public static Vec2f rotate90(Vec2f in) {
//Yes, when rotating by 90 degrees, x becomes y!
//noinspection SuspiciousNameCombination
return new Vec2f(-in.y, in.x);
}
public static Vec2f subtract(Vec2f a, Vec2f b) {
return new Vec2f(a.x-b.x, a.y-b.y);
}
public static Vec2f add(Vec2f a, Vec2f b) {
return new Vec2f(a.x+b.x, a.y+b.y);
}
public static Vec2f scale(Vec2f a, float f) {
return new Vec2f(a.x*f, a.y*f);
}
public static Vector3f withNewY(Vec2f in, float y) {
return new Vector3f(in.x, y, in.y);
}
}

View file

@ -38,6 +38,7 @@ item.industrialwires.panel_component.toggle_switch.name=Toggle Switch
item.industrialwires.panel_component.toggle_switch_covered.name=Covered Toggle Switch
item.industrialwires.panel_component.lock.name=Lock Switch
item.industrialwires.panel_component.panel_meter.name=Panel Meter
item.industrialwires.panel_component.7seg.name=7-Segment Display
item.industrialwires.key.key.name=Key
item.industrialwires.key.key_named.name=Key for
item.industrialwires.key.blank_key.name=Blank Key
@ -165,4 +166,5 @@ ie.manual.entry.industrialwires.toggle_switch1=the switch. The color of the cove
ie.manual.entry.industrialwires.variac=A Variac® is a variable autotransformer. The output signal of the transformer increases as the knob is turned to the right. The signal strenght can only be increased by one unit per click.
ie.manual.entry.industrialwires.lock=A lock switch activates a redstone signal when a key is inserted and turned. A newly crafted lock will have a unique key configuration. By placing a blank key and a lock in a crafting table a key for the lock can be created. Multiple locks fitting the same key can be created using component copying (see page 1). Keys can be named in a GUI opened by right-clicking with them.
ie.manual.entry.industrialwires.lock1=Up to <config;I;iwKeysOnRing> can be combined on a key ring. Keys are added to the ring by placing both in a crafting table. Shift-right-click the key ring to cycle through the keys on the ring. The selected key can be removed from the ring by placing the ring in a crafting table. The key ring will work just as the selected key would on lock switches.
ie.manual.entry.industrialwires.panel_meter=A panel meter can be used to show display analog redstone signals with some accuracy. Panel meters are available in two different formats, wide and narrow. The wide format gives a slightly bigger angle between redstone level 0 and 15, but is more typical for Multimeters that for panel meters.
ie.manual.entry.industrialwires.panel_meter=A panel meter can be used to show display analog redstone signals with some accuracy. Panel meters are available in two different formats, wide and narrow. The difference between the formats is purely visual.
ie.manual.entry.industrialwires.7seg=Seven-Segment Displays are a way of displaying analog redstone signals precisely. Signal strengths 0-9 are displayed as on would expect, levels 10-15 are represented by the letters A-E. Some of the letters are lower-case to differentiate them from digits (e.g. 8 vs B).

View file

@ -0,0 +1,7 @@
{
"parent":"item/generated",
"textures": {
"layer0":"industrialwires:items/background_odd",
"layer1":"industrialwires:items/7seg"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B