Started adding locks for panels
# Conflicts: # src/main/java/malte0811/industrialWires/CommonProxy.java # src/main/java/malte0811/industrialWires/IndustrialWires.java # src/main/java/malte0811/industrialWires/client/ClientProxy.java # src/main/java/malte0811/industrialWires/containers/ContainerPanelComponent.java # src/main/java/malte0811/industrialWires/items/ItemIC2Coil.java # src/main/java/malte0811/industrialWires/items/ItemPanelComponent.java # src/main/java/malte0811/industrialWires/network/MessageComponentSync.java
This commit is contained in:
parent
fe7c44f298
commit
55e03ab8a4
17 changed files with 908 additions and 47 deletions
|
@ -23,6 +23,7 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
|
|||
import malte0811.industrialWires.containers.ContainerPanelComponent;
|
||||
import malte0811.industrialWires.containers.ContainerPanelCreator;
|
||||
import malte0811.industrialWires.containers.ContainerRSPanelConn;
|
||||
import malte0811.industrialWires.containers.ContainerRenameKey;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -60,8 +61,12 @@ public class CommonProxy implements IGuiHandler {
|
|||
} else if (ID == 1) {//ITEM GUI
|
||||
EnumHand h = z == 1 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
|
||||
ItemStack held = player.getHeldItem(h);
|
||||
if (held != null && held.getItem() == IndustrialWires.panelComponent) {
|
||||
return new ContainerPanelComponent(h);
|
||||
if (held!=null) {
|
||||
if (held.getItem() == IndustrialWires.panelComponent) {
|
||||
return new ContainerPanelComponent(h);
|
||||
} else if (held.getItem() == IndustrialWires.key) {
|
||||
return new ContainerRenameKey(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -35,10 +35,12 @@ import malte0811.industrialWires.blocks.converter.TileEntityMechIEtoIC;
|
|||
import malte0811.industrialWires.blocks.wire.*;
|
||||
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||
import malte0811.industrialWires.crafting.RecipeCoilLength;
|
||||
import malte0811.industrialWires.crafting.RecipeKeyLock;
|
||||
import malte0811.industrialWires.items.ItemIC2Coil;
|
||||
import malte0811.industrialWires.items.ItemKey;
|
||||
import malte0811.industrialWires.items.ItemPanelComponent;
|
||||
import malte0811.industrialWires.network.MessageComponentSync;
|
||||
import malte0811.industrialWires.network.MessageGUIInteract;
|
||||
import malte0811.industrialWires.network.MessageItemSync;
|
||||
import malte0811.industrialWires.network.MessagePanelInteract;
|
||||
import malte0811.industrialWires.network.MessageTileSyncIW;
|
||||
import malte0811.industrialWires.wires.IC2Wiretype;
|
||||
|
@ -74,6 +76,7 @@ public class IndustrialWires {
|
|||
public static BlockPanel panel;
|
||||
public static ItemIC2Coil coil;
|
||||
public static ItemPanelComponent panelComponent;
|
||||
public static ItemKey key;
|
||||
public static final SimpleNetworkWrapper packetHandler = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
|
||||
@Mod.Instance(MODID)
|
||||
public static IndustrialWires instance = new IndustrialWires();
|
||||
|
@ -97,8 +100,12 @@ public class IndustrialWires {
|
|||
if (IWConfig.enableConversion)
|
||||
mechConv = new BlockMechanicalConverter();
|
||||
jacobsLadder = new BlockJacobsLadder();
|
||||
panel = new BlockPanel();
|
||||
|
||||
coil = new ItemIC2Coil();
|
||||
panelComponent = new ItemPanelComponent();
|
||||
|
||||
key = new ItemKey();
|
||||
panel = new BlockPanel();
|
||||
GameRegistry.registerTileEntity(TileEntityIC2ConnectorTin.class, "ic2ConnectorTin");
|
||||
GameRegistry.registerTileEntity(TileEntityIC2ConnectorCopper.class, "ic2ConnectorCopper");
|
||||
|
@ -195,13 +202,15 @@ public class IndustrialWires {
|
|||
"stickIron", Blocks.LEVER, "wireCopper"));
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(panelComponent, 1, 6),
|
||||
"aaa", "asa", 'a', "plateAluminum", 's', new ItemStack(panelComponent, 2, 5)));
|
||||
RecipeSorter.register("industrialwires:key_lock", RecipeKeyLock.class, Category.SHAPELESS, "after:forge:shapelessore");
|
||||
GameRegistry.addRecipe(new RecipeKeyLock());
|
||||
|
||||
ExtraIC2Compat.addToolConmpat();
|
||||
|
||||
packetHandler.registerMessage(MessageTileSyncIW.HandlerClient.class, MessageTileSyncIW.class, 0, Side.CLIENT);
|
||||
packetHandler.registerMessage(MessagePanelInteract.HandlerServer.class, MessagePanelInteract.class, 1, Side.SERVER);
|
||||
packetHandler.registerMessage(MessageGUIInteract.HandlerServer.class, MessageGUIInteract.class, 2, Side.SERVER);
|
||||
packetHandler.registerMessage(MessageComponentSync.HandlerServer.class, MessageComponentSync.class, 3, Side.SERVER);
|
||||
packetHandler.registerMessage(MessageItemSync.HandlerServer.class, MessageItemSync.class, 3, Side.SERVER);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import malte0811.industrialWires.blocks.controlpanel.TileEntityRSPanelConn;
|
|||
import malte0811.industrialWires.client.gui.GuiPanelComponent;
|
||||
import malte0811.industrialWires.client.gui.GuiPanelCreator;
|
||||
import malte0811.industrialWires.client.gui.GuiRSPanelConn;
|
||||
import malte0811.industrialWires.client.gui.GuiRenameKey;
|
||||
import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
|
||||
import malte0811.industrialWires.client.render.TileRenderJacobsLadder;
|
||||
import malte0811.industrialWires.controlpanel.PanelComponent;
|
||||
|
@ -284,8 +285,12 @@ public class ClientProxy extends CommonProxy {
|
|||
} else if (ID == 1) {
|
||||
EnumHand h = z == 1 ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
|
||||
ItemStack held = player.getHeldItem(h);
|
||||
if (held != null && held.getItem() == IndustrialWires.panelComponent) {
|
||||
return new GuiPanelComponent(h, ItemPanelComponent.componentFromStack(held));
|
||||
if (held!=null) {
|
||||
if (held.getItem() == IndustrialWires.panelComponent) {
|
||||
return new GuiPanelComponent(h, ItemPanelComponent.componentFromStack(held));
|
||||
} else if (held.getItem() == IndustrialWires.key) {
|
||||
return new GuiRenameKey(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -11,7 +11,8 @@ import malte0811.industrialWires.client.gui.elements.GuiIntChooser;
|
|||
import malte0811.industrialWires.containers.ContainerPanelComponent;
|
||||
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
|
||||
import malte0811.industrialWires.controlpanel.PanelComponent;
|
||||
import malte0811.industrialWires.network.MessageComponentSync;
|
||||
import malte0811.industrialWires.items.ItemPanelComponent;
|
||||
import malte0811.industrialWires.network.MessageItemSync;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
@ -245,41 +246,41 @@ public class GuiPanelComponent extends GuiContainer {
|
|||
|
||||
private void sync(int id, String value) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, id);
|
||||
update.setString(MessageComponentSync.VALUE, value);
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, id);
|
||||
update.setString(ItemPanelComponent.VALUE, value);
|
||||
syncSingle(update);
|
||||
}
|
||||
|
||||
private void sync(int id, boolean value) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, id);
|
||||
update.setBoolean(MessageComponentSync.VALUE, value);
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, id);
|
||||
update.setBoolean(ItemPanelComponent.VALUE, value);
|
||||
syncSingle(update);
|
||||
}
|
||||
|
||||
private void sync(int id, byte value) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, id);
|
||||
update.setByte(MessageComponentSync.VALUE, value);
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, id);
|
||||
update.setByte(ItemPanelComponent.VALUE, value);
|
||||
syncSingle(update);
|
||||
}
|
||||
|
||||
private void sync(int id, int value) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, id);
|
||||
update.setInteger(MessageComponentSync.VALUE, value);
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, id);
|
||||
update.setInteger(ItemPanelComponent.VALUE, value);
|
||||
syncSingle(update);
|
||||
}
|
||||
|
||||
private void sync(int id, float value) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, id);
|
||||
update.setFloat(MessageComponentSync.VALUE, value);
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, id);
|
||||
update.setFloat(ItemPanelComponent.VALUE, value);
|
||||
syncSingle(update);
|
||||
}
|
||||
|
||||
|
@ -287,37 +288,37 @@ public class GuiPanelComponent extends GuiContainer {
|
|||
NBTTagList list = new NBTTagList();
|
||||
for (int i = 0; i < stringTexts.size(); i++) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, i);
|
||||
update.setString(MessageComponentSync.VALUE, stringTexts.get(i).getText());
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.STRING.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, i);
|
||||
update.setString(ItemPanelComponent.VALUE, stringTexts.get(i).getText());
|
||||
list.appendTag(update);
|
||||
}
|
||||
for (int i = 0; i < boolButtons.size(); i++) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, i);
|
||||
update.setBoolean(MessageComponentSync.VALUE, boolButtons.get(i).state);
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.BOOL.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, i);
|
||||
update.setBoolean(ItemPanelComponent.VALUE, boolButtons.get(i).state);
|
||||
list.appendTag(update);
|
||||
}
|
||||
for (int i = 0; i < rsChannelChoosers.size(); i++) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, i);
|
||||
update.setByte(MessageComponentSync.VALUE, rsChannelChoosers.get(i).getSelected());
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.RS_CHANNEL.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, i);
|
||||
update.setByte(ItemPanelComponent.VALUE, rsChannelChoosers.get(i).getSelected());
|
||||
list.appendTag(update);
|
||||
}
|
||||
for (int i = 0; i < intChoosers.size(); i++) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, i);
|
||||
update.setInteger(MessageComponentSync.VALUE, intChoosers.get(i).getValue());
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.INT.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, i);
|
||||
update.setInteger(ItemPanelComponent.VALUE, intChoosers.get(i).getValue());
|
||||
list.appendTag(update);
|
||||
}
|
||||
for (int i = 0; i < floatSliders.size(); i++) {
|
||||
NBTTagCompound update = new NBTTagCompound();
|
||||
update.setInteger(MessageComponentSync.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
|
||||
update.setInteger(MessageComponentSync.ID, i);
|
||||
update.setFloat(MessageComponentSync.VALUE, (float) floatSliders.get(i).getValue());
|
||||
update.setInteger(ItemPanelComponent.TYPE, IConfigurableComponent.ConfigType.FLOAT.ordinal());
|
||||
update.setInteger(ItemPanelComponent.ID, i);
|
||||
update.setFloat(ItemPanelComponent.VALUE, (float) floatSliders.get(i).getValue());
|
||||
list.appendTag(update);
|
||||
}
|
||||
sync(list);
|
||||
|
@ -332,6 +333,6 @@ public class GuiPanelComponent extends GuiContainer {
|
|||
private void sync(NBTTagList list) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setTag("data", list);
|
||||
IndustrialWires.packetHandler.sendToServer(new MessageComponentSync(container.hand, nbt));
|
||||
IndustrialWires.packetHandler.sendToServer(new MessageItemSync(container.hand, nbt));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.containers.ContainerRenameKey;
|
||||
import malte0811.industrialWires.network.MessageItemSync;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiRenameKey extends GuiContainer {
|
||||
private EnumHand hand;
|
||||
private GuiTextField field;
|
||||
|
||||
public GuiRenameKey(EnumHand h) {
|
||||
super(new ContainerRenameKey(h));
|
||||
hand = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
field = new GuiTextField(0, mc.fontRenderer, (width-58)/2, (height-12)/2, 58, 12);
|
||||
ItemStack held = mc.player.getHeldItem(hand);
|
||||
NBTTagCompound nbt = held.getTagCompound();
|
||||
if (nbt!=null&&nbt.hasKey("name")) {
|
||||
field.setText(nbt.getString("name"));
|
||||
}
|
||||
xSize = 64;
|
||||
ySize = 64;
|
||||
guiLeft = (width - xSize) / 2;
|
||||
guiTop = (height - ySize) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
field.drawTextBox();
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
}
|
||||
|
||||
private ResourceLocation textureLoc = new ResourceLocation(IndustrialWires.MODID, "textures/gui/rs_wire_controller.png");
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
|
||||
GlStateManager.color(1, 1, 1, 1);
|
||||
mc.getTextureManager().bindTexture(textureLoc);
|
||||
Gui.drawModalRectWithCustomSizedTexture(guiLeft, guiTop, 0, 0, xSize, ySize, 64, 64);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
field.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if (!field.textboxKeyTyped(typedChar, keyCode)) {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
super.onGuiClosed();
|
||||
if (!field.getText().isEmpty()) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setString("name", field.getText());
|
||||
IndustrialWires.packetHandler.sendToServer(new MessageItemSync(hand, nbt));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.containers;
|
||||
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ContainerRenameKey extends Container {
|
||||
private final EnumHand hand;
|
||||
|
||||
public ContainerRenameKey(EnumHand h) {
|
||||
hand = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(@Nonnull EntityPlayer playerIn) {
|
||||
return playerIn.getHeldItem(hand).getItem()== IndustrialWires.key;
|
||||
}
|
||||
}
|
|
@ -64,8 +64,8 @@ public class LightedButton extends PanelComponent implements IConfigurableCompon
|
|||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
nbt.setInteger(COLOR, color);
|
||||
nbt.setInteger("timeout", ticksTillOff);
|
||||
if (!toItem) {
|
||||
nbt.setInteger("timeout", ticksTillOff);
|
||||
nbt.setBoolean("active", active);
|
||||
}
|
||||
nbt.setBoolean(LATCHING, latching);
|
||||
|
|
355
src/main/java/malte0811/industrialWires/controlpanel/Lock.java
Normal file
355
src/main/java/malte0811/industrialWires/controlpanel/Lock.java
Normal file
|
@ -0,0 +1,355 @@
|
|||
/*
|
||||
* 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 malte0811.industrialWires.items.ItemKey;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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.EnumHand;
|
||||
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.*;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
//TODO drop key when broken
|
||||
public class Lock extends PanelComponent implements IConfigurableComponent {
|
||||
private final static Random rand = new Random();
|
||||
@Nullable
|
||||
private NBTTagCompound keyNBT;
|
||||
private boolean turned;
|
||||
private boolean latching = false;
|
||||
private int rsOutputId;
|
||||
private int rsOutputChannel;
|
||||
private int ticksTillOff;
|
||||
private int lockID;
|
||||
private Set<BiConsumer<Integer, Byte>> rsOut = new HashSet<>();
|
||||
|
||||
public Lock() {
|
||||
super("lock");
|
||||
}
|
||||
|
||||
public Lock(boolean latching, int rsOutputId, int rsOutputChannel) {
|
||||
this();
|
||||
this.latching = latching;
|
||||
this.rsOutputChannel = rsOutputChannel;
|
||||
this.rsOutputId = rsOutputId;
|
||||
while (lockID==0) {
|
||||
lockID = rand.nextInt();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeCustomNBT(NBTTagCompound nbt, boolean toItem) {
|
||||
if (!toItem) {
|
||||
nbt.setInteger("timeout", ticksTillOff);
|
||||
nbt.setBoolean("turned", turned);
|
||||
if (keyNBT != null) {
|
||||
nbt.setTag("key", keyNBT);
|
||||
}
|
||||
}
|
||||
nbt.setInteger("lockId", lockID);
|
||||
nbt.setBoolean(LATCHING, latching);
|
||||
nbt.setInteger(RS_CHANNEL, rsOutputChannel);
|
||||
nbt.setInteger(RS_ID, rsOutputId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readCustomNBT(NBTTagCompound nbt) {
|
||||
ticksTillOff = nbt.getInteger("timeout");
|
||||
if (nbt.hasKey("key", 10)) {
|
||||
keyNBT = nbt.getCompoundTag("key");
|
||||
} else {
|
||||
keyNBT = null;
|
||||
}
|
||||
turned = nbt.getBoolean("turned");
|
||||
if (nbt.hasKey("lockId")) {
|
||||
lockID = nbt.getInteger("lockId");
|
||||
}
|
||||
latching = nbt.getBoolean(LATCHING);
|
||||
rsOutputChannel = nbt.getInteger(RS_CHANNEL);
|
||||
rsOutputId = nbt.getInteger(RS_ID);
|
||||
}
|
||||
|
||||
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 xOffset = (size - keyWidth) / 2;
|
||||
private final static float[] DARK_GRAY = {.4F, .4F, .4F};
|
||||
private final static float zOffset = keyWidth / 2;
|
||||
private final static float keyOffset = keyWidth;
|
||||
private final static float zOffsetLowerKey = size / 3;
|
||||
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (keyNBT != null) {
|
||||
Matrix4 mat = null;
|
||||
if (turned) {
|
||||
mat = new Matrix4();
|
||||
mat.translate(size / 2, 0, size / 2);
|
||||
mat.rotate(Math.PI / 2, 0, 1, 0);
|
||||
mat.translate(-size / 2, 0, -size / 2);
|
||||
}
|
||||
addKey(ret, mat);
|
||||
} else {
|
||||
PanelUtils.addColoredQuad(ret, new Vector3f(xOffset + keyWidth, yOffset, zOffset), new Vector3f(xOffset, yOffset, zOffset),
|
||||
new Vector3f(xOffset, yOffset, size - zOffset), new Vector3f(xOffset + keyWidth, yOffset, size - zOffset),
|
||||
EnumFacing.UP, DARK_GRAY);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void addKey(List<RawQuad> out, Matrix4 mat) {
|
||||
PanelUtils.addColoredBox(DARK_GRAY, DARK_GRAY, null, new Vector3f(xOffset, size / 2, zOffsetLowerKey), new Vector3f(keyWidth, keyOffset, size / 3), out, false, mat);
|
||||
PanelUtils.addColoredBox(DARK_GRAY, DARK_GRAY, null, new Vector3f(xOffset, size / 2 + keyOffset, zOffset), new Vector3f(keyWidth, size, size - 2 * zOffset), out, false, mat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public PanelComponent copyOf() {
|
||||
Lock ret = new Lock(latching, rsOutputId, rsOutputChannel);
|
||||
ret.turned = turned;
|
||||
ret.keyNBT = keyNBT == null ? null : keyNBT.copy();
|
||||
ret.ticksTillOff = ticksTillOff;
|
||||
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 void interactWith(Vec3d hitRel, TileEntityPanel tile, EntityPlayerMP player) {
|
||||
boolean update = false;
|
||||
if (keyNBT == null) {
|
||||
for (EnumHand hand : EnumHand.values()) {
|
||||
ItemStack held = player.getHeldItem(hand);
|
||||
if (held.getItem() == IndustrialWires.key && ItemKey.idForKey(held) == lockID) {
|
||||
keyNBT = held.serializeNBT();
|
||||
player.setHeldItem(hand, ItemStack.EMPTY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (!turned) {
|
||||
if (player.isSneaking() && player.getHeldItemMainhand().isEmpty()) {
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(keyNBT));
|
||||
keyNBT = null;
|
||||
} else {
|
||||
turned = true;
|
||||
}
|
||||
update = true;
|
||||
} else {
|
||||
if (latching) {
|
||||
turned = false;
|
||||
update = true;
|
||||
} else {
|
||||
ticksTillOff = 10;
|
||||
}
|
||||
}
|
||||
if (update) {
|
||||
setOut(tile);
|
||||
if (!latching && turned) {
|
||||
ticksTillOff = 10;
|
||||
}
|
||||
}
|
||||
tile.markDirty();
|
||||
tile.triggerRenderUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(TileEntityPanel tile) {
|
||||
if (!latching && ticksTillOff > 0) {
|
||||
ticksTillOff--;
|
||||
tile.markDirty();
|
||||
if (ticksTillOff == 0) {
|
||||
turned = false;
|
||||
tile.markDirty();
|
||||
tile.triggerRenderUpdate();
|
||||
setOut(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
|
||||
if (id == rsOutputId) {
|
||||
rsOut.add(out);
|
||||
out.accept(rsOutputChannel, (byte) (turned ? 15 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterRSOutput(int id, @Nonnull BiConsumer<Integer, Byte> out) {
|
||||
if (id == rsOutputId) {
|
||||
rsOut.remove(out);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
return size / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderInGUI(GuiPanelCreator gui) {
|
||||
//TODO somethin more fancy?
|
||||
renderInGUIDefault(gui, GRAY_INT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(TileEntityPanel te) {
|
||||
setOut(te);
|
||||
}
|
||||
|
||||
private void setOut(TileEntityPanel tile) {
|
||||
tile.markDirty();
|
||||
tile.triggerRenderUpdate();
|
||||
for (BiConsumer<Integer, Byte> rs : rsOut) {
|
||||
rs.accept(rsOutputChannel, (byte) (turned ? 15 : 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;
|
||||
|
||||
Lock lock = (Lock) o;
|
||||
|
||||
if (turned != lock.turned) return false;
|
||||
if (latching != lock.latching) return false;
|
||||
if (rsOutputId != lock.rsOutputId) return false;
|
||||
if (rsOutputChannel != lock.rsOutputChannel) return false;
|
||||
if (ticksTillOff != lock.ticksTillOff) return false;
|
||||
if (lockID != lock.lockID) return false;
|
||||
if (true) return false;
|
||||
return keyNBT != null ? keyNBT.equals(lock.keyNBT) : lock.keyNBT == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (keyNBT != null ? keyNBT.hashCode() : 0);
|
||||
result = 31 * result + (turned ? 1 : 0);
|
||||
result = 31 * result + (latching ? 1 : 0);
|
||||
result = 31 * result + rsOutputId;
|
||||
result = 31 * result + rsOutputChannel;
|
||||
result = 31 * result + ticksTillOff;
|
||||
result = 31 * result + lockID;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyConfigOption(ConfigType type, int id, NBTBase value) {
|
||||
switch (type) {
|
||||
case BOOL:
|
||||
if (id == 0) {
|
||||
latching = ((NBTTagByte) value).getByte() != 0;
|
||||
}
|
||||
break;
|
||||
case RS_CHANNEL:
|
||||
if (id == 0) {
|
||||
rsOutputChannel = ((NBTTagByte) value).getByte();
|
||||
}
|
||||
break;
|
||||
case INT:
|
||||
if (id == 0) {
|
||||
rsOutputId = ((NBTTagInt) value).getInt();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fomatConfigName(ConfigType type, int id) {
|
||||
switch (type) {
|
||||
case BOOL:
|
||||
return I18n.format(IndustrialWires.MODID + ".desc.latching");
|
||||
case RS_CHANNEL:
|
||||
case INT:
|
||||
return null;
|
||||
default:
|
||||
return "INVALID";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String fomatConfigDescription(ConfigType type, int id) {
|
||||
switch (type) {
|
||||
case BOOL:
|
||||
return I18n.format(IndustrialWires.MODID + ".desc.latching_info");
|
||||
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 RSChannelConfig[] getRSChannelOptions() {
|
||||
return new RSChannelConfig[]{new RSChannelConfig("channel", 0, 0, (byte) rsOutputChannel)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntConfig[] getIntegerOptions() {
|
||||
return new IntConfig[]{new IntConfig("rsId", 0, 50, rsOutputId, 2, false)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoolConfig[] getBooleanOptions() {
|
||||
return new BoolConfig[]{new BoolConfig("latching", 0, 70, latching)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return GRAY_INT;
|
||||
}
|
||||
|
||||
public int getLockID() {
|
||||
return lockID;
|
||||
}
|
||||
}
|
|
@ -69,6 +69,7 @@ public abstract class PanelComponent {
|
|||
baseCreaters.put("variac", Variac::new);
|
||||
baseCreaters.put("toggle_switch", ToggleSwitch::new);
|
||||
baseCreaters.put("toggle_switch_covered", CoveredToggleSwitch::new);
|
||||
baseCreaters.put("lock", Lock::new);
|
||||
}
|
||||
|
||||
protected abstract void writeCustomNBT(NBTTagCompound nbt, boolean toItem);
|
||||
|
|
|
@ -51,7 +51,7 @@ public class RecipeCoilLength implements IRecipe {
|
|||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* 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.crafting;
|
||||
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.controlpanel.Lock;
|
||||
import malte0811.industrialWires.controlpanel.PanelComponent;
|
||||
import malte0811.industrialWires.items.ItemKey;
|
||||
import malte0811.industrialWires.items.ItemPanelComponent;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
//TODO JEI
|
||||
public class RecipeKeyLock implements IRecipe {
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
|
||||
return getLockId(inv) != 0;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
|
||||
ItemStack ret = getKey(inv).copy();
|
||||
ItemKey.setId(ret, getLockId(inv));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRecipeSize() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack getRecipeOutput() {
|
||||
return new ItemStack(IndustrialWires.key);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) {
|
||||
NonNullList<ItemStack> ret = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
|
||||
for (int i = 0; i < ret.size(); i++) {
|
||||
ItemStack here = inv.getStackInSlot(i);
|
||||
if (here.getItem() == IndustrialWires.panelComponent) {
|
||||
ret.set(i, here);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private int getLockId(@Nonnull InventoryCrafting inv) {
|
||||
int id = 0;
|
||||
boolean hasKey = false;
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack here = inv.getStackInSlot(i);
|
||||
if (here.getItem() == IndustrialWires.key) {
|
||||
if (hasKey || ItemKey.idForKey(here) != 0) {//too many keys or non-blanks
|
||||
return 0;
|
||||
}
|
||||
hasKey = true;
|
||||
} else if (here.getItem() == IndustrialWires.panelComponent) {
|
||||
if (id != 0) {//too many locks/components
|
||||
return 0;
|
||||
}
|
||||
PanelComponent pc = ItemPanelComponent.componentFromStack(here);
|
||||
if (pc instanceof Lock) {
|
||||
id = ((Lock) pc).getLockID();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasKey) {
|
||||
return 0;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
//assumes that the recipe is valid
|
||||
private ItemStack getKey(@Nonnull InventoryCrafting inv) {
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
ItemStack here = inv.getStackInSlot(i);
|
||||
if (here.getItem() == IndustrialWires.key) {
|
||||
return here;
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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.items;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
||||
public interface INetGUIItem {
|
||||
void onChange(NBTTagCompound nbt, EntityPlayer p, EnumHand hand);
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
package malte0811.industrialWires.items;
|
||||
|
||||
import blusunrize.immersiveengineering.ImmersiveEngineering;
|
||||
import blusunrize.immersiveengineering.api.Lib;
|
||||
import blusunrize.immersiveengineering.api.TargetingInfo;
|
||||
import blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable;
|
||||
|
@ -41,13 +40,12 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.HashSet;
|
||||
|
@ -63,7 +61,8 @@ public class ItemIC2Coil extends Item implements IWireCoil {
|
|||
setHasSubtypes(true);
|
||||
this.setCreativeTab(IndustrialWires.creativeTab);
|
||||
setMaxStackSize(64);
|
||||
ImmersiveEngineering.registerByFullName(this, IndustrialWires.MODID + ":" + "ic2WireCoil");
|
||||
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "ic2WireCoil"));
|
||||
GameRegistry.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
103
src/main/java/malte0811/industrialWires/items/ItemKey.java
Normal file
103
src/main/java/malte0811/industrialWires/items/ItemKey.java
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* 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.items;
|
||||
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagInt;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class ItemKey extends Item implements INetGUIItem {
|
||||
private static final String lockId = "lockId";
|
||||
|
||||
public ItemKey() {
|
||||
setUnlocalizedName(IndustrialWires.MODID + ".key");
|
||||
setHasSubtypes(true);
|
||||
this.setCreativeTab(IndustrialWires.creativeTab);
|
||||
setMaxStackSize(64);
|
||||
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "key"));
|
||||
GameRegistry.register(this);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getItemStackDisplayName(@Nonnull ItemStack stack) {
|
||||
NBTTagCompound nbt = stack.getTagCompound();
|
||||
if (nbt!=null&&nbt.hasKey("name")) {
|
||||
return I18n.format("item."+IndustrialWires.MODID+".key_named.name")+nbt.getString("name");
|
||||
}
|
||||
return super.getItemStackDisplayName(stack);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getUnlocalizedName(ItemStack stack) {
|
||||
NBTTagCompound nbt = stack.getTagCompound();
|
||||
if (nbt==null||!nbt.hasKey(lockId)) {
|
||||
return I18n.format("item."+IndustrialWires.MODID+".key_raw.name");
|
||||
}
|
||||
return super.getUnlocalizedName(stack);
|
||||
}
|
||||
|
||||
public static void setId(ItemStack stack, int lockID) {
|
||||
stack.setTagInfo(lockId, new NBTTagInt(lockID));
|
||||
}
|
||||
|
||||
public static int idForKey(@Nonnull ItemStack held) {
|
||||
if (held.getItem()!=IndustrialWires.key) {
|
||||
return 0;
|
||||
}
|
||||
NBTTagCompound nbt = held.getTagCompound();
|
||||
if (nbt!=null) {
|
||||
return nbt.getInteger(lockId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemStackLimit(ItemStack stack) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
|
||||
if (!worldIn.isRemote) {
|
||||
playerIn.openGui(IndustrialWires.MODID, 1, worldIn, 0, 0, hand == EnumHand.MAIN_HAND ? 1 : 0);
|
||||
}
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(NBTTagCompound nbt, EntityPlayer p, EnumHand hand) {
|
||||
ItemStack held = p.getHeldItem(hand);
|
||||
held.setTagInfo("name", nbt.getTag("name"));
|
||||
}
|
||||
}
|
|
@ -18,8 +18,10 @@
|
|||
|
||||
package malte0811.industrialWires.items;
|
||||
|
||||
import blusunrize.immersiveengineering.api.ApiUtils;
|
||||
import blusunrize.immersiveengineering.client.ClientProxy;
|
||||
import malte0811.industrialWires.IndustrialWires;
|
||||
import malte0811.industrialWires.controlpanel.IConfigurableComponent;
|
||||
import malte0811.industrialWires.controlpanel.PanelComponent;
|
||||
import malte0811.industrialWires.controlpanel.PanelUtils;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
@ -30,6 +32,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
|
@ -43,10 +46,13 @@ import javax.annotation.Nonnull;
|
|||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemPanelComponent extends Item {
|
||||
public class ItemPanelComponent extends Item implements INetGUIItem {
|
||||
public static final String[] types = {
|
||||
"lighted_button", "label", "indicator_light", "slider", "variac", "toggle_switch", "toggle_switch_covered"
|
||||
"lighted_button", "label", "indicator_light", "slider", "variac", "toggle_switch", "toggle_switch_covered", "lock"
|
||||
};
|
||||
public static final String TYPE = "type";
|
||||
public static final String ID = "cfgId";
|
||||
public static final String VALUE = "value";
|
||||
|
||||
public ItemPanelComponent() {
|
||||
setUnlocalizedName(IndustrialWires.MODID + ".panel_component");
|
||||
|
@ -154,4 +160,27 @@ public class ItemPanelComponent extends Item {
|
|||
}
|
||||
return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(NBTTagCompound data, EntityPlayer player, EnumHand hand) {
|
||||
ItemStack held = player.getHeldItem(hand);
|
||||
if (held!=null && held.getItem() == IndustrialWires.panelComponent) {
|
||||
PanelComponent old = ItemPanelComponent.componentFromStack(held);
|
||||
if (old instanceof IConfigurableComponent) {
|
||||
NBTTagList changes = data.getTagList("data", 10);
|
||||
IConfigurableComponent cmp = (IConfigurableComponent) old;
|
||||
for (int i = 0; i < changes.tagCount(); i++) {
|
||||
NBTTagCompound curr = changes.getCompoundTagAt(i);
|
||||
IConfigurableComponent.ConfigType type = IConfigurableComponent.ConfigType.values()[curr.getInteger(TYPE)];
|
||||
try {
|
||||
cmp.applyConfigOption(type, curr.getInteger(ID), curr.getTag(VALUE));
|
||||
} catch (Exception x) {
|
||||
x.printStackTrace();
|
||||
}
|
||||
}
|
||||
ItemStack newCmp = ApiUtils.copyStackWithAmount(ItemPanelComponent.stackFromComponent(old), held.stackSize);
|
||||
player.setHeldItem(hand, newCmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* 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.network;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import malte0811.industrialWires.items.INetGUIItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class MessageItemSync implements IMessage {
|
||||
private EnumHand hand;
|
||||
private NBTTagCompound data;
|
||||
|
||||
public MessageItemSync(EnumHand h, NBTTagCompound data) {
|
||||
hand = h;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public MessageItemSync() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
hand = EnumHand.values()[buf.readInt()];
|
||||
data = ByteBufUtils.readTag(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(hand.ordinal());
|
||||
ByteBufUtils.writeTag(buf, data);
|
||||
}
|
||||
|
||||
public static class HandlerServer implements IMessageHandler<MessageItemSync, IMessage> {
|
||||
@Override
|
||||
public IMessage onMessage(MessageItemSync message, MessageContext ctx) {
|
||||
EntityPlayer player = ctx.getServerHandler().player;
|
||||
ItemStack held = player.getHeldItem(message.hand);
|
||||
if (held.getItem() instanceof INetGUIItem) {
|
||||
ctx.getServerHandler().player.getServerWorld().addScheduledTask(() ->
|
||||
((INetGUIItem)held.getItem()).onChange(message.data, player, message.hand));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,6 +35,9 @@ item.industrialwires.panel_component.slider.name=Slider
|
|||
item.industrialwires.panel_component.variac.name=Variac®
|
||||
item.industrialwires.panel_component.toggle_switch.name=Toggle Switch
|
||||
item.industrialwires.panel_component.toggle_switch_covered.name=Covered Toggle Switch
|
||||
item.industrialwires.key.name=Key
|
||||
item.industrialwires.key_named.name=Key for
|
||||
item.industrialwires.key_raw.name=Blank Key
|
||||
|
||||
|
||||
industrialwires.desc.wireLength=Wire length: %1s block(s)
|
||||
|
|
Loading…
Reference in a new issue