Work on initial data system for jetpacks/gasmasks

This commit is contained in:
Aidan Brady 2013-12-09 17:08:47 -05:00
parent 44a69da8a1
commit 26f0f83574
4 changed files with 99 additions and 23 deletions

View file

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

View file

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

View file

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

View file

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