From 327afae1d28ca3bbb0e234e1f16bc7b50fef096a Mon Sep 17 00:00:00 2001 From: Astoria Date: Thu, 6 Apr 2023 20:41:18 -0500 Subject: [PATCH] More progress towards multiplayer --- .../net/brokenmoon/afloydwiremod/WireMod.java | 6 +++- .../api/AbstractWireTileEntity.java | 7 ++-- .../afloydwiremod/gui/GuiWireTool.java | 5 +-- .../afloydwiremod/gui/GuiWiring.java | 9 +++-- .../afloydwiremod/item/ToolWiring.java | 8 ++--- .../mixin/MixinEntityPlayerMP.java | 8 +++-- .../mixin/MixinEntityPlayerSP.java | 4 +-- .../mixin/MixinNetClientHandler.java | 11 ++++++ .../mixin/MixinNetServerHandler.java | 17 ++++++++-- .../mixinInterfaces/IEntityPlayer.java | 2 +- .../mixinInterfaces/INetHandler.java | 4 +++ .../packet/WiremodSettingsGuiPacket.java | 34 +++++++++++++++++++ .../packet/WiremodWireGuiPacket.java | 31 +++++++++++++++++ .../tileentity/ChipTileEntity.java | 1 + .../tileentity/RedstoneLinkTileEntity.java | 1 + 15 files changed, 128 insertions(+), 20 deletions(-) create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodSettingsGuiPacket.java create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodWireGuiPacket.java diff --git a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java index a46e60e..14fa53b 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java @@ -29,14 +29,18 @@ public class WireMod implements ModInitializer { AccessorPacket.callAddIdClassMapping(111, true, true, WiremodWiringGuiPacket.class); AccessorPacket.callAddIdClassMapping(112, true, true, WiremodPacketSyncIO.class); AccessorPacket.callAddIdClassMapping(113, true, true, WiremodWiringPacket.class); + AccessorPacket.callAddIdClassMapping(114, true, true, WiremodSettingsGuiPacket.class); + AccessorPacket.callAddIdClassMapping(500, true, true, WiremodWireGuiPacket.class); } + public static final String MOD_ID = "afloydwiremod"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static Block ChipTile = BlockHelper.createBlock(MOD_ID, new ChipTile(905, Material.iron), "chipTile", "chip.png", Block.soundMetalFootstep,1.5f, 6f, 0 ); public static Item ToolProgrammer = ItemHelper.createItem(MOD_ID, new ToolProgrammer(906), "toolProgrammer", "progtool.png"); - public static Item ToolWiring = ItemHelper.createItem(MOD_ID, new ToolWiring(907), "toolWiring", "wiretool.png"); + public static ToolWiring ToolWiringClass = new ToolWiring(907); + public static Item ToolWiring = ItemHelper.createItem(MOD_ID, ToolWiringClass, "toolWiring", "wiretool.png"); public static Block LinkTileInactive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(908, Material.iron, false), "linkTile", "linkOff.png", Block.soundStoneFootstep, 1.5f, 6f, 0); public static Block LinkTileActive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(909, Material.iron, true), "linkTile", "linkOn.png", Block.soundStoneFootstep, 1.5f, 6f, 0); diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java index 1a04aae..01102ab 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java @@ -12,6 +12,7 @@ public abstract class AbstractWireTileEntity extends TileEntity { public void update() { updateIO(); + worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); } @Override @@ -96,7 +97,7 @@ public abstract class AbstractWireTileEntity extends TileEntity { } } } - worldObj.markBlocksDirty(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord); + worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); } public void prepForDelete() { @@ -112,6 +113,8 @@ public abstract class AbstractWireTileEntity extends TileEntity { otherChip.inputs[wire.thatslot].wire.isMade = false; this.updateIO(); otherChip.updateIO(); + worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); + worldObj.markBlockNeedsUpdate(wire.x, wire.y, wire.z); } } } @@ -121,7 +124,7 @@ public abstract class AbstractWireTileEntity extends TileEntity { 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 && otherChip.outputs != null) { + if(otherChip != null && otherChip.outputs != null && otherChip.outputs.length > wire.thatslot) { otherChip.outputs[wire.thatslot].wire.isMade = false; otherChip.updateIO(); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java index 57ec8bb..b2e5645 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java @@ -1,5 +1,6 @@ package net.brokenmoon.afloydwiremod.gui; +import net.brokenmoon.afloydwiremod.WireMod; import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; import net.minecraft.client.Minecraft; @@ -15,9 +16,9 @@ public class GuiWireTool extends GuiScreen { public GuiSlider blue; public GuiSlider alpha; public GuiSlider widthslider; - public GuiWireTool(EntityPlayerSP entityPlayerSP, ToolWiring toolWiring) { + public GuiWireTool(EntityPlayerSP entityPlayerSP) { super.initGui(); - this.tool = toolWiring; + this.tool = WireMod.ToolWiringClass; } @Override diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java index 291b077..3c740e3 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWiring.java @@ -79,7 +79,7 @@ public class GuiWiring extends GuiScrollable { tool.sideadd = new ArrayList(); } } else if(!this.tool.type.equals("unpaired")) { - if(this.tool.type.equals("input") && wireEntity.outputs[guibutton.slot].wire.isMade != true && otherEntity.inputs[tool.slot].wire.isMade != true) { + if(this.tool.type.equals("input") && wireEntity.outputs[guibutton.slot].wire.isMade != true && otherEntity != null && otherEntity.inputs[tool.slot].wire.isMade != true) { if(this.player instanceof EntityClientPlayerMP){ NetClientHandler netclienthandler = ((EntityClientPlayerMP)this.mc.thePlayer).sendQueue; netclienthandler.addToSendQueue(new WiremodWiringPacket(wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord, this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, false, tool.red, tool.green, tool.blue, tool.alpha, tool.width)); @@ -93,7 +93,12 @@ public class GuiWiring extends GuiScrollable { otherEntity.update(); otherEntity.updateIO(); } - } else if(this.tool.type.equals("output") && otherEntity.outputs[tool.slot].wire.isMade != true && wireEntity.inputs[guibutton.slot].wire.isMade != true ) { + tool.xadd = new ArrayList(); + tool.yadd = new ArrayList(); + tool.zadd = new ArrayList(); + tool.sideadd = new ArrayList(); + tool.type = "unpaired"; + } else if(this.tool.type.equals("output") && otherEntity.outputs[tool.slot].wire.isMade != true && otherEntity != null && wireEntity.inputs[guibutton.slot].wire.isMade != true ) { if(otherEntity != null) { if(this.player instanceof EntityClientPlayerMP){ NetClientHandler netclienthandler = ((EntityClientPlayerMP)this.mc.thePlayer).sendQueue; diff --git a/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java b/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java index 5ce1472..fe123fa 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/item/ToolWiring.java @@ -33,7 +33,7 @@ public class ToolWiring extends Item { public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l, double heightPlaced) { if(entityplayer.isSneaking()){ if (!world.isMultiplayerAndNotHost) { - this.displayWireSettings(entityplayer, this); + this.displayWireSettings(entityplayer); return true; } } else { @@ -46,14 +46,14 @@ public class ToolWiring extends Item { return false; } - private void displayWireSettings(EntityPlayer player, ToolWiring toolWiring) { + private void displayWireSettings(EntityPlayer player) { if(player instanceof EntityPlayerMP) { //Multiplayer - ((IEntityPlayer)player).displayGuiWireSettings(toolWiring); + ((IEntityPlayer)player).displayGuiWireSettings(); return; } //Singleplayer - ((IEntityPlayer)player).displayGuiWireSettings(toolWiring); + ((IEntityPlayer)player).displayGuiWireSettings(); } @Override diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerMP.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerMP.java index a3469e2..d6c6f3b 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerMP.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerMP.java @@ -4,6 +4,8 @@ import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.item.ToolWiring; import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerGuiPacket; +import net.brokenmoon.afloydwiremod.packet.WiremodSettingsGuiPacket; +import net.brokenmoon.afloydwiremod.packet.WiremodWireGuiPacket; import net.brokenmoon.afloydwiremod.packet.WiremodWiringGuiPacket; import net.minecraft.src.*; import org.spongepowered.asm.mixin.Mixin; @@ -27,11 +29,11 @@ public class MixinEntityPlayerMP implements IEntityPlayer { @Override public void displayGuiSettings(AbstractWireTileEntity chip) { - + this.playerNetServerHandler.sendPacket(new WiremodSettingsGuiPacket(chip.xCoord, chip.yCoord, chip.zCoord)); } @Override - public void displayGuiWireSettings(ToolWiring toolWiring) { - + public void displayGuiWireSettings() { + this.playerNetServerHandler.sendPacket(new WiremodWireGuiPacket()); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java index 8009d43..e6c80ec 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinEntityPlayerSP.java @@ -34,7 +34,7 @@ public class MixinEntityPlayerSP implements IEntityPlayer { } @Override - public void displayGuiWireSettings(ToolWiring toolWiring) { - this.mc.displayGuiScreen(new GuiWireTool(((EntityPlayerSP)(Object)this), toolWiring)); + public void displayGuiWireSettings() { + this.mc.displayGuiScreen(new GuiWireTool(((EntityPlayerSP)(Object)this))); } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetClientHandler.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetClientHandler.java index b840423..4a0d8e4 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetClientHandler.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetClientHandler.java @@ -1,5 +1,6 @@ package net.brokenmoon.afloydwiremod.mixin; +import net.brokenmoon.afloydwiremod.WireMod; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; import net.brokenmoon.afloydwiremod.gui.GuiWiring; import net.brokenmoon.afloydwiremod.item.ToolWiring; @@ -50,4 +51,14 @@ public class MixinNetClientHandler implements INetHandler { public void wiremodHandleWireChips(WiremodWiringPacket wiremodWiringPacket) { } + + @Override + public void wiremodHandleWireToolGui(WiremodSettingsGuiPacket wiremodSettingsGuiPacket) { + + } + + @Override + public void wiremodHandleWireToolSettingsGui(WiremodWireGuiPacket wiremodWireGuiPacket) { + ((IEntityPlayer)this.mc.thePlayer).displayGuiWireSettings(); + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetServerHandler.java b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetServerHandler.java index bc20985..e16d7e9 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetServerHandler.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixin/MixinNetServerHandler.java @@ -50,7 +50,7 @@ public class MixinNetServerHandler implements INetHandler { wireEntity.outputs[packet.slot1].wire = new WireConnection(packet.x2, packet.y2, packet.z2, packet.slot1, packet.slot2, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), packet.backwired, packet.red, packet.green, packet.blue, packet.alpha, packet.width); } else{ wireEntity = (AbstractWireTileEntity) this.mcServer.getWorldManager(this.playerEntity.dimension).getBlockTileEntity(packet.x2, packet.y2, packet.z2); - wireEntity.outputs[packet.slot1].wire = new WireConnection(packet.x1, packet.y1, packet.z1, packet.slot1, packet.slot2, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), packet.backwired, packet.red, packet.green, packet.blue, packet.alpha, packet.width); + wireEntity.outputs[packet.slot2].wire = new WireConnection(packet.x1, packet.y1, packet.z1, packet.slot1, packet.slot2, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), packet.backwired, packet.red, packet.green, packet.blue, packet.alpha, packet.width); } wireEntity.update(); wireEntity.updateIO(); @@ -62,12 +62,23 @@ public class MixinNetServerHandler implements INetHandler { otherEntity.inputs[packet.slot2].wire = new WireConnection(packet.x2, packet.y2, packet.z2, packet.slot1, packet.slot2); } else{ otherEntity = (AbstractWireTileEntity)this.mcServer.getWorldManager(this.playerEntity.dimension).getBlockTileEntity(packet.x2, packet.y2, packet.z2); - otherEntity.inputs[packet.slot2].wire = new WireConnection(packet.x1, packet.y1, packet.z1, packet.slot1, packet.slot2); + otherEntity.inputs[packet.slot1].wire = new WireConnection(packet.x1, packet.y1, packet.z1, packet.slot1, packet.slot2); } otherEntity.update(); otherEntity.updateIO(); break; } - System.out.println("9"); + this.mcServer.getWorldManager(this.playerEntity.dimension).markBlockNeedsUpdate(packet.x1, packet.y1, packet.z1); + this.mcServer.getWorldManager(this.playerEntity.dimension).markBlockNeedsUpdate(packet.x2, packet.y2, packet.z2); + } + + @Override + public void wiremodHandleWireToolGui(WiremodSettingsGuiPacket wiremodSettingsGuiPacket) { + + } + + @Override + public void wiremodHandleWireToolSettingsGui(WiremodWireGuiPacket wiremodWireGuiPacket) { + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java index e6f04a2..8e7274b 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/IEntityPlayer.java @@ -9,5 +9,5 @@ public interface IEntityPlayer { public void displayGuiWiring(ToolWiring tool, AbstractWireTileEntity chip, int x, int y, int z); public void displayGuiSettings(AbstractWireTileEntity chip); - public void displayGuiWireSettings(ToolWiring toolWiring); + public void displayGuiWireSettings(); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler.java b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler.java index 395bb04..88a0c65 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/mixinInterfaces/INetHandler.java @@ -12,4 +12,8 @@ public interface INetHandler { void wiremodHandleIODisc(WiremodPacketSyncIO wiremodPacketSyncIO); void wiremodHandleWireChips(WiremodWiringPacket wiremodWiringPacket); + + void wiremodHandleWireToolGui(WiremodSettingsGuiPacket wiremodSettingsGuiPacket); + + void wiremodHandleWireToolSettingsGui(WiremodWireGuiPacket wiremodWireGuiPacket); } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodSettingsGuiPacket.java b/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodSettingsGuiPacket.java new file mode 100644 index 0000000..4016d29 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodSettingsGuiPacket.java @@ -0,0 +1,34 @@ +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 WiremodSettingsGuiPacket extends Packet { + public WiremodSettingsGuiPacket(int xCoord, int yCoord, int zCoord) { + } + + @Override + public void readPacketData(DataInputStream dataInputStream) throws IOException { + + } + + @Override + public void writePacketData(DataOutputStream dataOutputStream) throws IOException { + + } + + @Override + public void processPacket(NetHandler netHandler) { + + } + + @Override + public int getPacketSize() { + return 0; + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodWireGuiPacket.java b/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodWireGuiPacket.java new file mode 100644 index 0000000..ca36126 --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/packet/WiremodWireGuiPacket.java @@ -0,0 +1,31 @@ +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 WiremodWireGuiPacket extends Packet { + @Override + public void readPacketData(DataInputStream dataInputStream) throws IOException { + + } + + @Override + public void writePacketData(DataOutputStream dataOutputStream) throws IOException { + + } + + @Override + public void processPacket(NetHandler netHandler) { + ((INetHandler)netHandler).wiremodHandleWireToolSettingsGui(this); + } + + @Override + public int getPacketSize() { + return 0; + } +} diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java index ce75b84..6dd51ce 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/ChipTileEntity.java @@ -132,6 +132,7 @@ public class ChipTileEntity extends AbstractWireTileEntity { doPulse(); break; } + worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); } private void doPulse() { diff --git a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java index 87cb766..61be81b 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/tileentity/RedstoneLinkTileEntity.java @@ -43,5 +43,6 @@ public class RedstoneLinkTileEntity extends AbstractWireTileEntity { this.shouldnotremove = false; this.isActive = false; } + worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord); } }