From 26f0f83574e7fc3d8558c9141d48f30205da3257 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Mon, 9 Dec 2013 17:08:47 -0500 Subject: [PATCH] Work on initial data system for jetpacks/gasmasks --- common/mekanism/client/ClientTickHandler.java | 8 ++-- .../mekanism/common/CommonPlayerTracker.java | 26 ++++++++++- .../common/network/PacketJetpackData.java | 44 +++++++++++++++---- .../common/network/PacketScubaTankData.java | 44 +++++++++++++++---- 4 files changed, 99 insertions(+), 23 deletions(-) diff --git a/common/mekanism/client/ClientTickHandler.java b/common/mekanism/client/ClientTickHandler.java index ce66f098d..99357cbba 100644 --- a/common/mekanism/client/ClientTickHandler.java +++ b/common/mekanism/client/ClientTickHandler.java @@ -27,7 +27,7 @@ import mekanism.common.network.PacketConfiguratorState; import mekanism.common.network.PacketElectricBowState; import mekanism.common.network.PacketJetpackData; import mekanism.common.network.PacketWalkieTalkieState; -import mekanism.common.network.PacketJetpackData.PacketType; +import mekanism.common.network.PacketJetpackData.JetpackPacket; import mekanism.common.network.PacketScubaTankData; import mekanism.common.util.MekanismUtils; import mekanism.common.util.StackUtils; @@ -255,7 +255,7 @@ public class ClientTickHandler implements ITickHandler if(!lastTickUpdate) { ((ItemJetpack)jetpack.getItem()).incrementMode(jetpack); - PacketHandler.sendPacket(Transmission.SERVER, new PacketJetpackData().setParams(PacketType.MODE)); + PacketHandler.sendPacket(Transmission.SERVER, new PacketJetpackData().setParams(JetpackPacket.MODE)); Minecraft.getMinecraft().sndManager.playSoundFX("mekanism:etc.Hydraulic", 1.0F, 1.0F); lastTickUpdate = true; } @@ -279,7 +279,7 @@ public class ClientTickHandler implements ITickHandler Mekanism.jetpackOn.remove(mc.thePlayer); } - PacketHandler.sendPacket(Transmission.SERVER, new PacketJetpackData().setParams(PacketType.UPDATE, mc.thePlayer, isJetpackOn(mc.thePlayer))); + PacketHandler.sendPacket(Transmission.SERVER, new PacketJetpackData().setParams(JetpackPacket.UPDATE, mc.thePlayer, isJetpackOn(mc.thePlayer))); } if(Mekanism.gasmaskOn.contains(mc.thePlayer) != isGasMaskOn(mc.thePlayer)) @@ -292,7 +292,7 @@ public class ClientTickHandler implements ITickHandler Mekanism.gasmaskOn.remove(mc.thePlayer); } - PacketHandler.sendPacket(Transmission.SERVER, new PacketScubaTankData().setParams(PacketType.UPDATE, mc.thePlayer, isGasMaskOn(mc.thePlayer))); + PacketHandler.sendPacket(Transmission.SERVER, new PacketScubaTankData().setParams(JetpackPacket.UPDATE, mc.thePlayer, isGasMaskOn(mc.thePlayer))); } if(MekanismClient.audioHandler != null) diff --git a/common/mekanism/common/CommonPlayerTracker.java b/common/mekanism/common/CommonPlayerTracker.java index 376c64994..bc84a32f9 100644 --- a/common/mekanism/common/CommonPlayerTracker.java +++ b/common/mekanism/common/CommonPlayerTracker.java @@ -1,22 +1,46 @@ package mekanism.common; +import mekanism.common.PacketHandler.Transmission; +import mekanism.common.network.PacketJetpackData; +import mekanism.common.network.PacketJetpackData.JetpackPacket; +import mekanism.common.network.PacketScubaTankData; +import mekanism.common.network.PacketScubaTankData.ScubaTankPacket; import net.minecraft.entity.player.EntityPlayer; import cpw.mods.fml.common.IPlayerTracker; public class CommonPlayerTracker implements IPlayerTracker { @Override - public void onPlayerLogin(EntityPlayer player) {} + public void onPlayerLogin(EntityPlayer player) + { + if(!player.worldObj.isRemote) + { + PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(JetpackPacket.FULL), player.worldObj.provider.dimensionId); + PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player.worldObj.provider.dimensionId); + } + } @Override public void onPlayerLogout(EntityPlayer player) { Mekanism.jetpackOn.remove(player); + + if(!player.worldObj.isRemote) + { + PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(JetpackPacket.FULL), player.worldObj.provider.dimensionId); + PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player.worldObj.provider.dimensionId); + } } @Override public void onPlayerChangedDimension(EntityPlayer player) { Mekanism.jetpackOn.remove(player); + + if(!player.worldObj.isRemote) + { + PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(JetpackPacket.FULL), player.worldObj.provider.dimensionId); + PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(ScubaTankPacket.FULL), player.worldObj.provider.dimensionId); + } } @Override diff --git a/common/mekanism/common/network/PacketJetpackData.java b/common/mekanism/common/network/PacketJetpackData.java index a1530c845..00a0025ba 100644 --- a/common/mekanism/common/network/PacketJetpackData.java +++ b/common/mekanism/common/network/PacketJetpackData.java @@ -14,7 +14,7 @@ import com.google.common.io.ByteArrayDataInput; public class PacketJetpackData implements IMekanismPacket { - public PacketType packetType; + public JetpackPacket packetType; public EntityPlayer updatePlayer; public boolean value; @@ -28,9 +28,9 @@ public class PacketJetpackData implements IMekanismPacket @Override public IMekanismPacket setParams(Object... data) { - packetType = (PacketType)data[0]; + packetType = (JetpackPacket)data[0]; - if(packetType == PacketType.UPDATE) + if(packetType == JetpackPacket.UPDATE) { updatePlayer = (EntityPlayer)data[1]; value = (Boolean)data[2]; @@ -42,9 +42,25 @@ public class PacketJetpackData implements IMekanismPacket @Override public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception { - packetType = PacketType.values()[dataStream.readInt()]; + packetType = JetpackPacket.values()[dataStream.readInt()]; - if(packetType == PacketType.UPDATE) + if(packetType == JetpackPacket.FULL) + { + Mekanism.jetpackOn.clear(); + + int amount = dataStream.readInt(); + + for(int i = 0; i < amount; i++) + { + EntityPlayer p = world.getPlayerEntityByName(dataStream.readUTF()); + + if(p != null) + { + Mekanism.jetpackOn.add(p); + } + } + } + else if(packetType == JetpackPacket.UPDATE) { String username = dataStream.readUTF(); boolean value = dataStream.readBoolean(); @@ -63,11 +79,11 @@ public class PacketJetpackData implements IMekanismPacket if(!world.isRemote) { - PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(PacketType.UPDATE, p, value), world.provider.dimensionId); + PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(JetpackPacket.UPDATE, p, value), world.provider.dimensionId); } } } - else if(packetType == PacketType.MODE) + else if(packetType == JetpackPacket.MODE) { ItemStack stack = player.getCurrentItemOrArmor(3); @@ -83,16 +99,26 @@ public class PacketJetpackData implements IMekanismPacket { dataStream.writeInt(packetType.ordinal()); - if(packetType == PacketType.UPDATE) + if(packetType == JetpackPacket.UPDATE) { dataStream.writeUTF(updatePlayer.username); dataStream.writeBoolean(value); } + else if(packetType == JetpackPacket.FULL) + { + dataStream.writeInt(Mekanism.jetpackOn.size()); + + for(EntityPlayer player : Mekanism.jetpackOn) + { + dataStream.writeUTF(player.username); + } + } } - public static enum PacketType + public static enum JetpackPacket { UPDATE, + FULL, MODE; } } diff --git a/common/mekanism/common/network/PacketScubaTankData.java b/common/mekanism/common/network/PacketScubaTankData.java index 84f2abc93..d6dc2b9b6 100644 --- a/common/mekanism/common/network/PacketScubaTankData.java +++ b/common/mekanism/common/network/PacketScubaTankData.java @@ -14,7 +14,7 @@ import com.google.common.io.ByteArrayDataInput; public class PacketScubaTankData implements IMekanismPacket { - public PacketType packetType; + public ScubaTankPacket packetType; public EntityPlayer updatePlayer; public boolean value; @@ -28,9 +28,9 @@ public class PacketScubaTankData implements IMekanismPacket @Override public IMekanismPacket setParams(Object... data) { - packetType = (PacketType)data[0]; + packetType = (ScubaTankPacket)data[0]; - if(packetType == PacketType.UPDATE) + if(packetType == ScubaTankPacket.UPDATE) { updatePlayer = (EntityPlayer)data[1]; value = (Boolean)data[2]; @@ -42,9 +42,25 @@ public class PacketScubaTankData implements IMekanismPacket @Override public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception { - packetType = PacketType.values()[dataStream.readInt()]; + packetType = ScubaTankPacket.values()[dataStream.readInt()]; - if(packetType == PacketType.UPDATE) + if(packetType == ScubaTankPacket.FULL) + { + Mekanism.gasmaskOn.clear(); + + int amount = dataStream.readInt(); + + for(int i = 0; i < amount; i++) + { + EntityPlayer p = world.getPlayerEntityByName(dataStream.readUTF()); + + if(p != null) + { + Mekanism.gasmaskOn.add(p); + } + } + } + else if(packetType == ScubaTankPacket.UPDATE) { String username = dataStream.readUTF(); boolean value = dataStream.readBoolean(); @@ -63,11 +79,11 @@ public class PacketScubaTankData implements IMekanismPacket if(!world.isRemote) { - PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(PacketType.UPDATE, p, value), world.provider.dimensionId); + PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(ScubaTankPacket.UPDATE, p, value), world.provider.dimensionId); } } } - else if(packetType == PacketType.MODE) + else if(packetType == ScubaTankPacket.MODE) { ItemStack stack = player.getCurrentItemOrArmor(3); @@ -83,16 +99,26 @@ public class PacketScubaTankData implements IMekanismPacket { dataStream.writeInt(packetType.ordinal()); - if(packetType == PacketType.UPDATE) + if(packetType == ScubaTankPacket.UPDATE) { dataStream.writeUTF(updatePlayer.username); dataStream.writeBoolean(value); } + else if(packetType == ScubaTankPacket.FULL) + { + dataStream.writeInt(Mekanism.gasmaskOn.size()); + + for(EntityPlayer player : Mekanism.gasmaskOn) + { + dataStream.writeUTF(player.username); + } + } } - public static enum PacketType + public static enum ScubaTankPacket { UPDATE, + FULL, MODE; } }