Sync chip states! Working on chunk load, not after changing block. PROGRESS

main
Astoria 2 years ago
parent 47f00747e8
commit 09c57a3d35

@ -3,8 +3,10 @@ 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.WiremodPacketSyncIO;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringGuiPacket;
import net.brokenmoon.afloydwiremod.ter.TERDisplay;
import net.brokenmoon.afloydwiremod.ter.TERWire;
import net.brokenmoon.afloydwiremod.tile.ChipTile;
@ -25,8 +27,10 @@ import turniplabs.halplibe.helper.ItemHelper;
public class WireMod implements ModInitializer {
public WireMod(){
AccessorPacket.callAddIdClassMapping(109, true, true, WiremodGuiPacket.class);
AccessorPacket.callAddIdClassMapping(109, true, true, WiremodProgrammerGuiPacket.class);
AccessorPacket.callAddIdClassMapping(110, true, true, WiremodProgrammerPacket.class);
AccessorPacket.callAddIdClassMapping(111, true, true, WiremodWiringGuiPacket.class);
AccessorPacket.callAddIdClassMapping(112, true, true, WiremodPacketSyncIO.class);
}
public static final String MOD_ID = "afloydwiremod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

@ -1,9 +1,8 @@
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;
import net.brokenmoon.afloydwiremod.packet.WiremodPacketSyncIO;
import net.minecraft.src.*;
public abstract class AbstractWireTileEntity extends TileEntity {
public WiringButton[] inputs = null;
@ -129,4 +128,9 @@ public abstract class AbstractWireTileEntity extends TileEntity {
}
}
}
@Override
public Packet getDescriptionPacket() {
return new WiremodPacketSyncIO(this.xCoord, this.yCoord, this.zCoord, inputs, outputs);
}
}

@ -3,7 +3,8 @@ 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.brokenmoon.afloydwiremod.packet.WiremodProgrammerGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringGuiPacket;
import net.minecraft.src.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -14,11 +15,13 @@ public class MixinEntityPlayerMP implements IEntityPlayer {
@Override
public void displayGuiProgrammer(AbstractWireTileEntity chip) {
this.playerNetServerHandler.sendPacket(new WiremodGuiPacket(1, chip.xCoord, chip.yCoord, chip.zCoord));
this.playerNetServerHandler.sendPacket(new WiremodProgrammerGuiPacket(chip.xCoord, chip.yCoord, chip.zCoord));
}
@Override
public void displayGuiWiring(ToolWiring tool, AbstractWireTileEntity chip, int x, int y, int z) {
System.out.println("E");
this.playerNetServerHandler.sendPacket(new WiremodWiringGuiPacket(chip.xCoord, chip.yCoord, chip.zCoord, x, y, z));
}

@ -1,13 +1,18 @@
package net.brokenmoon.afloydwiremod.mixin;
import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity;
import net.brokenmoon.afloydwiremod.gui.GuiWiring;
import net.brokenmoon.afloydwiremod.item.ToolWiring;
import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer;
import net.brokenmoon.afloydwiremod.mixinInterfaces.INetHandler;
import net.brokenmoon.afloydwiremod.packet.WiremodGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodPacketSyncIO;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringGuiPacket;
import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.src.NetClientHandler;
import net.minecraft.src.TileEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -16,16 +21,32 @@ 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;
}
public void wiremodHandleOpenProgrammerGUI(WiremodProgrammerGuiPacket packet) {
((IEntityPlayer)this.mc.thePlayer).displayGuiProgrammer((ChipTileEntity)this.mc.theWorld.getBlockTileEntity(packet.x, packet.y, packet.z));
}
@Override
public void wiremodHandleProgramTile(WiremodProgrammerPacket wiremodProgrammerPacket) {
}
@Override
public void wiremodHandleOpenWiringGUI(WiremodWiringGuiPacket packet) {
System.out.println(packet.x + " " + packet.y + " " + packet.z);
this.mc.displayGuiScreen(new GuiWiring(this.mc.thePlayer, ((ToolWiring)this.mc.thePlayer.inventory.getCurrentItem().getItem()), (AbstractWireTileEntity) this.mc.theWorld.getBlockTileEntity(packet.x, packet.y, packet.z), packet.x2, packet.y2, packet.z2));
}
@Override
public void handleIODisc(WiremodPacketSyncIO packet) {
boolean test = this.mc.theWorld.getBlockTileEntity(packet.x, packet.y, packet.z) instanceof ChipTileEntity;
System.out.println("Sync Try! " + " " + packet.x + " " + packet.y + " " + packet.z + " " + test);
TileEntity tileentity;
if (this.mc.theWorld.blockExists(packet.x, packet.y, packet.z) && (tileentity = this.mc.theWorld.getBlockTileEntity(packet.x, packet.y, packet.z)) instanceof AbstractWireTileEntity) {
AbstractWireTileEntity wireEntity = (AbstractWireTileEntity)tileentity;
wireEntity.inputs = packet.io;
wireEntity.outputs = packet.oi;
System.out.println("Synced!");
wireEntity.onInventoryChanged();
}
}
}

@ -1,11 +1,11 @@
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.WiremodPacketSyncIO;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringGuiPacket;
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;
@ -20,7 +20,7 @@ public class MixinNetServerHandler implements INetHandler {
private EntityPlayerMP playerEntity;
@Override
public void wiremodHandleOpenGUI(WiremodGuiPacket packet) {
public void wiremodHandleOpenProgrammerGUI(WiremodProgrammerGuiPacket packet) {
}
@ -28,4 +28,14 @@ public class MixinNetServerHandler implements INetHandler {
public void wiremodHandleProgramTile(WiremodProgrammerPacket packet) {
((ChipTileEntity)this.mcServer.getWorldManager(this.playerEntity.dimension).getBlockTileEntity(packet.x, packet.y, packet.z)).setMode(packet.mode);
}
@Override
public void wiremodHandleOpenWiringGUI(WiremodWiringGuiPacket wiremodWiringGuiPacket) {
}
@Override
public void handleIODisc(WiremodPacketSyncIO wiremodPacketSyncIO) {
}
}

@ -1,10 +1,16 @@
package net.brokenmoon.afloydwiremod.mixinInterfaces;
import net.brokenmoon.afloydwiremod.packet.WiremodGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodPacketSyncIO;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringGuiPacket;
public interface INetHandler {
void wiremodHandleOpenGUI(WiremodGuiPacket packet);
void wiremodHandleOpenProgrammerGUI(WiremodProgrammerGuiPacket packet);
void wiremodHandleProgramTile(WiremodProgrammerPacket wiremodProgrammerPacket);
void wiremodHandleOpenWiringGUI(WiremodWiringGuiPacket wiremodWiringGuiPacket);
void handleIODisc(WiremodPacketSyncIO wiremodPacketSyncIO);
}

@ -0,0 +1,273 @@
package net.brokenmoon.afloydwiremod.packet;
import net.brokenmoon.afloydwiremod.api.WireConnection;
import net.brokenmoon.afloydwiremod.gui.WiringButton;
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 WiremodPacketSyncIO extends Packet {
public int x;
public int y;
public int z;
private int size;
public WiringButton[] io;
public WiringButton[] oi;
public WiremodPacketSyncIO(){
this.isChunkDataPacket = true;
}
public WiremodPacketSyncIO(int xCoord, int yCoord, int zCoord, WiringButton[] inputs, WiringButton[] outputs) {
this.isChunkDataPacket = true;
this.x = xCoord;
this.y = yCoord;
this.z = zCoord;
this.io = inputs;
this.oi = outputs;
}
@Override
public void readPacketData(DataInputStream dataInputStream) throws IOException {
this.x = dataInputStream.readInt();
this.y = dataInputStream.readInt();
this.z = dataInputStream.readInt();
if(dataInputStream.readBoolean()){
//INPUT
int length = dataInputStream.readInt();
io = new WiringButton[length];
for(int i = 0; i < length; ++i){
io[i] = new WiringButton();
io[i].x = dataInputStream.readInt();
io[i].y = dataInputStream.readInt();
io[i].buttonString = dataInputStream.readUTF();
io[i].floatvalue = dataInputStream.readFloat();
io[i].stringvalue = dataInputStream.readUTF();
if(dataInputStream.readBoolean()){
this.io[i].wire = new WireConnection();
this.io[i].wire.x = dataInputStream.readInt();
this.io[i].wire.y = dataInputStream.readInt();
this.io[i].wire.z = dataInputStream.readInt();
this.io[i].wire.thisslot = dataInputStream.readInt();
this.io[i].wire.thatslot = dataInputStream.readInt();
this.io[i].wire.red = dataInputStream.readFloat();
this.io[i].wire.green = dataInputStream.readFloat();
this.io[i].wire.blue = dataInputStream.readFloat();
this.io[i].wire.alpha = dataInputStream.readFloat();
this.io[i].wire.width = dataInputStream.readFloat();
this.io[i].wire.backwired = dataInputStream.readBoolean();
this.io[i].wire.isMade = dataInputStream.readBoolean();
if(dataInputStream.readBoolean()){
int ixlength = dataInputStream.readInt();
for(int ix = 0; i < ixlength; i++){
this.io[i].wire.xadd.add(dataInputStream.readInt());
this.io[i].wire.yadd.add(dataInputStream.readInt());
this.io[i].wire.zadd.add(dataInputStream.readInt());
this.io[i].wire.sideadd.add(dataInputStream.readInt());
}
}
}
}
}
if(dataInputStream.readBoolean()){
int length = dataInputStream.readInt();
oi = new WiringButton[length];
for(int i = 0; i < length; ++i){
oi[i] = new WiringButton();
oi[i].x = dataInputStream.readInt();
oi[i].y = dataInputStream.readInt();
oi[i].buttonString = dataInputStream.readUTF();
oi[i].floatvalue = dataInputStream.readFloat();
oi[i].stringvalue = dataInputStream.readUTF();
if(dataInputStream.readBoolean()){
this.oi[i].wire = new WireConnection();
this.oi[i].wire.x = dataInputStream.readInt();
this.oi[i].wire.y = dataInputStream.readInt();
this.oi[i].wire.z = dataInputStream.readInt();
this.oi[i].wire.thisslot = dataInputStream.readInt();
this.oi[i].wire.thatslot = dataInputStream.readInt();
this.oi[i].wire.red = dataInputStream.readFloat();
this.oi[i].wire.green = dataInputStream.readFloat();
this.oi[i].wire.blue = dataInputStream.readFloat();
this.oi[i].wire.alpha = dataInputStream.readFloat();
this.oi[i].wire.width = dataInputStream.readFloat();
this.oi[i].wire.backwired = dataInputStream.readBoolean();
this.oi[i].wire.isMade = dataInputStream.readBoolean();
if(dataInputStream.readBoolean()){
int ixlength = dataInputStream.readInt();
for(int ix = 0; i < ixlength; i++){
this.oi[i].wire.xadd.add(dataInputStream.readInt());
this.oi[i].wire.yadd.add(dataInputStream.readInt());
this.oi[i].wire.zadd.add(dataInputStream.readInt());
this.oi[i].wire.sideadd.add(dataInputStream.readInt());
}
}
}
}
}
}
@Override
public void writePacketData(DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeInt(x);
dataOutputStream.writeInt(y);
dataOutputStream.writeInt(z);
size = size + 4;
size = size + 4;
size = size + 4;
if(io != null){
dataOutputStream.writeBoolean(true);
size++;
dataOutputStream.writeInt(io.length);
size = size + 4;
for(int i = 0; i < this.io.length; ++i){
dataOutputStream.writeInt(this.io[i].x);
size = size + 4;
dataOutputStream.writeInt(this.io[i].y);
size = size + 4;
dataOutputStream.writeUTF(this.io[i].buttonString);
size = size + this.io[i].buttonString.length();
dataOutputStream.writeFloat(this.io[i].floatvalue);
size = size + 4;
dataOutputStream.writeUTF(this.io[i].stringvalue);
size = size + this.io[i].stringvalue.length();
if(io[i].wire != null){
dataOutputStream.writeBoolean(true);
size++;
dataOutputStream.writeInt(this.io[i].wire.x);
dataOutputStream.writeInt(this.io[i].wire.y);
dataOutputStream.writeInt(this.io[i].wire.z);
size = size + 4;
size = size + 4;
size = size + 4;
dataOutputStream.writeInt(this.io[i].wire.thisslot);
dataOutputStream.writeInt(this.io[i].wire.thatslot);
dataOutputStream.writeFloat(this.io[i].wire.red);
size = size + 4;
size = size + 4;
size = size + 4;
dataOutputStream.writeFloat(this.io[i].wire.green);
dataOutputStream.writeFloat(this.io[i].wire.blue);
dataOutputStream.writeFloat(this.io[i].wire.alpha);
size = size + 4;
size = size + 4;
size = size + 4;
dataOutputStream.writeFloat(this.io[i].wire.width);
dataOutputStream.writeBoolean(this.io[i].wire.backwired);
dataOutputStream.writeBoolean(this.io[i].wire.isMade);
size = size + 4;
size++;
size++;
if(this.io[i].wire.xadd != null){
dataOutputStream.writeBoolean(true);
size++;
dataOutputStream.writeInt(this.io[i].wire.xadd.size());
size = size + 4;
for(int ix = 0; i < this.io[i].wire.xadd.size(); i++){
dataOutputStream.writeInt(this.io[i].wire.xadd.get(ix));
dataOutputStream.writeInt(this.io[i].wire.yadd.get(ix));
dataOutputStream.writeInt(this.io[i].wire.zadd.get(ix));
dataOutputStream.writeInt(this.io[i].wire.sideadd.get(ix));
size = size + 4;
size = size + 4;
size = size + 4;
size = size + 4;
}
} else {
dataOutputStream.writeBoolean(false);
size++;
}
} else{
dataOutputStream.writeBoolean(false);
size++;
}
}
} else {
dataOutputStream.writeBoolean(false);
size++;
}
if(oi != null){
dataOutputStream.writeBoolean(true);
size++;
dataOutputStream.writeInt(oi.length);
size = size + 4;
for(int i = 0; i < this.oi.length; ++i){
dataOutputStream.writeInt(this.oi[i].x);
size = size + 4;
dataOutputStream.writeInt(this.oi[i].y);
size = size + 4;
dataOutputStream.writeUTF(this.oi[i].buttonString);
size = size + this.oi[i].buttonString.length();
dataOutputStream.writeFloat(this.oi[i].floatvalue);
size = size + 4;
dataOutputStream.writeUTF(this.oi[i].stringvalue);
size = size + this.oi[i].stringvalue.length();
if(oi[i].wire != null){
dataOutputStream.writeBoolean(true);
size++;
dataOutputStream.writeInt(this.oi[i].wire.x);
dataOutputStream.writeInt(this.oi[i].wire.y);
dataOutputStream.writeInt(this.oi[i].wire.z);
size = size + 4;
size = size + 4;
size = size + 4;
dataOutputStream.writeInt(this.oi[i].wire.thisslot);
dataOutputStream.writeInt(this.oi[i].wire.thatslot);
dataOutputStream.writeFloat(this.oi[i].wire.red);
size = size + 4;
size = size + 4;
size = size + 4;
dataOutputStream.writeFloat(this.oi[i].wire.green);
dataOutputStream.writeFloat(this.oi[i].wire.blue);
dataOutputStream.writeFloat(this.oi[i].wire.alpha);
size = size + 4;
size = size + 4;
size = size + 4;
dataOutputStream.writeFloat(this.oi[i].wire.width);
dataOutputStream.writeBoolean(this.oi[i].wire.backwired);
dataOutputStream.writeBoolean(this.oi[i].wire.isMade);
size = size + 4;
size++;
size++;
if(this.oi[i].wire.xadd != null){
dataOutputStream.writeBoolean(true);
size++;
dataOutputStream.writeInt(this.oi[i].wire.xadd.size());
size = size + 4;
for(int ix = 0; i < this.oi[i].wire.xadd.size(); i++){
dataOutputStream.writeInt(this.oi[i].wire.xadd.get(ix));
dataOutputStream.writeInt(this.oi[i].wire.yadd.get(ix));
dataOutputStream.writeInt(this.oi[i].wire.zadd.get(ix));
dataOutputStream.writeInt(this.oi[i].wire.sideadd.get(ix));
size = size + 4;
size = size + 4;
size = size + 4;
size = size + 4;
}
} else {
dataOutputStream.writeBoolean(false);
size++;
}
} else{
dataOutputStream.writeBoolean(false);
size++;
}
}
} else {
dataOutputStream.writeBoolean(false);
size++;
}
}
@Override
public void processPacket(NetHandler netHandler) {
((INetHandler)netHandler).handleIODisc(this);
}
@Override
public int getPacketSize() {
return size;
}
}

@ -8,17 +8,15 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
public class WiremodGuiPacket extends Packet {
public int guiType;
public class WiremodProgrammerGuiPacket extends Packet {
public int x;
public int y;
public int z;
public WiremodGuiPacket(){
public WiremodProgrammerGuiPacket(){
}
public WiremodGuiPacket(int type, int x, int y, int z){
this.guiType = type;
public WiremodProgrammerGuiPacket(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
@ -26,7 +24,6 @@ public class WiremodGuiPacket extends Packet {
@Override
public void readPacketData(DataInputStream dataInputStream) throws IOException {
this.guiType = dataInputStream.readInt();
this.x = dataInputStream.readInt();
this.y = dataInputStream.readInt();
this.z = dataInputStream.readInt();
@ -35,7 +32,6 @@ public class WiremodGuiPacket extends Packet {
@Override
public void writePacketData(DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeInt(this.guiType);
dataOutputStream.writeInt(this.x);
dataOutputStream.writeInt(this.y);
dataOutputStream.writeInt(this.z);
@ -43,11 +39,11 @@ public class WiremodGuiPacket extends Packet {
@Override
public void processPacket(NetHandler netHandler) {
((INetHandler)netHandler).wiremodHandleOpenGUI(this);
((INetHandler)netHandler).wiremodHandleOpenProgrammerGUI(this);
}
@Override
public int getPacketSize() {
return 4 * 4;
return 3 * 4;
}
}

@ -0,0 +1,58 @@
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 WiremodWiringGuiPacket extends Packet {
public int x;
public int y;
public int z;
public int x2;
public int y2;
public int z2;
public WiremodWiringGuiPacket(){
}
public WiremodWiringGuiPacket(int x, int y, int z, int x2, int y2, int z2){
this.x = x;
this.y = y;
this.z = z;
this.x2 = x2;
this.y2 = z2;
this.z2 = y2;
}
@Override
public void readPacketData(DataInputStream dataInputStream) throws IOException {
this.x = dataInputStream.readInt();
this.y = dataInputStream.readInt();
this.z = dataInputStream.readInt();
this.x2 = dataInputStream.readInt();
this.y2 = dataInputStream.readInt();
this.z2 = dataInputStream.readInt();
}
@Override
public void writePacketData(DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeInt(this.x);
dataOutputStream.writeInt(this.y);
dataOutputStream.writeInt(this.z);
dataOutputStream.writeInt(this.x2);
dataOutputStream.writeInt(this.y2);
dataOutputStream.writeInt(this.z2);
}
@Override
public void processPacket(NetHandler netHandler) {
((INetHandler)netHandler).wiremodHandleOpenWiringGUI(this);
}
@Override
public int getPacketSize() {
return 6 * 4;
}
}
Loading…
Cancel
Save