Added a variable transformer/Variac to put on control panels
This commit is contained in:
parent
4586e57b84
commit
bf66a0fdc7
|
@ -128,7 +128,7 @@ public class TileEntityPanelCreator extends TileEntityIWBase implements IIEInven
|
|||
}
|
||||
break;
|
||||
case CREATE_PANEL:
|
||||
if (PanelUtils.getPanelBase().equals(inv[0])) {
|
||||
if (ItemStack.areItemStacksEqual(PanelUtils.getPanelBase(), inv[0])) {
|
||||
NBTTagCompound panelNBT = new NBTTagCompound();
|
||||
writeToItemNBT(panelNBT, true);
|
||||
ItemStack panel = new ItemStack(IndustrialWires.panel, 1, BlockTypes_Panel.TOP.ordinal());
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package malte0811.industrialWires.client;
|
||||
|
||||
import blusunrize.immersiveengineering.common.util.chickenbones.Matrix4;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
@ -49,4 +50,10 @@ public class RawQuad {
|
|||
this.normal = normal;
|
||||
this.uvs = uvs;
|
||||
}
|
||||
public RawQuad apply(Matrix4 mat) {
|
||||
Matrix4 matNormal = mat.copy().transpose();
|
||||
matNormal.invert();
|
||||
return new RawQuad(mat.apply(vertices[0]), mat.apply(vertices[1]), mat.apply(vertices[2]), mat.apply(vertices[3]),
|
||||
facing, tex, colorA, matNormal.apply(normal), uvs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import blusunrize.immersiveengineering.client.gui.elements.GuiSliderIE;
|
|||
import com.google.common.collect.ImmutableList;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.client.gui.elements.GuiChannelPicker;
|
||||
import malte0811.industrialWires.client.gui.elements.GuiChannelPickerSmall;
|
||||
import malte0811.industrialWires.client.gui.elements.GuiIntChooser;
|
||||
import malte0811.industrialWires.containers.ContainerPanelComponent;
|
||||
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
|
||||
|
@ -68,7 +69,11 @@ public class GuiPanelComponent extends GuiContainer {
|
|||
IConfigurableComponent.RSChannelConfig[] rs = confComp.getRSChannelOptions();
|
||||
rsChannelChoosers.clear();
|
||||
for (IConfigurableComponent.RSChannelConfig rc : rs) {
|
||||
rsChannelChoosers.add(new GuiChannelPicker(0, componentLeft + rc.x, componentTop + rc.y, 40, rc.value));
|
||||
if (rc.small) {
|
||||
rsChannelChoosers.add(new GuiChannelPickerSmall(0, componentLeft + rc.x, componentTop + rc.y, 10, 40, rc.value));
|
||||
} else {
|
||||
rsChannelChoosers.add(new GuiChannelPicker(0, componentLeft + rc.x, componentTop + rc.y, 40, rc.value));
|
||||
}
|
||||
}
|
||||
intChoosers.clear();
|
||||
IConfigurableComponent.IntConfig[] is = confComp.getIntegerOptions();
|
||||
|
@ -88,7 +93,6 @@ public class GuiPanelComponent extends GuiContainer {
|
|||
private ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/panel_component.png");
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/panel_component.png");
|
||||
GlStateManager.color(1,1,1,1);
|
||||
mc.getTextureManager().bindTexture(textureLoc);
|
||||
Gui.drawModalRectWithCustomSizedTexture(guiLeft, guiTop, 0, 0, xSize, ySize, 150, 150);
|
||||
|
@ -121,6 +125,17 @@ public class GuiPanelComponent extends GuiContainer {
|
|||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
for (int i = 0;i<rsChannelChoosers.size();i++) {
|
||||
GuiChannelPicker picker = rsChannelChoosers.get(i);
|
||||
int old = picker.getSelected();
|
||||
boolean stopNow = picker.click(mouseX, mouseY);
|
||||
if (old != picker.getSelected()) {
|
||||
sync(i, picker.getSelected());
|
||||
}
|
||||
if (stopNow) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (int i = 0;i<stringTexts.size();i++) {
|
||||
GuiTextField field = stringTexts.get(i);
|
||||
boolean focus = field.isFocused();
|
||||
|
@ -129,18 +144,6 @@ public class GuiPanelComponent extends GuiContainer {
|
|||
sync(i, field.getText());
|
||||
}
|
||||
}
|
||||
for (int i = 0;i<rsChannelChoosers.size();i++) {
|
||||
GuiChannelPicker picker = rsChannelChoosers.get(i);
|
||||
int mXRel = mouseX-picker.xPosition;
|
||||
int mYRel = mouseY-picker.yPosition;
|
||||
if (mXRel>=0&&mXRel<picker.width&&mYRel>=0&&mYRel<picker.height) {
|
||||
int old = picker.getSelected();
|
||||
picker.select();
|
||||
if (old != picker.getSelected()) {
|
||||
sync(i, picker.getSelected());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0;i<boolButtons.size();i++) {
|
||||
GuiButtonCheckbox box = boolButtons.get(i);
|
||||
boolean on = box.state;
|
||||
|
@ -204,7 +207,7 @@ public class GuiPanelComponent extends GuiContainer {
|
|||
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()) {
|
||||
if (tooltip!=null&&pick.isHovered(mouseX, mouseY)) {
|
||||
ClientUtils.drawHoveringText(ImmutableList.of(tooltip), mouseX, mouseY, mc.fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import net.minecraft.item.EnumDyeColor;
|
|||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GuiChannelPicker extends GuiButton {
|
||||
private byte selected;
|
||||
private byte currHovered;
|
||||
protected byte selected;
|
||||
protected byte currHovered;
|
||||
public GuiChannelPicker(int id, int x, int y, int size, byte selectedChannel) {
|
||||
super(id, x, y, size, size, "");
|
||||
selected = selectedChannel;
|
||||
|
@ -46,7 +46,15 @@ public class GuiChannelPicker extends GuiButton {
|
|||
}
|
||||
}
|
||||
|
||||
public void select() {
|
||||
public boolean click(int x, int y) {
|
||||
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
|
||||
select();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void select() {
|
||||
if (currHovered>=0) {
|
||||
selected = currHovered;
|
||||
}
|
||||
|
@ -54,7 +62,7 @@ public class GuiChannelPicker extends GuiButton {
|
|||
public byte getSelected() {
|
||||
return selected;
|
||||
}
|
||||
public boolean isHovered() {
|
||||
return currHovered>=0;
|
||||
public boolean isHovered(int x, int y) {
|
||||
return xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* 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.client.gui.elements;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GuiChannelPickerSmall extends GuiChannelPicker {
|
||||
private boolean open = false;
|
||||
private int offSize, onSize;
|
||||
public GuiChannelPickerSmall(int id, int x, int y, int offSize, int onSize, byte selectedChannel) {
|
||||
super(id, x, y, offSize, selectedChannel);
|
||||
selected = selectedChannel;
|
||||
this.onSize = onSize;
|
||||
this.offSize = offSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY) {
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.enableBlend();
|
||||
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) {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
} else {
|
||||
EnumDyeColor color = EnumDyeColor.byMetadata(selected);
|
||||
int colorVal = color.getMapColor().colorValue | 0xff000000;
|
||||
drawRect(xPosition, yPosition, xPosition+width, yPosition+height, colorVal);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean click(int x, int y) {
|
||||
if (!open) {
|
||||
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
|
||||
open = true;
|
||||
width = onSize;
|
||||
height = onSize;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
boolean ret = false;
|
||||
if (xPosition<=x&&xPosition+width>=x&&yPosition<=y&&yPosition+height>=y) {
|
||||
select();
|
||||
ret = true;
|
||||
}
|
||||
open = false;
|
||||
width = offSize;
|
||||
height = offSize;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -84,8 +84,13 @@ public interface IConfigurableComponent {
|
|||
}
|
||||
|
||||
class RSChannelConfig extends UniversalConfig<Byte> {
|
||||
public boolean small;
|
||||
public RSChannelConfig(String name, int x, int y, Byte value) {
|
||||
this(name, x, y, value, false);
|
||||
}
|
||||
public RSChannelConfig(String name, int x, int y, Byte value, boolean small) {
|
||||
super(name, x, y, value);
|
||||
this.small = small;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ public abstract class PanelComponent {
|
|||
baseCreaters.put("label", Label::new);
|
||||
baseCreaters.put("indicator_light", IndicatorLight::new);
|
||||
baseCreaters.put("slider", Slider::new);
|
||||
baseCreaters.put("variac", Variac::new);
|
||||
}
|
||||
protected abstract void writeCustomNBT(NBTTagCompound nbt, boolean toItem);
|
||||
protected abstract void readCustomNBT(NBTTagCompound nbt);
|
||||
|
|
|
@ -46,6 +46,7 @@ import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad;
|
|||
import org.lwjgl.util.vector.Vector3f;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -85,22 +86,22 @@ public final class PanelUtils {
|
|||
float vMax = 16 * components.height;
|
||||
addQuad(rawOut, new Vector3f(0, components.height, 0), new Vector3f(0, components.height, 1),
|
||||
new Vector3f(1, components.height, 1), new Vector3f(1, components.height, 0),
|
||||
EnumFacing.UP, WHITE, PANEL_TEXTURE, UV_FULL);
|
||||
EnumFacing.UP, WHITE, PANEL_TEXTURE, UV_FULL, null);
|
||||
addQuad(rawOut, new Vector3f(0, 0, 0), new Vector3f(1, 0, 0),
|
||||
new Vector3f(1, 0, 1), new Vector3f(0, 0, 1),
|
||||
EnumFacing.DOWN, WHITE, PANEL_TEXTURE, new float[]{0, 16, 16, 0});
|
||||
EnumFacing.DOWN, WHITE, PANEL_TEXTURE, new float[]{0, 16, 16, 0}, null);
|
||||
addQuad(rawOut, new Vector3f(0, 0, 0), new Vector3f(0, 0, 1),
|
||||
new Vector3f(0, components.height, 1), new Vector3f(0, components.height, 0),
|
||||
EnumFacing.WEST, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0});
|
||||
EnumFacing.WEST, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0}, null);
|
||||
addQuad(rawOut, new Vector3f(1, 0, 0), new Vector3f(1, components.height, 0),
|
||||
new Vector3f(1, components.height, 1), new Vector3f(1, 0, 1),
|
||||
EnumFacing.EAST, WHITE, PANEL_TEXTURE, new float[]{16, vMax, 0, 0});
|
||||
EnumFacing.EAST, WHITE, PANEL_TEXTURE, new float[]{16, vMax, 0, 0}, null);
|
||||
addQuad(rawOut, new Vector3f(1, 0, 0), new Vector3f(0, 0, 0),
|
||||
new Vector3f(0, components.height, 0), new Vector3f(1, components.height, 0),
|
||||
EnumFacing.NORTH, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0});
|
||||
EnumFacing.NORTH, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0}, null);
|
||||
addQuad(rawOut, new Vector3f(0, 0, 1), new Vector3f(1, 0, 1),
|
||||
new Vector3f(1, components.height, 1), new Vector3f(0, components.height, 1),
|
||||
EnumFacing.SOUTH, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0});
|
||||
EnumFacing.SOUTH, WHITE, PANEL_TEXTURE, new float[]{0, vMax, 16, 0}, null);
|
||||
for (RawQuad bq : rawOut) {
|
||||
ret.add(bakeQuad(bq, baseTrans, baseNorm, bq.facing != EnumFacing.EAST && bq.facing != EnumFacing.UP));//flip south and west
|
||||
}
|
||||
|
@ -158,44 +159,57 @@ public final class PanelUtils {
|
|||
private static final float[] WHITE = {1, 1, 1, 1};
|
||||
|
||||
public static void addTexturedBox(Vector3f min, Vector3f size, List<RawQuad> out, float[] uvs, TextureAtlasSprite tex) {
|
||||
addBox(WHITE, WHITE, WHITE, min, size, out, true, uvs, tex);
|
||||
addBox(WHITE, WHITE, WHITE, min, size, out, true, uvs, tex, null);
|
||||
}
|
||||
|
||||
public static void addColoredBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom) {
|
||||
addBox(colorTop, colorSides, colorBottom, min, size, out, doBottom, UV_FULL, ModelLoader.White.INSTANCE);
|
||||
addBox(colorTop, colorSides, colorBottom, min, size, out, doBottom, UV_FULL, ModelLoader.White.INSTANCE, null);
|
||||
}
|
||||
|
||||
public static void addBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom, float[] uvs, TextureAtlasSprite tex) {
|
||||
public static void addColoredBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom, @Nullable Matrix4 mat) {
|
||||
addBox(colorTop, colorSides, colorBottom, min, size, out, doBottom, UV_FULL, ModelLoader.White.INSTANCE, mat);
|
||||
}
|
||||
|
||||
public static void addBox(float[] colorTop, float[] colorSides, float[] colorBottom, Vector3f min, Vector3f size, List<RawQuad> out, boolean doBottom, float[] uvs, TextureAtlasSprite tex,
|
||||
@Nullable Matrix4 mat) {
|
||||
addQuad(out, new Vector3f(min.x, min.y + size.y, min.z), new Vector3f(min.x, min.y + size.y, min.z + size.z),
|
||||
new Vector3f(min.x + size.x, min.y + size.y, min.z + size.z), new Vector3f(min.x + size.x, min.y + size.y, min.z),
|
||||
EnumFacing.UP, colorTop, tex, uvs);
|
||||
EnumFacing.UP, colorTop, tex, uvs, mat);
|
||||
if (doBottom) {
|
||||
addQuad(out, new Vector3f(min.x, min.y, min.z), new Vector3f(min.x + size.x, min.y, min.z),
|
||||
new Vector3f(min.x + size.x, min.y, min.z + size.z), new Vector3f(min.x, min.y, min.z + size.z),
|
||||
EnumFacing.UP, colorBottom, tex, uvs);
|
||||
EnumFacing.UP, colorBottom, tex, uvs, mat);
|
||||
}
|
||||
addQuad(out, new Vector3f(min.x, min.y, min.z), new Vector3f(min.x, min.y, min.z + size.z),
|
||||
new Vector3f(min.x, min.y + size.y, min.z + size.z), new Vector3f(min.x, min.y + size.y, min.z),
|
||||
EnumFacing.WEST, colorSides, tex, uvs);
|
||||
EnumFacing.WEST, colorSides, tex, uvs, mat);
|
||||
addQuad(out, new Vector3f(min.x + size.x, min.y, min.z), new Vector3f(min.x + size.x, min.y + size.y, min.z),
|
||||
new Vector3f(min.x + size.x, min.y + size.y, min.z + size.z), new Vector3f(min.x + size.x, min.y, min.z + size.z),
|
||||
EnumFacing.EAST, colorSides, tex, uvs);
|
||||
EnumFacing.EAST, colorSides, tex, uvs, mat);
|
||||
addQuad(out, new Vector3f(min.x, min.y, min.z), new Vector3f(min.x, min.y + size.y, min.z),
|
||||
new Vector3f(min.x + size.x, min.y + size.y, min.z), new Vector3f(min.x + size.x, min.y, min.z),
|
||||
EnumFacing.NORTH, colorSides, tex, uvs);
|
||||
EnumFacing.NORTH, colorSides, tex, uvs, mat);
|
||||
addQuad(out, new Vector3f(min.x, min.y, min.z + size.z), new Vector3f(min.x + size.x, min.y, min.z + size.z),
|
||||
new Vector3f(min.x + size.x, min.y + size.y, min.z + size.z), new Vector3f(min.x, min.y + size.y, min.z + size.z),
|
||||
EnumFacing.SOUTH, colorSides, tex, uvs);
|
||||
EnumFacing.SOUTH, colorSides, tex, uvs, mat);
|
||||
}
|
||||
|
||||
public static void addColoredQuad(List<RawQuad> out, Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3, EnumFacing dir, float[] color) {
|
||||
addQuad(out, v0, v1, v2, v3, dir, color, Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(ModelLoader.White.LOCATION.toString()), UV_FULL);
|
||||
addQuad(out, v0, v1, v2, v3, dir, color, Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(ModelLoader.White.LOCATION.toString()), UV_FULL, null);
|
||||
}
|
||||
|
||||
public static void addQuad(List<RawQuad> out, Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3, EnumFacing dir, float[] color, TextureAtlasSprite tex, float[] uvs) {
|
||||
public static void addColoredQuad(List<RawQuad> out, Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3, EnumFacing dir, float[] color, @Nullable Matrix4 mat) {
|
||||
addQuad(out, v0, v1, v2, v3, dir, color, Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry(ModelLoader.White.LOCATION.toString()), UV_FULL, mat);
|
||||
}
|
||||
|
||||
public static void addQuad(List<RawQuad> out, Vector3f v0, Vector3f v1, Vector3f v2, Vector3f v3, EnumFacing dir, float[] color, TextureAtlasSprite tex, float[] uvs, @Nullable Matrix4 mat) {
|
||||
Vec3i dirV = dir.getDirectionVec();
|
||||
out.add(new RawQuad(v0, v1, v2, v3, dir, tex,
|
||||
color, new Vector3f(dirV.getX(), dirV.getY(), dirV.getZ()), uvs));
|
||||
RawQuad quad = new RawQuad(v0, v1, v2, v3, dir, tex,
|
||||
color, new Vector3f(dirV.getX(), dirV.getY(), dirV.getZ()), uvs);
|
||||
if (mat!=null) {
|
||||
quad = quad.apply(mat);
|
||||
}
|
||||
out.add(quad);
|
||||
}
|
||||
|
||||
public static void addInfo(ItemStack stack, List<String> list, NBTTagCompound data) {
|
||||
|
@ -224,6 +238,9 @@ public final class PanelUtils {
|
|||
list.add(I18n.format(IndustrialWires.MODID + ".tooltip.length", data.getFloat(LENGTH)));
|
||||
}
|
||||
|
||||
break;
|
||||
case 4://variac
|
||||
addCommonInfo(data, list, false, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
284
src/main/java/malte0811/industrialWires/controlpanel/Variac.java
Normal file
284
src/main/java/malte0811/industrialWires/controlpanel/Variac.java
Normal file
|
@ -0,0 +1,284 @@
|
|||
/*
|
||||
* 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 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 net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
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 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;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public class Variac extends PanelComponent implements IConfigurableComponent {
|
||||
private static final float SIZE = 3 / 16F;
|
||||
private static final float innerSize = (float) (Math.sqrt(2) / 2 * SIZE);
|
||||
private static final float offset = (SIZE - innerSize) / 2;
|
||||
private static final float[] darkGray = {.2F, .2F, .2F, 1};
|
||||
private static final float[] white = {1, 1, 1, 1};
|
||||
private static final float rodDia = .0625F / 2;
|
||||
private static final float rodOffset = (SIZE - rodDia) / 2;
|
||||
private static final float arrowSize = .0625F / 2;
|
||||
|
||||
private byte out;
|
||||
private byte rsChannel;
|
||||
private int rsId;
|
||||
private Set<BiConsumer<Integer, Byte>> outputs = new HashSet<>();
|
||||
|
||||
public Variac(int rsId, byte rsChannel) {
|
||||
this();
|
||||
this.rsChannel = rsChannel;
|
||||
this.rsId = rsId;
|
||||
}
|
||||
|
||||
public Variac() {
|
||||
super("variac");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
if (!toItem) {
|
||||
nbt.setByte("output", out);
|
||||
}
|
||||
nbt.setByte(RS_CHANNEL, rsChannel);
|
||||
nbt.setInteger(RS_ID, rsId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readCustomNBT(NBTTagCompound nbt) {
|
||||
out = nbt.getByte("output");
|
||||
rsChannel = nbt.getByte(RS_CHANNEL);
|
||||
rsId = nbt.getInteger(RS_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RawQuad> getQuads() {
|
||||
List<RawQuad> ret = new ArrayList<>();
|
||||
float angle = -(float) (2 * Math.PI * (.5 + out) / 17F);
|
||||
Matrix4 mat = new Matrix4();
|
||||
mat.translate(SIZE / 2, 0, SIZE / 2);
|
||||
mat.rotate(angle, 0, 1, 0);
|
||||
mat.translate(-SIZE / 2, 0, -SIZE / 2);
|
||||
PanelUtils.addColoredBox(darkGray, darkGray, null, new Vector3f(offset, getHeight() / 2, offset),
|
||||
new Vector3f(innerSize, getHeight() / 2, innerSize), ret, false, mat);
|
||||
PanelUtils.addColoredBox(GRAY, GRAY, null, new Vector3f(rodOffset, 0, rodOffset),
|
||||
new Vector3f(rodDia, getHeight() / 2, rodDia), ret, false, mat);
|
||||
mat.translate(SIZE / 2, 0, SIZE / 2);
|
||||
mat.rotate(Math.PI / 4, 0, 1, 0);
|
||||
mat.translate(-SIZE / 2, 0, -SIZE / 2);
|
||||
PanelUtils.addColoredBox(darkGray, darkGray, null, new Vector3f(offset, getHeight() / 2, offset),
|
||||
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, 0, -SIZE / 2);
|
||||
PanelUtils.addColoredQuad(ret, new Vector3f(offset, getHeight() + .00001F, offset), new Vector3f(offset, getHeight() + .00001F, offset),
|
||||
new Vector3f(offset + arrowSize / 2, getHeight() + .00001F, offset + arrowSize),
|
||||
new Vector3f(offset + arrowSize, getHeight() + .00001F, offset + arrowSize / 2), EnumFacing.UP, white, mat);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public PanelComponent copyOf() {
|
||||
Variac ret = new Variac(rsId, rsChannel);
|
||||
ret.out = out;
|
||||
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 + SIZE, getHeight(), y + SIZE);
|
||||
}
|
||||
return aabb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean interactWith(Vec3d hitRelative, TileEntityPanel tile) {
|
||||
double xRel = hitRelative.xCoord - SIZE / 2;
|
||||
double yRel = -(hitRelative.zCoord - SIZE / 2);
|
||||
double angle = 1.5 * Math.PI - Math.atan2(yRel, xRel);
|
||||
if (angle < 0) {
|
||||
angle += 2 * Math.PI;
|
||||
} 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 true;
|
||||
}
|
||||
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));
|
||||
if (newLevel != out) {
|
||||
for (BiConsumer<Integer, Byte> output : outputs) {
|
||||
output.accept((int) rsChannel, newLevel);
|
||||
}
|
||||
out = newLevel;
|
||||
tile.markDirty();
|
||||
tile.triggerRenderUpdate();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
|
||||
if (id == rsId) {
|
||||
outputs.add(out);
|
||||
out.accept((int) rsChannel, this.out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
|
||||
if (id == rsId) {
|
||||
outputs.remove(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TileEntityPanel tile) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return .0625F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInGUI(GuiPanelCreator gui) {
|
||||
int left = (int) Math.ceil(gui.getX0() + (offset + aabb.minX) * gui.panelSize);
|
||||
int top = (int) Math.ceil(gui.getY0() + (offset + aabb.minZ) * gui.panelSize);
|
||||
int right = (int) Math.floor(gui.getX0() + (aabb.maxX - offset) * gui.panelSize);
|
||||
int bottom = (int) Math.floor(gui.getY0() + (aabb.maxZ - offset) * gui.panelSize);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate((left + right) / 2, (top + bottom) / 2, 0);
|
||||
GlStateManager.rotate(360 / 17F, 0, 0, 1);
|
||||
GlStateManager.translate(-(left + right) / 2, -(top + bottom) / 2, 0);
|
||||
Gui.drawRect(left, top, right, bottom, 0xff333333);
|
||||
GlStateManager.translate((left + right) / 2, (top + bottom) / 2, 0);
|
||||
GlStateManager.rotate(45, 0, 0, 1);
|
||||
GlStateManager.translate(-(left + right) / 2, -(top + bottom) / 2, 0);
|
||||
Gui.drawRect(left, top, right, bottom, 0xff333333);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(TileEntityPanel te) {
|
||||
for (BiConsumer<Integer, Byte> out : outputs) {
|
||||
out.accept((int) rsChannel, (byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
Variac variac = (Variac) o;
|
||||
|
||||
if (out != variac.out) return false;
|
||||
return rsChannel == variac.rsChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (int) out;
|
||||
result = 31 * result + (int) rsChannel;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyConfigOption(IConfigurableComponent.ConfigType type, int id, NBTBase value) {
|
||||
switch (type) {
|
||||
case RS_CHANNEL:
|
||||
rsChannel = ((NBTTagByte) value).getByte();
|
||||
break;
|
||||
case INT:
|
||||
rsId = ((NBTTagInt) value).getInt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fomatConfigName(IConfigurableComponent.ConfigType type, int id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@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?";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigurableComponent.RSChannelConfig[] getRSChannelOptions() {
|
||||
return new IConfigurableComponent.RSChannelConfig[]{
|
||||
new IConfigurableComponent.RSChannelConfig("channel", 0, 0, rsChannel)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigurableComponent.IntConfig[] getIntegerOptions() {
|
||||
return new IConfigurableComponent.IntConfig[]{
|
||||
new IConfigurableComponent.IntConfig("rsId", 0, 50, rsId, 2, false)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return 0xffffff;
|
||||
}
|
||||
}
|
|
@ -43,7 +43,7 @@ import java.util.List;
|
|||
|
||||
public class ItemPanelComponent extends Item {
|
||||
public static final String[] types = {
|
||||
"lighted_button", "label", "indicator_light", "slider"
|
||||
"lighted_button", "label", "indicator_light", "slider", "variac"
|
||||
};
|
||||
|
||||
public ItemPanelComponent() {
|
||||
|
|
|
@ -32,6 +32,7 @@ item.industrialwires.panel_component.lighted_button.name=Lighted Button
|
|||
item.industrialwires.panel_component.label.name=Label
|
||||
item.industrialwires.panel_component.indicator_light.name=Indicator Light
|
||||
item.industrialwires.panel_component.slider.name=Slider
|
||||
item.industrialwires.panel_component.variac.name=Variac®
|
||||
|
||||
|
||||
industrialwires.desc.wireLength=Wire length: %1s block(s)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"parent":"item/generated",
|
||||
"textures": {
|
||||
"layer0":"industrialwires:items/background",
|
||||
"layer1":"industrialwires:items/button"//TODO change when there is a proper texture for it
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue