2013-12-06 21:26:44 +01:00
|
|
|
package mekanism.common.network;
|
|
|
|
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
|
|
|
|
import mekanism.common.Mekanism;
|
|
|
|
import mekanism.common.PacketHandler;
|
|
|
|
import mekanism.common.PacketHandler.Transmission;
|
|
|
|
import mekanism.common.item.ItemScubaTank;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import com.google.common.io.ByteArrayDataInput;
|
|
|
|
|
|
|
|
public class PacketScubaTankData implements IMekanismPacket
|
|
|
|
{
|
2013-12-09 23:08:47 +01:00
|
|
|
public ScubaTankPacket packetType;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-09 23:34:53 +01:00
|
|
|
public String username;
|
2013-12-06 21:26:44 +01:00
|
|
|
public boolean value;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-06 21:26:44 +01:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public String getName()
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
|
|
|
return "ScubaTankData";
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-06 21:26:44 +01:00
|
|
|
@Override
|
|
|
|
public IMekanismPacket setParams(Object... data)
|
|
|
|
{
|
2013-12-09 23:08:47 +01:00
|
|
|
packetType = (ScubaTankPacket)data[0];
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-09 23:08:47 +01:00
|
|
|
if(packetType == ScubaTankPacket.UPDATE)
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
2013-12-09 23:34:53 +01:00
|
|
|
username = (String)data[1];
|
2013-12-06 21:26:44 +01:00
|
|
|
value = (Boolean)data[2];
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-06 21:26:44 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
|
|
|
|
{
|
2013-12-09 23:08:47 +01:00
|
|
|
packetType = ScubaTankPacket.values()[dataStream.readInt()];
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
if(packetType == ScubaTankPacket.FULL)
|
|
|
|
{
|
2013-12-09 23:08:47 +01:00
|
|
|
Mekanism.gasmaskOn.clear();
|
|
|
|
|
|
|
|
int amount = dataStream.readInt();
|
|
|
|
|
|
|
|
for(int i = 0; i < amount; i++)
|
|
|
|
{
|
2013-12-09 23:34:53 +01:00
|
|
|
Mekanism.gasmaskOn.add(dataStream.readUTF());
|
2013-12-09 23:08:47 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
else if(packetType == ScubaTankPacket.UPDATE)
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
|
|
|
String username = dataStream.readUTF();
|
|
|
|
boolean value = dataStream.readBoolean();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-09 23:34:53 +01:00
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
Mekanism.gasmaskOn.add(username);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Mekanism.gasmaskOn.remove(username);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-09 23:34:53 +01:00
|
|
|
if(!world.isRemote)
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
2013-12-09 23:34:53 +01:00
|
|
|
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketScubaTankData().setParams(ScubaTankPacket.UPDATE, username, value), world.provider.dimensionId);
|
2013-12-06 21:26:44 +01:00
|
|
|
}
|
|
|
|
}
|
2013-12-09 23:08:47 +01:00
|
|
|
else if(packetType == ScubaTankPacket.MODE)
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
|
|
|
ItemStack stack = player.getCurrentItemOrArmor(3);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-06 21:26:44 +01:00
|
|
|
if(stack != null && stack.getItem() instanceof ItemScubaTank)
|
|
|
|
{
|
|
|
|
((ItemScubaTank)stack.getItem()).toggleFlowing(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(DataOutputStream dataStream) throws Exception
|
|
|
|
{
|
|
|
|
dataStream.writeInt(packetType.ordinal());
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-09 23:08:47 +01:00
|
|
|
if(packetType == ScubaTankPacket.UPDATE)
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
2013-12-09 23:34:53 +01:00
|
|
|
dataStream.writeUTF(username);
|
2013-12-06 21:26:44 +01:00
|
|
|
dataStream.writeBoolean(value);
|
|
|
|
}
|
2013-12-09 23:08:47 +01:00
|
|
|
else if(packetType == ScubaTankPacket.FULL)
|
|
|
|
{
|
|
|
|
dataStream.writeInt(Mekanism.gasmaskOn.size());
|
|
|
|
|
2013-12-09 23:34:53 +01:00
|
|
|
for(String username : Mekanism.gasmaskOn)
|
2013-12-09 23:08:47 +01:00
|
|
|
{
|
2013-12-09 23:34:53 +01:00
|
|
|
dataStream.writeUTF(username);
|
2013-12-09 23:08:47 +01:00
|
|
|
}
|
|
|
|
}
|
2013-12-06 21:26:44 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-09 23:08:47 +01:00
|
|
|
public static enum ScubaTankPacket
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
|
|
|
UPDATE,
|
2013-12-09 23:08:47 +01:00
|
|
|
FULL,
|
2013-12-06 21:26:44 +01:00
|
|
|
MODE;
|
|
|
|
}
|
|
|
|
}
|