2017-04-10 16:20:39 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
2018-02-28 21:06:33 +01:00
|
|
|
* Copyright (C) 2016-2018 malte0811
|
2017-04-10 16:20:39 +02:00
|
|
|
* 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;
|
2018-07-30 18:41:52 +02:00
|
|
|
import malte0811.industrialWires.controlpanel.ControlPanelNetwork.RSChannel;
|
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;
|
2017-04-01 17:33:58 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
2017-10-31 16:29:38 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2017-04-01 17:33:58 +02:00
|
|
|
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-10-04 17:05:04 +02:00
|
|
|
import static malte0811.industrialWires.util.NBTKeys.*;
|
|
|
|
|
2017-04-22 18:14:49 +02:00
|
|
|
public class IndicatorLight extends PanelComponent implements IConfigurableComponent {
|
2018-07-30 18:41:52 +02:00
|
|
|
@Nonnull
|
|
|
|
private RSChannel inputChannel = RSChannel.INVALID_CHANNEL;
|
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
|
|
|
|
2018-07-30 18:41:52 +02:00
|
|
|
public IndicatorLight(@Nonnull RSChannel input, int color) {
|
2017-04-01 17:33:58 +02:00
|
|
|
this();
|
|
|
|
colorA = color;
|
2018-07-30 18:41:52 +02:00
|
|
|
inputChannel = input;
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-04-09 16:59:57 +02:00
|
|
|
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
2018-07-30 18:41:52 +02:00
|
|
|
nbt.setInteger(RS_ID, inputChannel.getController());
|
|
|
|
nbt.setByte(RS_CHANNEL, inputChannel.getColor());
|
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) {
|
2018-07-30 18:41:52 +02:00
|
|
|
int rsController = nbt.getInteger(RS_ID);
|
|
|
|
byte rsColor = nbt.getByte(RS_CHANNEL);
|
|
|
|
inputChannel = new RSChannel(rsController, rsColor);
|
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
|
2017-10-31 16:29:38 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-01 17:33:58 +02:00
|
|
|
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() {
|
2018-07-30 18:41:52 +02:00
|
|
|
IndicatorLight ret = new IndicatorLight(inputChannel, colorA);
|
2017-04-01 17:33:58 +02:00
|
|
|
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
|
2018-07-30 18:41:52 +02:00
|
|
|
public void interactWith(Vec3d hitRelative, EntityPlayerMP player) {
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 18:41:52 +02:00
|
|
|
public void update() {
|
2017-04-01 17:33:58 +02:00
|
|
|
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2018-07-30 18:41:52 +02:00
|
|
|
private Consumer<ControlPanelNetwork.RSChannelState> handler = (state) -> {
|
|
|
|
if (state.getStrength() != rsInput) {
|
|
|
|
rsInput = state.getStrength();
|
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
|
|
|
|
2018-07-30 18:41:52 +02:00
|
|
|
|
2017-04-01 17:33:58 +02:00
|
|
|
@Override
|
2018-07-30 18:41:52 +02:00
|
|
|
public void setNetwork(ControlPanelNetwork net, TileEntityPanel panel) {
|
|
|
|
super.setNetwork(net, panel);
|
|
|
|
net.addListener(this, handler, inputChannel);
|
2017-04-01 17:33:58 +02:00
|
|
|
}
|
|
|
|
|
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
|
2017-10-31 16:29:38 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-13 17:14:05 +02:00
|
|
|
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) {
|
2018-07-30 18:41:52 +02:00
|
|
|
case RS_CHANNEL:
|
|
|
|
if (id == 0) {
|
|
|
|
inputChannel = inputChannel.withColor(value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INT:
|
|
|
|
if (id == 0) {
|
|
|
|
inputChannel = inputChannel.withController(value);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-22 18:14:49 +02:00
|
|
|
case FLOAT:
|
|
|
|
colorA = PanelUtils.setColor(colorA, id, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
2018-07-30 18:41:52 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-22 18:14:49 +02:00
|
|
|
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
|
2018-07-30 18:41:52 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2017-04-22 18:14:49 +02:00
|
|
|
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
|
2018-07-30 18:41:52 +02:00
|
|
|
public RSColorConfig[] getRSChannelOptions() {
|
|
|
|
return new RSColorConfig[]{
|
|
|
|
new RSColorConfig("channel", 0, 0, inputChannel.getColor())
|
2017-04-22 18:14:49 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IntConfig[] getIntegerOptions() {
|
2017-05-11 16:39:20 +02:00
|
|
|
return new IntConfig[]{
|
2018-07-30 18:41:52 +02:00
|
|
|
new IntConfig("rsId", 0, 45, inputChannel.getController(), 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
|
|
|
}
|