diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java new file mode 100644 index 0000000..45c0154 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java @@ -0,0 +1,47 @@ +package net.brokenmoon.afloydwiremod.api; + +import net.brokenmoon.afloydwiremod.WireMod; +import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.minecraft.src.*; + +public abstract class AbstractWireTile extends BlockContainer { + public AbstractWireTile(int i, Material material) { + super(i, material); + } + @Override + public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player){ + AbstractWireTileEntity wireEntity = (AbstractWireTileEntity)world.getBlockTileEntity(x, y, z); + if (!world.isMultiplayerAndNotHost) { + if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().itemID == WireMod.ToolProgrammer.itemID && !wireEntity.initialized) { + this.displayProgrammingGui(player, wireEntity); + return true; + } else if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().itemID == WireMod.ToolWiring.itemID && wireEntity.initialized) { + ToolWiring tool = ((ToolWiring)player.inventory.getCurrentItem().getItem()); + this.displayWiringGui(player, wireEntity, tool, x, y, z); + return true; + } + } + return false; + } + public void displayWiringGui(EntityPlayer player, AbstractWireTileEntity chip, ToolWiring tool, int x, int y, int z) { + if(player instanceof EntityPlayerMP) { + //Multiplayer + ((IEntityPlayer)player).displayGuiWiring(tool, chip, x, y, z); + return; + } + //Singleplayer + ((IEntityPlayer)player).displayGuiWiring(tool, chip, x, y, z); + } + public void displayProgrammingGui(EntityPlayer player, AbstractWireTileEntity chip){ + if(player instanceof EntityPlayerMP) { + //Multiplayer + ((IEntityPlayer)player).displayGuiProgrammer(chip); + return; + } + //Singleplayer + ((IEntityPlayer)player).displayGuiProgrammer(chip); + + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java new file mode 100644 index 0000000..f55259c --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java @@ -0,0 +1,92 @@ +package net.brokenmoon.afloydwiremod.api; + +import net.brokenmoon.afloydwiremod.gui.WiringButton; +import net.minecraft.src.NBTTagCompound; +import net.minecraft.src.NBTTagList; +import net.minecraft.src.TileEntity; + +public abstract class AbstractWireTileEntity extends TileEntity { + public WiringButton[] inputs = null; + public WiringButton[] outputs = null; + public boolean initialized = false; + + @Override + public void updateEntity() { + updateIO(); + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) { + super.readFromNBT(nbttagcompound); + this.initialized = nbttagcompound.getBoolean("init"); + if(nbttagcompound.getBoolean("inputExists")){ + this.inputs = new WiringButton[nbttagcompound.getInteger("inputLength")]; + NBTTagList nbttaglistInputs = nbttagcompound.getTagList("Inputs"); + for (int i = 0; i < nbttaglistInputs.tagCount(); ++i) { + NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglistInputs.tagAt(i); + this.inputs[i] = new WiringButton(); + this.inputs[i].readFromNBT(nbttagcompound1); + } + } + if(nbttagcompound.getBoolean("outputExists")){ + this.outputs = new WiringButton[nbttagcompound.getInteger("outputLength")]; + NBTTagList nbttaglistOutputs = nbttagcompound.getTagList("Outputs"); + for (int i = 0; i < nbttaglistOutputs.tagCount(); ++i) { + NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglistOutputs.tagAt(i); + this.outputs[i] = new WiringButton(); + this.outputs[i].readFromNBT(nbttagcompound1); + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + nbttagcompound.setBoolean("init", this.initialized); + if(inputs != null){ + nbttagcompound.setBoolean("inputExists", true); + nbttagcompound.setInteger("inputLength", inputs.length); + NBTTagList nbttaglistInputs = new NBTTagList(); + for(int i = 0; i < this.inputs.length; ++i){ + NBTTagCompound nbttagInput = new NBTTagCompound(); + this.inputs[i].writeToNBT(nbttagInput); + nbttaglistInputs.setTag(nbttagInput); + } + nbttagcompound.setTag("Inputs", nbttaglistInputs); + } else { + nbttagcompound.setBoolean("inputExists", false); + } + if(outputs != null){ + nbttagcompound.setBoolean("outputExists", true); + nbttagcompound.setInteger("outputLength", outputs.length); + NBTTagList nbttaglistOutputs = new NBTTagList(); + for(int i = 0; i < this.outputs.length; ++i){ + NBTTagCompound nbttagOutput = new NBTTagCompound(); + this.outputs[i].writeToNBT(nbttagOutput); + nbttaglistOutputs.setTag(nbttagOutput); + } + nbttagcompound.setTag("Outputs", nbttaglistOutputs); + } else { + nbttagcompound.setBoolean("outputExists", false); + } + } + + public void updateIO(){ + if(inputs != null) { + for (int i = 0; i < inputs.length; ++i) { + if (inputs[i].wire != null && inputs[i].wire.thisslot > -1) { + WireConnection wire = inputs[i].wire; + AbstractWireTileEntity otherChip = (AbstractWireTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); + if(otherChip == null) break; + if(otherChip.outputs == null) break; + if(inputs[i].floatvalue != otherChip.outputs[wire.thatslot].floatvalue) { + inputs[i].floatvalue = otherChip.outputs[wire.thatslot].floatvalue; + } + if(!inputs[i].stringvalue.equals(otherChip.outputs[wire.thatslot].stringvalue)) { + inputs[i].stringvalue = otherChip.outputs[wire.thatslot].stringvalue; + } + } + } + } + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/IWireConnectable.java b/src/main/java/net/brokenmoon/afloydwiremod/api/IWireConnectable.java deleted file mode 100644 index a4617ef..0000000 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/IWireConnectable.java +++ /dev/null @@ -1,6 +0,0 @@ -package net.brokenmoon.afloydwiremod.api; - -import java.util.ArrayList; - -public interface IWireConnectable { -} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java index c5888c7..48fcd5a 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/WireConnection.java @@ -34,7 +34,6 @@ public class WireConnection { nbttagcompound.setInteger("wz", this.z); nbttagcompound.setInteger("wthisslot", thisslot); nbttagcompound.setInteger("wthatslot", thatslot); - System.out.println("Writing wires to nbt"); return nbttagcompound; } @@ -44,6 +43,5 @@ public class WireConnection { this.z = nbttagcompound.getInteger("wz"); this.thisslot = nbttagcompound.getInteger("wthisslot"); this.thatslot = nbttagcompound.getInteger("wthatslot"); - System.out.println("Loading wires from nbt"); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java index 7cb0bc7..8411194 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java @@ -6,15 +6,14 @@ public class GuiButtonExtended extends GuiButton { public String type; public int slot; - public GuiButtonExtended(int xPosition, int yPosition, String s, String extra, int slot) { - super(0, xPosition, yPosition, s); + public static final int width = 50; + public static final int height = 10; + public GuiButtonExtended(int id, int xPosition, String s, String extra, int slot) { + super(id, xPosition / 2 - (width / 2), 50 - height + (height * id), width, height, s); this.type = extra; this.slot = slot; } - - public GuiButtonExtended(int xPosition, int yPosition, int width, int height, String s, String extra, int slot) { - super(0, xPosition, yPosition, width, height, s); - this.type = extra; - this.slot = slot; + public GuiButtonExtended(int id, int xPosition, String s) { + super(id, xPosition / 2 - (width / 2), 50 - height + (height * id), width, height, s); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java index e9f34af..f6eef74 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -1,31 +1,51 @@ package net.brokenmoon.afloydwiremod.gui; +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; import net.minecraft.src.*; +import org.lwjgl.input.Mouse; public class GuiProgrammer extends GuiScreen { - private ChipTileEntity chip; + private AbstractWireTileEntity wireEntity; + + private int scroll; @Override public void initGui() { //this.height - 240 is top //This.width / 2 - this.controlList.add(new GuiButton(1, this.width / 2 - 214, this.height - 240, "Constant")); - this.controlList.add(new GuiButton(2, this.width / 2 - 214, this.height - 220, "Count")); + this.controlList.add(new GuiButtonExtended(1, this.width, "Constant")); + this.controlList.add(new GuiButtonExtended(2, this.width, "Count")); + } + + @Override + public void drawScreen(int x, int y, float renderPartialTicks) { + int wheel = Mouse.getDWheel(); + for (int i = 0; i < this.controlList.size(); ++i) { + GuiButton guibutton = this.controlList.get(i); + if(wheel > 0) + guibutton.yPosition = guibutton.yPosition + 1; + if(wheel < 0) + guibutton.yPosition = guibutton.yPosition - 1; + if(guibutton.yPosition >= 50 && guibutton.yPosition <= 200) + guibutton.drawButton(this.mc, x, y); + } } - public GuiProgrammer(EntityPlayer player, ChipTileEntity chip) { + public GuiProgrammer(EntityPlayer player, AbstractWireTileEntity wireEntity) { super.initGui(); - this.chip = chip; + this.wireEntity = wireEntity; } @Override protected void actionPerformed(GuiButton guibutton) { - if (guibutton.id == 1) { - chip.setMode("constant"); - } else if(guibutton.id == 2){ - chip.setMode("count"); + if(wireEntity instanceof ChipTileEntity) { + if (guibutton.id == 1) { + ((ChipTileEntity) wireEntity).setMode("constant"); + } else if (guibutton.id == 2) { + ((ChipTileEntity) wireEntity).setMode("count"); + } } this.mc.displayGuiScreen(null); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java index b473fc9..5f10bb4 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java @@ -1,12 +1,12 @@ package net.brokenmoon.afloydwiremod.gui; +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.api.WireConnection; import net.brokenmoon.afloydwiremod.item.ToolWiring; -import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; import net.minecraft.src.EntityPlayer; import net.minecraft.src.GuiButton; import net.minecraft.src.GuiScreen; -import net.minecraft.src.TileEntity; +import org.lwjgl.input.Mouse; public class GuiWiring extends GuiScreen { private ToolWiring tool; @@ -14,32 +14,46 @@ public class GuiWiring extends GuiScreen { private int x; private int y; private int z; - private ChipTileEntity chip; + private AbstractWireTileEntity wireEntity; @Override public void initGui() { //this.height - 240 is top //This.width / 2 - 214 is left //Inputs - if(chip.inputs != null && this.tool.type.equals("output")) { - for (int i = 0; i < chip.inputs.length; i++) { - this.controlList.add(new GuiButtonExtended(this.width / 2 - chip.inputs[i].x, this.height - chip.inputs[i].y, chip.inputs[i].buttonString, "Input", chip.inputs[i].slot)); + if(wireEntity.inputs != null && this.tool.type.equals("output")) { + for (int i = 0; i < wireEntity.inputs.length; i++) { + this.controlList.add(new GuiButtonExtended(i + 1, this.width, wireEntity.inputs[i].buttonString, "Input", wireEntity.inputs[i].slot)); } } //Outputs - if(chip.outputs != null && !this.tool.type.equals("output")) { - for (int i = 0; i < chip.outputs.length; i++) { - this.controlList.add(new GuiButtonExtended(this.width / 2 - chip.outputs[i].x, this.height - chip.outputs[i].y, chip.outputs[i].buttonString, "Output", chip.outputs[i].slot)); + if(wireEntity.outputs != null && !this.tool.type.equals("output")) { + for (int i = 0; i < wireEntity.outputs.length; i++) { + this.controlList.add(new GuiButtonExtended(i + 1, this.width, wireEntity.outputs[i].buttonString, "Output", wireEntity.outputs[i].slot)); } } } - public GuiWiring(EntityPlayer player, ToolWiring tool, ChipTileEntity chip, int x, int y, int z) { + @Override + public void drawScreen(int x, int y, float renderPartialTicks) { + int wheel = Mouse.getDWheel(); + for (int i = 0; i < this.controlList.size(); ++i) { + GuiButton guibutton = this.controlList.get(i); + if(wheel > 0) + guibutton.yPosition = guibutton.yPosition + 1; + if(wheel < 0) + guibutton.yPosition = guibutton.yPosition - 1; + if(guibutton.yPosition >= 50 && guibutton.yPosition <= 200) + guibutton.drawButton(this.mc, x, y); + } + } + + public GuiWiring(EntityPlayer player, ToolWiring tool, AbstractWireTileEntity wireEntity, int x, int y, int z) { super.initGui(); this.tool = tool; this.x = x; this.y = y; this.z = z; - this.chip = chip; + this.wireEntity = wireEntity; } @Override @@ -62,8 +76,7 @@ public class GuiWiring extends GuiScreen { this.tool.z = z; } } else if(this.tool.type.equals("output")) { - this.chip.inputs[guibutton.slot].wire = new WireConnection(tool.x, tool.y, tool.z, guibutton.slot, tool.slot); - System.out.print(guibutton.slot + " " + tool.slot); + this.wireEntity.inputs[guibutton.slot].wire = new WireConnection(tool.x, tool.y, tool.z, guibutton.slot, tool.slot); tool.type = "unpaired"; } this.mc.displayGuiScreen(null); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java index 89d2493..7d867b0 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java @@ -1,5 +1,6 @@ package net.brokenmoon.afloydwiremod.mixin; +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.gui.GuiProgrammer; import net.brokenmoon.afloydwiremod.gui.GuiWiring; import net.brokenmoon.afloydwiremod.item.ToolWiring; @@ -14,12 +15,12 @@ import org.spongepowered.asm.mixin.Shadow; public class MixinEntityPlayerSP implements IEntityPlayer { @Shadow protected Minecraft mc; - public void displayGuiProgrammer(ChipTileEntity chip) { + public void displayGuiProgrammer(AbstractWireTileEntity chip) { this.mc.displayGuiScreen(new GuiProgrammer(((EntityPlayerSP)(Object)this), chip)); } @Override - public void displayGuiWiring(ToolWiring tool, ChipTileEntity chip, int x, int y, int z) { + public void displayGuiWiring(ToolWiring tool, AbstractWireTileEntity chip, int x, int y, int z) { this.mc.displayGuiScreen(new GuiWiring(((EntityPlayerSP)(Object)this), tool, chip, x, y, z)); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinTileEntity.java deleted file mode 100644 index 917f287..0000000 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinTileEntity.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.brokenmoon.afloydwiremod.mixin; - -import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; -import net.brokenmoon.afloydwiremod.tileentity.RedstoneLinkTileEntity; -import net.minecraft.src.TileEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(value = TileEntity.class, remap = false) -public class MixinTileEntity { - @Shadow - private static void addMapping(Class class1, String s) {} - - static { - addMapping(ChipTileEntity.class, "Chip"); - addMapping(RedstoneLinkTileEntity.class, "Link"); - } -} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java index 0e00a3b..dafcee6 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java @@ -1,10 +1,11 @@ package net.brokenmoon.afloydwiremod.mixinInterfaces; +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; public interface IEntityPlayer { - public void displayGuiProgrammer(ChipTileEntity chip); + public void displayGuiProgrammer(AbstractWireTileEntity chip); - public void displayGuiWiring(ToolWiring tool, ChipTileEntity chip, int x, int y, int z); + public void displayGuiWiring(ToolWiring tool, AbstractWireTileEntity chip, int x, int y, int z); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tile/ChipTile.java b/src/main/java/net/brokenmoon/afloydwiremod/tile/ChipTile.java index 1667103..bca5e30 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tile/ChipTile.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tile/ChipTile.java @@ -1,60 +1,14 @@ package net.brokenmoon.afloydwiremod.tile; -import net.brokenmoon.afloydwiremod.WireMod; -import net.brokenmoon.afloydwiremod.item.ToolWiring; -import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; +import net.brokenmoon.afloydwiremod.api.AbstractWireTile; import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; -import net.brokenmoon.afloydwiremod.tileentity.RedstoneLinkTileEntity; import net.minecraft.src.*; -public class ChipTile extends BlockContainer { +public class ChipTile extends AbstractWireTile { public ChipTile(int i, Material material) { super(i, material); } - @Override - public void onBlockRemoval(World world, int i, int j, int k) { - super.onBlockRemoval(world, i, j, k); - } - @Override - public boolean blockActivated(World world, int x, int y, int z, EntityPlayer player){ - ChipTileEntity chip = (ChipTileEntity)world.getBlockTileEntity(x, y, z); - if (!world.isMultiplayerAndNotHost) { - if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().itemID == WireMod.ToolProgrammer.itemID && chip.mode.equals("none")) { - this.displayProgrammingGui(player, chip); - return true; - } else if(player.inventory.getCurrentItem() != null && player.inventory.getCurrentItem().itemID == WireMod.ToolWiring.itemID && !chip.mode.equals("none")) { - ToolWiring tool = ((ToolWiring)player.inventory.getCurrentItem().getItem()); - this.displayWiringGui(player, chip, tool, x, y, z); - return true; - } - if(chip instanceof RedstoneLinkTileEntity) - System.out.println(((RedstoneLinkTileEntity)chip).inputs[0].wire.x); - } - return false; - } - - private void displayWiringGui(EntityPlayer player, ChipTileEntity chip, ToolWiring tool, int x, int y, int z) { - if(player instanceof EntityPlayerMP) { - //Multiplayer - ((IEntityPlayer)player).displayGuiWiring(tool, chip, x, y, z); - return; - } - //Singleplayer - ((IEntityPlayer)player).displayGuiWiring(tool, chip, x, y, z); - } - - public static void displayProgrammingGui(EntityPlayer player, ChipTileEntity chip){ - if(player instanceof EntityPlayerMP) { - //Multiplayer - ((IEntityPlayer)player).displayGuiProgrammer(chip); - return; - } - //Singleplayer - ((IEntityPlayer)player).displayGuiProgrammer(chip); - - } - @Override protected TileEntity getBlockEntity() { return new ChipTileEntity(); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java b/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java index c6ffb9a..b369396 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tile/RedstoneLinkTile.java @@ -1,35 +1,36 @@ package net.brokenmoon.afloydwiremod.tile; import net.brokenmoon.afloydwiremod.WireMod; +import net.brokenmoon.afloydwiremod.api.AbstractWireTile; import net.brokenmoon.afloydwiremod.tileentity.RedstoneLinkTileEntity; import net.minecraft.src.*; import java.util.Random; -public class RedstoneLinkTile extends ChipTile { +public class RedstoneLinkTile extends AbstractWireTile { + + boolean isActive; public RedstoneLinkTile(int i, Material material, boolean isActive) { super(i, material); this.isActive = isActive; this.setTickOnLoad(true); } - boolean isActive; - @Override - public boolean renderAsNormalBlock(){ - return false; - } public static void updateLinkBlockState(boolean flag, World world, int x, int y, int z) { if (flag) { world.setBlockAndMetadataWithNotify(x, y, z, WireMod.LinkTileActive.blockID, 1); - System.out.println("activating"); } if (!flag) { world.setBlockAndMetadataWithNotify(x, y, z, WireMod.LinkTileInactive.blockID, 1); - System.out.println("deactivating"); } } + @Override + public boolean renderAsNormalBlock() { + return false; + } + @Override public int tickRate() { return 2; @@ -37,20 +38,20 @@ public class RedstoneLinkTile extends ChipTile { @Override public void onBlockAdded(World world, int x, int y, int z) { - if(world.getBlockMetadata(x, y, z) == 0){ + if (world.getBlockMetadata(x, y, z) == 0) { world.setBlockTileEntity(x, y, z, new RedstoneLinkTileEntity()); } } @Override public void onBlockRemoval(World world, int x, int y, int z) { - if(world.getBlockTileEntity(x, y, z) != null && !((RedstoneLinkTileEntity)world.getBlockTileEntity(x, y, z)).shouldnotremove) + if (world.getBlockTileEntity(x, y, z) != null && !((RedstoneLinkTileEntity) world.getBlockTileEntity(x, y, z)).shouldnotremove) super.onBlockRemoval(world, x, y, z); } @Override public void updateTick(World world, int i, int j, int k, Random random) { - RedstoneLinkTileEntity link = (RedstoneLinkTileEntity)world.getBlockTileEntity(i, j, k); + RedstoneLinkTileEntity link = (RedstoneLinkTileEntity) world.getBlockTileEntity(i, j, k); if (world.isBlockGettingPowered(i, j, k)) { link.outputs[0].floatvalue = 1.0f; } else { diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java index b8af53d..9bf0ffc 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -1,107 +1,57 @@ package net.brokenmoon.afloydwiremod.tileentity; -import net.brokenmoon.afloydwiremod.api.IWireConnectable; -import net.brokenmoon.afloydwiremod.api.WireConnection; +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.gui.WiringButton; -import net.minecraft.client.Minecraft; -import net.minecraft.src.*; +import net.minecraft.src.NBTTagCompound; -import java.util.ArrayList; - -public class ChipTileEntity extends TileEntity implements IWireConnectable { - - public WiringButton[] inputs = null; - public WiringButton[] outputs = null; +public class ChipTileEntity extends AbstractWireTileEntity { public String mode = "none"; + private boolean shouldIncrement = true; @Override public void updateEntity() { updateIO(); - switch(mode){ + switch (mode) { case "count": doIncrement(); break; } } - private boolean shouldIncrement = true; - public void doIncrement(){ - if(this.inputs[2].floatvalue > 0){ + public void doIncrement() { + if (inputs[2].floatvalue > 0) { this.outputs[0].floatvalue = 0; return; } - if(this.inputs[1].floatvalue > 0 && shouldIncrement){ + if (this.inputs[1].floatvalue > 0 && shouldIncrement) { this.outputs[0].floatvalue = this.outputs[0].floatvalue + this.inputs[0].floatvalue; shouldIncrement = false; System.out.println("Incrementing to " + this.outputs[0].floatvalue); - } else if(this.inputs[1].floatvalue == 0.0 && !shouldIncrement){ + } else if (this.inputs[1].floatvalue == 0.0 && !shouldIncrement) { shouldIncrement = true; } } + @Override public void readFromNBT(NBTTagCompound nbttagcompound) { super.readFromNBT(nbttagcompound); this.mode = nbttagcompound.getString("mode"); - if(nbttagcompound.getBoolean("inputExists")){ - this.inputs = new WiringButton[nbttagcompound.getInteger("inputLength")]; - NBTTagList nbttaglistInputs = nbttagcompound.getTagList("Inputs"); - for (int i = 0; i < nbttaglistInputs.tagCount(); ++i) { - NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglistInputs.tagAt(i); - this.inputs[i] = new WiringButton(); - this.inputs[i].readFromNBT(nbttagcompound1); - } - } - if(nbttagcompound.getBoolean("outputExists")){ - this.outputs = new WiringButton[nbttagcompound.getInteger("outputLength")]; - NBTTagList nbttaglistOutputs = nbttagcompound.getTagList("Outputs"); - for (int i = 0; i < nbttaglistOutputs.tagCount(); ++i) { - NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglistOutputs.tagAt(i); - this.outputs[i] = new WiringButton(); - this.outputs[i].readFromNBT(nbttagcompound1); - } - } } + @Override public void writeToNBT(NBTTagCompound nbttagcompound) { super.writeToNBT(nbttagcompound); nbttagcompound.setString("mode", mode); - if(inputs != null){ - nbttagcompound.setBoolean("inputExists", true); - nbttagcompound.setInteger("inputLength", inputs.length); - NBTTagList nbttaglistInputs = new NBTTagList(); - for(int i = 0; i < this.inputs.length; ++i){ - NBTTagCompound nbttagInput = new NBTTagCompound(); - this.inputs[i].writeToNBT(nbttagInput); - nbttaglistInputs.setTag(nbttagInput); - } - nbttagcompound.setTag("Inputs", nbttaglistInputs); - } else { - nbttagcompound.setBoolean("inputExists", false); - } - if(outputs != null){ - nbttagcompound.setBoolean("outputExists", true); - nbttagcompound.setInteger("outputLength", outputs.length); - NBTTagList nbttaglistOutputs = new NBTTagList(); - for(int i = 0; i < this.outputs.length; ++i){ - NBTTagCompound nbttagOutput = new NBTTagCompound(); - this.outputs[i].writeToNBT(nbttagOutput); - nbttaglistOutputs.setTag(nbttagOutput); - } - nbttagcompound.setTag("Outputs", nbttaglistOutputs); - } else { - nbttagcompound.setBoolean("outputExists", false); - } } - public void setMode(String string){ - if(mode.equals("none")) { - if(string.equals("constant")) { - System.out.println(string); + public void setMode(String string) { + if (mode.equals("none")) { + if (string.equals("constant")) { mode = string; this.inputs = new WiringButton[0]; this.outputs = new WiringButton[1]; - } else if(string.equals("count")){ - System.out.println(string); + initialized = true; + } else if (string.equals("count")) { mode = string; this.inputs = new WiringButton[3]; this.outputs = new WiringButton[1]; @@ -109,26 +59,7 @@ public class ChipTileEntity extends TileEntity implements IWireConnectable { this.inputs[0] = new WiringButton(214, 220, "Source", 0); this.inputs[1] = new WiringButton(214, 200, "Clock", 1); this.inputs[2] = new WiringButton(214, 180, "Reset", 2); - System.out.println("ae"); - } - } - } - - public void updateIO(){ - if(inputs != null) { - for (int i = 0; i < inputs.length; ++i) { - if (inputs[i].wire != null && inputs[i].wire.thisslot > -1) { - WireConnection wire = inputs[i].wire; - ChipTileEntity otherChip = (ChipTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); - if(otherChip == null) break; - if(otherChip.outputs == null) break; - if(inputs[i].floatvalue != otherChip.outputs[wire.thatslot].floatvalue) { - inputs[i].floatvalue = otherChip.outputs[wire.thatslot].floatvalue; - } - if(!inputs[i].stringvalue.equals(otherChip.outputs[wire.thatslot].stringvalue)) { - inputs[i].stringvalue = otherChip.outputs[wire.thatslot].stringvalue; - } - } + initialized = true; } } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java index 2780d61..863f4cb 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java @@ -1,26 +1,22 @@ package net.brokenmoon.afloydwiremod.tileentity; import net.brokenmoon.afloydwiremod.WireMod; -import net.brokenmoon.afloydwiremod.api.IWireConnectable; -import net.brokenmoon.afloydwiremod.api.WireConnection; +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.gui.WiringButton; import net.brokenmoon.afloydwiremod.tile.RedstoneLinkTile; -import net.minecraft.src.BlockSensor; import net.minecraft.src.NBTTagCompound; -import net.minecraft.src.NBTTagList; -import net.minecraft.src.TileEntity; -public class RedstoneLinkTileEntity extends ChipTileEntity { +public class RedstoneLinkTileEntity extends AbstractWireTileEntity { public boolean isActive = false; public boolean shouldnotremove = false; public RedstoneLinkTileEntity(){ super(); - this.mode = "rslink"; inputs = new WiringButton[1]; outputs = new WiringButton[1]; outputs[0] = new WiringButton(214, 240, "Output", 0); inputs[0] = new WiringButton(214, 220, "Input", 0); + this.initialized = true; } @Override diff --git a/src/main/resources/afloydwiremod.mixins.json b/src/main/resources/afloydwiremod.mixins.json index 4a1cfc6..82d0380 100644 --- a/src/main/resources/afloydwiremod.mixins.json +++ b/src/main/resources/afloydwiremod.mixins.json @@ -4,7 +4,6 @@ "package": "net.brokenmoon.afloydwiremod.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "MixinTileEntity", "MixinEntityPlayerSP" ], "client": [