2017-04-10 16:20:39 +02:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2017-04-13 17:14:05 +02:00
|
|
|
package malte0811.industrialWires.controlpanel;
|
2017-04-01 17:33:58 +02:00
|
|
|
|
2017-04-22 18:14:49 +02:00
|
|
|
import malte0811.industrialWires.IndustrialWires;
|
|
|
|
import malte0811.industrialWires.blocks.controlpanel.TileEntityPanel;
|
2017-04-01 17:33:58 +02:00
|
|
|
import malte0811.industrialWires.client.RawQuad;
|
2017-04-13 17:14:05 +02:00
|
|
|
import malte0811.industrialWires.client.gui.GuiPanelCreator;
|
2017-04-22 18:14:49 +02:00
|
|
|
import net.minecraft.client.resources.I18n;
|
2017-05-08 17:20:04 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2017-04-22 18:14:49 +02:00
|
|
|
import net.minecraft.nbt.NBTBase;
|
|
|
|
import net.minecraft.nbt.NBTTagByte;
|
2017-04-01 17:33:58 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2017-04-22 18:14:49 +02:00
|
|
|
import net.minecraft.nbt.NBTTagInt;
|
2017-04-01 17:33:58 +02:00
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
|
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;
|
|
|
|
|
2017-04-22 18:14:49 +02:00
|
|
|
public class IndicatorLight extends PanelComponent implements IConfigurableComponent {
|
2017-04-02 17:16:42 +02:00
|
|
|
private int rsInputId;
|
2017-04-22 18:14:49 +02:00
|
|
|
private byte rsInputChannel;
|
2017-04-13 17:14:05 +02:00
|
|
|
private int colorA = 0xff00;
|
2017-04-02 17:16:42 +02:00
|
|
|
private byte rsInput;
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
public IndicatorLight() {
|
|
|
|
super("indicator_light");
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-22 18:14:49 +02:00
|
|
|
public IndicatorLight(int rsId, byte rsChannel, int color) {
|
2017-04-01 17:33:58 +02:00
|
|
|
this();
|
|
|
|
colorA = color;
|
|
|
|
rsInputChannel = rsChannel;
|
|
|
|
rsInputId = rsId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-09 16:59:57 +02:00
|
|
|
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
2017-04-13 17:14:05 +02:00
|
|
|
nbt.setInteger(RS_ID, rsInputId);
|
2017-04-22 18:14:49 +02:00
|
|
|
nbt.setByte(RS_CHANNEL, rsInputChannel);
|
2017-04-13 17:14:05 +02:00
|
|
|
nbt.setInteger(COLOR, colorA);
|
2017-04-09 16:59:57 +02:00
|
|
|
if (!toItem) {
|
|
|
|
nbt.setInteger("rsInput", rsInput);
|
|
|
|
}
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void readCustomNBT(NBTTagCompound nbt) {
|
2017-04-13 17:14:05 +02:00
|
|
|
rsInputId = nbt.getInteger(RS_ID);
|
2017-04-22 18:14:49 +02:00
|
|
|
rsInputChannel = nbt.getByte(RS_CHANNEL);
|
2017-04-13 17:14:05 +02:00
|
|
|
colorA = nbt.getInteger(COLOR);
|
2017-04-01 17:33:58 +02:00
|
|
|
rsInput = nbt.getByte("rsInput");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final float size = .0625F;
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@Override
|
|
|
|
public List<RawQuad> getQuads() {
|
|
|
|
float[] color = new float[4];
|
|
|
|
color[3] = 1;
|
2017-05-11 16:39:20 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
color[i] = ((this.colorA >> (8 * (2 - i))) & 255) / 255F * (rsInput + 15F) / 30F;
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
List<RawQuad> ret = new ArrayList<>(1);
|
2017-05-27 17:00:26 +02:00
|
|
|
PanelUtils.addColoredQuad(ret, new Vector3f(), new Vector3f(0, 0, size), new Vector3f(size, 0, size), new Vector3f(size, 0, 0), EnumFacing.UP, color);
|
2017-05-11 16:39:20 +02:00
|
|
|
if (rsInput>0) {
|
|
|
|
ret.get(ret.size()-1).light = 0xff0ff;
|
|
|
|
}
|
2017-04-01 17:33:58 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public PanelComponent copyOf() {
|
|
|
|
IndicatorLight ret = new IndicatorLight(rsInputId, rsInputChannel, colorA);
|
|
|
|
ret.rsInput = rsInput;
|
|
|
|
ret.setX(x);
|
|
|
|
ret.setY(y);
|
|
|
|
ret.panelHeight = panelHeight;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-12 15:55:37 +02:00
|
|
|
@Nonnull
|
2017-04-01 17:33:58 +02:00
|
|
|
@Override
|
|
|
|
public AxisAlignedBB getBlockRelativeAABB() {
|
2017-05-11 16:39:20 +02:00
|
|
|
if (aabb == null) {
|
|
|
|
aabb = new AxisAlignedBB(x, 0, y, x + size, 0, y + size);
|
2017-04-12 15:55:37 +02:00
|
|
|
}
|
|
|
|
return aabb;
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-10 17:56:05 +02:00
|
|
|
public void interactWith(Vec3d hitRelative, TileEntityPanel tile, EntityPlayerMP player) {
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(TileEntityPanel tile) {
|
|
|
|
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-02 17:16:42 +02:00
|
|
|
private TileEntityPanel panel;
|
2017-05-11 16:39:20 +02:00
|
|
|
private Consumer<byte[]> handler = (input) -> {
|
|
|
|
if (input[rsInputChannel] != rsInput) {
|
2017-04-02 17:16:42 +02:00
|
|
|
rsInput = input[rsInputChannel];
|
2017-08-22 18:33:05 +02:00
|
|
|
panel.markDirty();
|
2017-04-02 17:16:42 +02:00
|
|
|
panel.triggerRenderUpdate();
|
|
|
|
}
|
|
|
|
};
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public Consumer<byte[]> getRSInputHandler(int id, TileEntityPanel panel) {
|
2017-07-13 09:22:20 +02:00
|
|
|
if (matchesId(rsInputId, id)) {
|
2017-04-02 17:16:42 +02:00
|
|
|
this.panel = panel;
|
|
|
|
return handler;
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-04-04 17:07:45 +02:00
|
|
|
@Override
|
|
|
|
public float getHeight() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@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;
|
|
|
|
|
|
|
|
IndicatorLight that = (IndicatorLight) o;
|
|
|
|
|
|
|
|
if (colorA != that.colorA) return false;
|
|
|
|
return rsInput == that.rsInput;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
int result = super.hashCode();
|
|
|
|
result = 31 * result + colorA;
|
|
|
|
result = 31 * result + (int) rsInput;
|
|
|
|
return result;
|
|
|
|
}
|
2017-04-13 17:14:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderInGUI(GuiPanelCreator gui) {
|
|
|
|
renderInGUIDefault(gui, colorA);
|
|
|
|
}
|
2017-04-22 18:14:49 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
|
|
|
|
switch (type) {
|
|
|
|
case RS_CHANNEL:
|
2017-05-11 16:39:20 +02:00
|
|
|
rsInputChannel = ((NBTTagByte) value).getByte();
|
2017-04-22 18:14:49 +02:00
|
|
|
break;
|
|
|
|
case INT:
|
2017-05-11 16:39:20 +02:00
|
|
|
rsInputId = ((NBTTagInt) value).getInt();
|
2017-04-22 18:14:49 +02:00
|
|
|
break;
|
|
|
|
case FLOAT:
|
|
|
|
colorA = PanelUtils.setColor(colorA, id, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public String fomatConfigName(ConfigType type, int id) {
|
|
|
|
switch (type) {
|
|
|
|
case FLOAT:
|
2017-05-11 16:39:20 +02:00
|
|
|
return I18n.format(IndustrialWires.MODID + ".desc." + (id == 0 ? "red" : (id == 1 ? "green" : "blue")));
|
2017-04-22 18:14:49 +02:00
|
|
|
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:
|
2017-05-11 16:39:20 +02:00
|
|
|
return I18n.format(IndustrialWires.MODID + ".desc.rschannel_info");
|
2017-04-22 18:14:49 +02:00
|
|
|
case INT:
|
2017-05-11 16:39:20 +02:00
|
|
|
return I18n.format(IndustrialWires.MODID + ".desc.rsid_info");
|
2017-04-22 18:14:49 +02:00
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public RSChannelConfig[] getRSChannelOptions() {
|
2017-05-11 16:39:20 +02:00
|
|
|
return new RSChannelConfig[]{
|
2017-04-22 18:14:49 +02:00
|
|
|
new RSChannelConfig("channel", 0, 0, rsInputChannel)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IntConfig[] getIntegerOptions() {
|
2017-05-11 16:39:20 +02:00
|
|
|
return new IntConfig[]{
|
2017-05-01 18:40:29 +02:00
|
|
|
new IntConfig("rsId", 0, 45, rsInputId, 2, false)
|
2017-04-22 18:14:49 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FloatConfig[] getFloatOptions() {
|
|
|
|
float[] color = PanelUtils.getFloatColor(true, this.colorA);
|
2017-05-01 18:40:29 +02:00
|
|
|
int x = 70;
|
|
|
|
int yOffset = 10;
|
2017-04-22 18:14:49 +02:00
|
|
|
return new FloatConfig[]{
|
2017-05-01 18:40:29 +02:00
|
|
|
new FloatConfig("red", x, yOffset, color[0], 60),
|
2017-05-11 16:39:20 +02:00
|
|
|
new FloatConfig("green", x, yOffset + 20, color[1], 60),
|
|
|
|
new FloatConfig("blue", x, yOffset + 40, color[2], 60)
|
2017-04-22 18:14:49 +02:00
|
|
|
};
|
|
|
|
}
|
2017-04-27 18:15:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getColor() {
|
|
|
|
return colorA;
|
|
|
|
}
|
2017-04-02 17:16:42 +02:00
|
|
|
}
|