Multiplayer lives! Somewhat!

main
Astoria 2 years ago
parent 09c57a3d35
commit dbbe82936a

@ -3,10 +3,7 @@ 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.WiremodPacketSyncIO;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringGuiPacket;
import net.brokenmoon.afloydwiremod.packet.*;
import net.brokenmoon.afloydwiremod.ter.TERDisplay;
import net.brokenmoon.afloydwiremod.ter.TERWire;
import net.brokenmoon.afloydwiremod.tile.ChipTile;
@ -31,6 +28,7 @@ public class WireMod implements ModInitializer {
AccessorPacket.callAddIdClassMapping(110, true, true, WiremodProgrammerPacket.class);
AccessorPacket.callAddIdClassMapping(111, true, true, WiremodWiringGuiPacket.class);
AccessorPacket.callAddIdClassMapping(112, true, true, WiremodPacketSyncIO.class);
AccessorPacket.callAddIdClassMapping(113, true, true, WiremodWiringPacket.class);
}
public static final String MOD_ID = "afloydwiremod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

@ -96,6 +96,7 @@ public abstract class AbstractWireTileEntity extends TileEntity {
}
}
}
worldObj.markBlocksDirty(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
}
public void prepForDelete() {

@ -3,9 +3,13 @@ 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.packet.WiremodProgrammerPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.src.EntityClientPlayerMP;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.GuiButton;
import net.minecraft.src.NetClientHandler;
import java.util.ArrayList;
@ -37,12 +41,14 @@ public class GuiWiring extends GuiScrollable {
public GuiWiring(EntityPlayer player, ToolWiring tool, AbstractWireTileEntity wireEntity, int x, int y, int z) {
super.initGui();
this.player = player;
this.tool = tool;
this.x = x;
this.y = y;
this.z = z;
this.wireEntity = wireEntity;
otherEntity = (AbstractWireTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(tool.x, tool.y, tool.z);
System.out.println(player instanceof EntityClientPlayerMP);
}
@Override
@ -74,26 +80,36 @@ public class GuiWiring extends GuiScrollable {
}
} 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) {
wireEntity.outputs[guibutton.slot].wire = new WireConnection(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);
otherEntity.inputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot);
wireEntity.update();
wireEntity.updateIO();
otherEntity.update();
otherEntity.updateIO();
tool.xadd = new ArrayList<Integer>();
tool.yadd = new ArrayList<Integer>();
tool.zadd = new ArrayList<Integer>();
tool.sideadd = new ArrayList<Integer>();
tool.type = "unpaired";
} else if(this.tool.type.equals("output") && otherEntity.outputs[tool.slot].wire.isMade != true && wireEntity.inputs[guibutton.slot].wire.isMade != true ) {
if(otherEntity != null) {
otherEntity.outputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, true, tool.red, tool.green, tool.blue, tool.alpha, tool.width);
wireEntity.inputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot);
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));
netclienthandler.addToSendQueue(new WiremodWiringPacket(this.tool.x, this.tool.y, this.tool.z, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot));
System.out.println("Okay");
} else{
wireEntity.outputs[guibutton.slot].wire = new WireConnection(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);
otherEntity.inputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot);
wireEntity.update();
wireEntity.updateIO();
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 ) {
if(otherEntity != null) {
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, true, tool.red, tool.green, tool.blue, tool.alpha, tool.width));
netclienthandler.addToSendQueue(new WiremodWiringPacket(this.tool.x, this.tool.y, this.tool.z, this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot));
System.out.println("Okay");
} else{
otherEntity.outputs[tool.slot].wire = new WireConnection(this.wireEntity.xCoord, this.wireEntity.yCoord, this.wireEntity.zCoord, tool.slot, guibutton.slot, tool.xadd, tool.yadd, tool.zadd, tool.sideadd, true, tool.red, tool.green, tool.blue, tool.alpha, tool.width);
wireEntity.inputs[guibutton.slot].wire = new WireConnection(this.tool.x, this.tool.y, this.tool.z, guibutton.slot, tool.slot);
wireEntity.update();
wireEntity.updateIO();
otherEntity.update();
otherEntity.updateIO();
}
}
tool.xadd = new ArrayList<Integer>();
tool.yadd = new ArrayList<Integer>();
tool.zadd = new ArrayList<Integer>();

@ -5,10 +5,7 @@ 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.WiremodPacketSyncIO;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerGuiPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket;
import net.brokenmoon.afloydwiremod.packet.WiremodWiringGuiPacket;
import net.brokenmoon.afloydwiremod.packet.*;
import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.src.NetClientHandler;
@ -32,12 +29,11 @@ public class MixinNetClientHandler implements INetHandler {
@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));
((IEntityPlayer)this.mc.thePlayer).displayGuiWiring(((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) {
public void wiremodHandleIODisc(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;
@ -49,4 +45,9 @@ public class MixinNetClientHandler implements INetHandler {
wireEntity.onInventoryChanged();
}
}
@Override
public void wiremodHandleWireChips(WiremodWiringPacket wiremodWiringPacket) {
}
}

@ -1,10 +1,9 @@
package net.brokenmoon.afloydwiremod.mixin;
import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity;
import net.brokenmoon.afloydwiremod.api.WireConnection;
import net.brokenmoon.afloydwiremod.mixinInterfaces.INetHandler;
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.packet.*;
import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.EntityPlayerMP;
@ -12,6 +11,8 @@ import net.minecraft.src.NetServerHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.ArrayList;
@Mixin(value = NetServerHandler.class, remap = false)
public class MixinNetServerHandler implements INetHandler {
@Shadow
@ -35,7 +36,38 @@ public class MixinNetServerHandler implements INetHandler {
}
@Override
public void handleIODisc(WiremodPacketSyncIO wiremodPacketSyncIO) {
public void wiremodHandleIODisc(WiremodPacketSyncIO wiremodPacketSyncIO) {
}
@Override
public void wiremodHandleWireChips(WiremodWiringPacket packet) {
switch(packet.type){
case 0:
AbstractWireTileEntity wireEntity;
if(!packet.backwired) {
wireEntity = (AbstractWireTileEntity) this.mcServer.getWorldManager(this.playerEntity.dimension).getBlockTileEntity(packet.x1, packet.y1, packet.z1);
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.update();
wireEntity.updateIO();
break;
case 1:
AbstractWireTileEntity otherEntity;
if(!packet.backwired) {
otherEntity = (AbstractWireTileEntity)this.mcServer.getWorldManager(this.playerEntity.dimension).getBlockTileEntity(packet.x1, packet.y1, packet.z1);
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.update();
otherEntity.updateIO();
break;
}
System.out.println("9");
}
}

@ -1,9 +1,6 @@
package net.brokenmoon.afloydwiremod.mixinInterfaces;
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.packet.*;
public interface INetHandler {
void wiremodHandleOpenProgrammerGUI(WiremodProgrammerGuiPacket packet);
@ -12,5 +9,7 @@ public interface INetHandler {
void wiremodHandleOpenWiringGUI(WiremodWiringGuiPacket wiremodWiringGuiPacket);
void handleIODisc(WiremodPacketSyncIO wiremodPacketSyncIO);
void wiremodHandleIODisc(WiremodPacketSyncIO wiremodPacketSyncIO);
void wiremodHandleWireChips(WiremodWiringPacket wiremodWiringPacket);
}

@ -61,7 +61,7 @@ public class WiremodPacketSyncIO extends Packet {
this.io[i].wire.isMade = dataInputStream.readBoolean();
if(dataInputStream.readBoolean()){
int ixlength = dataInputStream.readInt();
for(int ix = 0; i < ixlength; i++){
for(int ix = 0; ix < ixlength; ix++){
this.io[i].wire.xadd.add(dataInputStream.readInt());
this.io[i].wire.yadd.add(dataInputStream.readInt());
this.io[i].wire.zadd.add(dataInputStream.readInt());
@ -97,7 +97,7 @@ public class WiremodPacketSyncIO extends Packet {
this.oi[i].wire.isMade = dataInputStream.readBoolean();
if(dataInputStream.readBoolean()){
int ixlength = dataInputStream.readInt();
for(int ix = 0; i < ixlength; i++){
for(int ix = 0; ix < ixlength; ix++){
this.oi[i].wire.xadd.add(dataInputStream.readInt());
this.oi[i].wire.yadd.add(dataInputStream.readInt());
this.oi[i].wire.zadd.add(dataInputStream.readInt());
@ -165,7 +165,7 @@ public class WiremodPacketSyncIO extends Packet {
size++;
dataOutputStream.writeInt(this.io[i].wire.xadd.size());
size = size + 4;
for(int ix = 0; i < this.io[i].wire.xadd.size(); i++){
for(int ix = 0; ix < this.io[i].wire.xadd.size(); ix++){
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));
@ -236,7 +236,7 @@ public class WiremodPacketSyncIO extends Packet {
size++;
dataOutputStream.writeInt(this.oi[i].wire.xadd.size());
size = size + 4;
for(int ix = 0; i < this.oi[i].wire.xadd.size(); i++){
for(int ix = 0; ix < this.oi[i].wire.xadd.size(); ix++){
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));
@ -263,7 +263,7 @@ public class WiremodPacketSyncIO extends Packet {
@Override
public void processPacket(NetHandler netHandler) {
((INetHandler)netHandler).handleIODisc(this);
((INetHandler)netHandler).wiremodHandleIODisc(this);
}
@Override

@ -23,8 +23,8 @@ public class WiremodWiringGuiPacket extends Packet {
this.y = y;
this.z = z;
this.x2 = x2;
this.y2 = z2;
this.z2 = y2;
this.y2 = y2;
this.z2 = z2;
}
@Override
public void readPacketData(DataInputStream dataInputStream) throws IOException {

@ -0,0 +1,121 @@
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;
import java.util.ArrayList;
public class WiremodWiringPacket extends Packet {
public int type;
public int x1;
public int y1;
public int z1;
public int x2;
public int y2;
public int z2;
public int slot1;
public int slot2;
public ArrayList<Integer> xadd;
public ArrayList<Integer> yadd;
public ArrayList<Integer> zadd;
public ArrayList<Integer> sideadd;
public boolean backwired;
public float red = 1.0f;
public float green = 0f;
public float blue = 0f;
public float alpha = 1f;
public float width = 0.5f;
private int size = 0;
public WiremodWiringPacket(){
System.out.println("Z");
}
public WiremodWiringPacket(int x1, int y1, int z1, int x2, int y2, int z2, int slot1, int slot2, ArrayList<Integer> xadd, ArrayList<Integer> yadd, ArrayList<Integer> zadd, ArrayList<Integer> sideadd, boolean b, float red, float green, float blue, float alpha, float width) {
this.type = 0;
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
this.x2 = x2;
this.y2 = y2;
this.z2 = z2;
this.slot1 = slot1;
this.slot2 = slot2;
this.xadd = xadd;
this.yadd = yadd;
this.zadd = zadd;
this.sideadd = sideadd;
this.backwired = b;
this.red = red;
this.blue = blue;
this.green = green;
this.alpha = alpha;
this.width = width;
System.out.println("X");
}
public WiremodWiringPacket(int x1, int y1, int z1, int x2, int y2, int z2, int slot1, int slot2) {
this.type = 1;
this.x1 = x1;
this.y1 = y1;
this.z1 = z1;
this.x2 = x2;
this.y2 = y2;
this.z2 = z2;
this.slot1 = slot1;
this.slot2 = slot2;
}
@Override
public void readPacketData(DataInputStream dataInputStream) throws IOException {
this.type = dataInputStream.readInt();
this.x1 = dataInputStream.readInt();
this.y1 = dataInputStream.readInt();
this.z1 = dataInputStream.readInt();
this.x2 = dataInputStream.readInt();
this.y2 = dataInputStream.readInt();
this.z2 = dataInputStream.readInt();
this.slot1 = dataInputStream.readInt();
this.slot2 = dataInputStream.readInt();
backwired = dataInputStream.readBoolean();
red = dataInputStream.readFloat();
green = dataInputStream.readFloat();
blue = dataInputStream.readFloat();
alpha = dataInputStream.readFloat();
width = dataInputStream.readFloat();
boolean isxadd = dataInputStream.readBoolean();
System.out.println("C");
}
@Override
public void writePacketData(DataOutputStream dataOutputStream) throws IOException {
dataOutputStream.writeInt(type);
dataOutputStream.writeInt(x1);
dataOutputStream.writeInt(y1);
dataOutputStream.writeInt(z1);
dataOutputStream.writeInt(x2);
dataOutputStream.writeInt(y2);
dataOutputStream.writeInt(z2);
dataOutputStream.writeInt(slot1);
dataOutputStream.writeInt(slot2);
dataOutputStream.writeBoolean(backwired);
dataOutputStream.writeFloat(red);
dataOutputStream.writeFloat(green);
dataOutputStream.writeFloat(blue);
dataOutputStream.writeFloat(alpha);
dataOutputStream.writeFloat(width);
dataOutputStream.writeBoolean(xadd != null);
}
@Override
public void processPacket(NetHandler netHandler) {
((INetHandler)netHandler).wiremodHandleWireChips(this);
}
@Override
public int getPacketSize() {
return 14 * 4 + 2;
}
}
Loading…
Cancel
Save