Programmer GUI: working in MP

main
Astoria 2 years ago
parent 8e5e02fd6f
commit 47f00747e8

@ -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);

@ -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);
}
}

@ -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) {

@ -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();
}
}

@ -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) {
}
}

@ -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));
}

@ -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) {
}
}

@ -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);
}
}

@ -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);
}

@ -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;
}
}

@ -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();
}
}

@ -5,7 +5,11 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinEntityPlayerSP",
"MixinBlockRenderer"
"MixinEntityPlayerMP",
"MixinBlockRenderer",
"MixinNetClientHandler",
"MixinNetServerHandler",
"AccessorPacket"
],
"client": [
],

@ -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"]
}
}
}

Loading…
Cancel
Save