diff --git a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java index d75e0ed..02f8185 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java @@ -2,6 +2,9 @@ package net.brokenmoon.afloydwiremod; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.mixin.AccessorPacket; +import net.brokenmoon.afloydwiremod.packet.WiremodGuiPacket; +import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket; import net.brokenmoon.afloydwiremod.ter.TERDisplay; import net.brokenmoon.afloydwiremod.ter.TERWire; import net.brokenmoon.afloydwiremod.tile.ChipTile; @@ -21,6 +24,10 @@ import turniplabs.halplibe.helper.ItemHelper; public class WireMod implements ModInitializer { + public WireMod(){ + AccessorPacket.callAddIdClassMapping(109, true, true, WiremodGuiPacket.class); + AccessorPacket.callAddIdClassMapping(110, true, true, WiremodProgrammerPacket.class); + } public static final String MOD_ID = "afloydwiremod"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java index a20abc6..639c1b7 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -1,7 +1,11 @@ package net.brokenmoon.afloydwiremod.gui; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; +import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; +import net.brokenmoon.afloydwiremod.mixinInterfaces.INetHandler; +import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket; import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.minecraft.client.Minecraft; import net.minecraft.src.*; public class GuiProgrammer extends GuiScrollable { @@ -46,42 +50,43 @@ public class GuiProgrammer extends GuiScrollable { public GuiProgrammer(EntityPlayer player, AbstractWireTileEntity wireEntity) { super.initGui(); + this.player = player; this.wireEntity = wireEntity; } @Override protected void actionPerformed(GuiButton guibutton) { - if(wireEntity instanceof ChipTileEntity) { + System.out.println("One"); switch(guibutton.displayString){ case "Constant": - ((ChipTileEntity) wireEntity).setMode("constant"); + this.setMode("constant"); break; case "Increment": - ((ChipTileEntity) wireEntity).setMode("inc"); + this.setMode("inc"); break; case "Duplicate": - ((ChipTileEntity) wireEntity).setMode("dup"); + this.setMode("dup"); break; case "Addition": - ((ChipTileEntity) wireEntity).setMode("add"); + this.setMode("add"); break; case "Subtraction": - ((ChipTileEntity) wireEntity).setMode("sub"); + this.setMode("sub"); break; case "Multiplication": - ((ChipTileEntity) wireEntity).setMode("mult"); + this.setMode("mult"); break; case "Division": - ((ChipTileEntity) wireEntity).setMode("div"); + this.setMode("div"); break; case "Decrement": - ((ChipTileEntity) wireEntity).setMode("dec"); + this.setMode("dec"); break; case "Increment/Decrement": - ((ChipTileEntity) wireEntity).setMode("incdec"); + this.setMode("incdec"); break; case "Memory": - ((ChipTileEntity) wireEntity).setMode("mem"); + this.setMode("mem"); break; case "TRUE": case "FALSE": @@ -100,11 +105,23 @@ public class GuiProgrammer extends GuiScrollable { case "<=": case "<=>": case "Pulse": - ((ChipTileEntity) wireEntity).setMode(guibutton.displayString); + this.setMode(guibutton.displayString); break; - } } this.mc.displayGuiScreen(null); } + public void setMode(String string){ + System.out.println("Two"); + if(this.player instanceof EntityClientPlayerMP){ + System.out.println("Three"); + NetClientHandler netclienthandler = ((EntityClientPlayerMP)this.mc.thePlayer).sendQueue; + netclienthandler.addToSendQueue(new WiremodProgrammerPacket(string, wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord)); + System.out.println("e"); + return; + } + System.out.println("Four"); + ((ChipTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord)).setMode(string); + + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java index cef5180..27e7b25 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java @@ -1,10 +1,12 @@ package net.brokenmoon.afloydwiremod.gui; +import net.minecraft.src.EntityPlayer; import net.minecraft.src.GuiButton; import net.minecraft.src.GuiScreen; import org.lwjgl.input.Mouse; public class GuiScrollable extends GuiScreen { + public EntityPlayer player; private int scroll; @Override public void drawScreen(int x, int y, float renderPartialTicks) { diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/AccessorPacket.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/AccessorPacket.java new file mode 100644 index 0000000..ff9e590 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/AccessorPacket.java @@ -0,0 +1,13 @@ +package net.brokenmoon.afloydwiremod.mixin; + +import net.minecraft.src.Packet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(value = Packet.class, remap = false) +public interface AccessorPacket { + @Invoker("addIdClassMapping") + static void callAddIdClassMapping(int i, boolean clientPacket, boolean serverPacket, Class class1) { + throw new AssertionError(); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerMP.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerMP.java new file mode 100644 index 0000000..4717ac7 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerMP.java @@ -0,0 +1,34 @@ +package net.brokenmoon.afloydwiremod.mixin; + +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; +import net.brokenmoon.afloydwiremod.item.ToolWiring; +import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; +import net.brokenmoon.afloydwiremod.packet.WiremodGuiPacket; +import net.minecraft.src.*; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = EntityPlayerMP.class, remap = false) +public class MixinEntityPlayerMP implements IEntityPlayer { + @Shadow public NetServerHandler playerNetServerHandler; + + @Override + public void displayGuiProgrammer(AbstractWireTileEntity chip) { + this.playerNetServerHandler.sendPacket(new WiremodGuiPacket(1, chip.xCoord, chip.yCoord, chip.zCoord)); + } + + @Override + public void displayGuiWiring(ToolWiring tool, AbstractWireTileEntity chip, int x, int y, int z) { + + } + + @Override + public void displayGuiSettings(AbstractWireTileEntity chip) { + + } + + @Override + public void displayGuiWireSettings(ToolWiring toolWiring) { + + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java index 787d54f..8009d43 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java @@ -17,6 +17,8 @@ import org.spongepowered.asm.mixin.Shadow; public class MixinEntityPlayerSP implements IEntityPlayer { @Shadow protected Minecraft mc; + + @Override public void displayGuiProgrammer(AbstractWireTileEntity chip) { this.mc.displayGuiScreen(new GuiProgrammer(((EntityPlayerSP)(Object)this), chip)); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetClientHandler.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetClientHandler.java new file mode 100644 index 0000000..faac9ed --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetClientHandler.java @@ -0,0 +1,31 @@ +package net.brokenmoon.afloydwiremod.mixin; + +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; +import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; +import net.brokenmoon.afloydwiremod.mixinInterfaces.INetHandler; +import net.brokenmoon.afloydwiremod.packet.WiremodGuiPacket; +import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket; +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.minecraft.client.Minecraft; +import net.minecraft.src.NetClientHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = NetClientHandler.class, remap = false) +public class MixinNetClientHandler implements INetHandler { + @Shadow + Minecraft mc; + @Override + public void wiremodHandleOpenGUI(WiremodGuiPacket packet) { + switch (packet.guiType){ + case 1: + ((IEntityPlayer)this.mc.thePlayer).displayGuiProgrammer((ChipTileEntity)this.mc.theWorld.getBlockTileEntity(packet.x, packet.y, packet.z)); + break; + } + } + + @Override + public void wiremodHandleProgramTile(WiremodProgrammerPacket wiremodProgrammerPacket) { + + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetServerHandler.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetServerHandler.java new file mode 100644 index 0000000..1f38494 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetServerHandler.java @@ -0,0 +1,31 @@ +package net.brokenmoon.afloydwiremod.mixin; + +import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; +import net.brokenmoon.afloydwiremod.mixinInterfaces.INetHandler; +import net.brokenmoon.afloydwiremod.packet.WiremodGuiPacket; +import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket; +import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; +import net.minecraft.client.Minecraft; +import net.minecraft.server.MinecraftServer; +import net.minecraft.src.EntityPlayerMP; +import net.minecraft.src.NetServerHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(value = NetServerHandler.class, remap = false) +public class MixinNetServerHandler implements INetHandler { + @Shadow + private MinecraftServer mcServer; + @Shadow + private EntityPlayerMP playerEntity; + + @Override + public void wiremodHandleOpenGUI(WiremodGuiPacket packet) { + + } + + @Override + public void wiremodHandleProgramTile(WiremodProgrammerPacket packet) { + ((ChipTileEntity)this.mcServer.getWorldManager(this.playerEntity.dimension).getBlockTileEntity(packet.x, packet.y, packet.z)).setMode(packet.mode); + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler.java b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler.java new file mode 100644 index 0000000..70f0222 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler.java @@ -0,0 +1,10 @@ +package net.brokenmoon.afloydwiremod.mixinInterfaces; + +import net.brokenmoon.afloydwiremod.packet.WiremodGuiPacket; +import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket; + +public interface INetHandler { + void wiremodHandleOpenGUI(WiremodGuiPacket packet); + + void wiremodHandleProgramTile(WiremodProgrammerPacket wiremodProgrammerPacket); +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodGuiPacket.java b/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodGuiPacket.java new file mode 100644 index 0000000..3a30433 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodGuiPacket.java @@ -0,0 +1,53 @@ +package net.brokenmoon.afloydwiremod.packet; + +import net.brokenmoon.afloydwiremod.mixinInterfaces.INetHandler; +import net.minecraft.src.NetHandler; +import net.minecraft.src.Packet; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class WiremodGuiPacket extends Packet { + public int guiType; + public int x; + public int y; + public int z; + public WiremodGuiPacket(){ + + } + + public WiremodGuiPacket(int type, int x, int y, int z){ + this.guiType = type; + this.x = x; + this.y = y; + this.z = z; + } + + @Override + public void readPacketData(DataInputStream dataInputStream) throws IOException { + this.guiType = dataInputStream.readInt(); + this.x = dataInputStream.readInt(); + this.y = dataInputStream.readInt(); + this.z = dataInputStream.readInt(); + + } + + @Override + public void writePacketData(DataOutputStream dataOutputStream) throws IOException { + dataOutputStream.writeInt(this.guiType); + dataOutputStream.writeInt(this.x); + dataOutputStream.writeInt(this.y); + dataOutputStream.writeInt(this.z); + } + + @Override + public void processPacket(NetHandler netHandler) { + ((INetHandler)netHandler).wiremodHandleOpenGUI(this); + } + + @Override + public int getPacketSize() { + return 4 * 4; + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodProgrammerPacket.java b/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodProgrammerPacket.java new file mode 100644 index 0000000..ce360d8 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodProgrammerPacket.java @@ -0,0 +1,52 @@ +package net.brokenmoon.afloydwiremod.packet; + +import net.brokenmoon.afloydwiremod.mixinInterfaces.INetHandler; +import net.minecraft.src.NetHandler; +import net.minecraft.src.Packet; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class WiremodProgrammerPacket extends Packet { + public WiremodProgrammerPacket(){ + + } + public String mode; + public int x; + public int y; + public int z; + public WiremodProgrammerPacket(String mode, int x, int y, int z){ + this.mode = mode; + this.x = x; + this.y = y; + this.z = z; + } + @Override + public void readPacketData(DataInputStream dataInputStream) throws IOException { + this.mode = dataInputStream.readUTF(); + this.x = dataInputStream.readInt(); + this.y = dataInputStream.readInt(); + this.z = dataInputStream.readInt(); + } + + @Override + public void writePacketData(DataOutputStream dataOutputStream) throws IOException { + dataOutputStream.writeUTF(mode); + dataOutputStream.writeInt(this.x); + dataOutputStream.writeInt(this.y); + dataOutputStream.writeInt(this.z); + + } + + @Override + public void processPacket(NetHandler netHandler) { + System.out.println("AE"); + ((INetHandler)netHandler).wiremodHandleProgramTile(this); + } + + @Override + public int getPacketSize() { + return (4 * 3) + this.mode.length(); + } +} diff --git a/src/main/resources/afloydwiremod.mixins.json b/src/main/resources/afloydwiremod.mixins.json index 7716fed..0b41183 100644 --- a/src/main/resources/afloydwiremod.mixins.json +++ b/src/main/resources/afloydwiremod.mixins.json @@ -5,7 +5,11 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "MixinEntityPlayerSP", - "MixinBlockRenderer" + "MixinEntityPlayerMP", + "MixinBlockRenderer", + "MixinNetClientHandler", + "MixinNetServerHandler", + "AccessorPacket" ], "client": [ ], diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 61bdcd9..4798ebf 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,7 +33,9 @@ "custom": { "loom:injected_interfaces": { "net/minecraft/src/EntityPlayerSP": ["net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer"], - "net/minecraft/src/EntityPlayerMP": ["net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer"] + "net/minecraft/src/EntityPlayerMP": ["net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer"], + "net/minecraft/src/NetClientHandler": ["net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler"], + "net/minecraft/src/NetServerHandler": ["net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler"] } } }