2013-12-06 21:26:44 +01:00
|
|
|
package mekanism.common.network;
|
|
|
|
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
|
|
|
|
import mekanism.common.Mekanism;
|
|
|
|
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;
|
2014-04-20 22:15:44 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
2013-12-06 21:26:44 +01:00
|
|
|
|
2014-04-20 22:15:44 +02:00
|
|
|
public class PacketScubaTankData extends MekanismPacket
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
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
|
|
|
|
2014-04-20 22:15:44 +02:00
|
|
|
public PacketScubaTankData(ScubaTankPacket type, String name, boolean state)
|
2013-12-06 21:26:44 +01:00
|
|
|
{
|
2014-04-20 22:15:44 +02:00
|
|
|
packetType = type;
|
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
|
|
|
{
|
2014-04-20 22:15:44 +02:00
|
|
|
username = name;
|
|
|
|
value = state;
|
2013-12-06 21:26:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-04-20 22:15:44 +02:00
|
|
|
Mekanism.packetPipeline.sendToDimension(new PacketScubaTankData(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
|
|
|
{
|
2014-04-20 23:34:45 +02:00
|
|
|
ItemStack stack = player.getEquipmentInSlot(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-04-20 22:15:44 +02:00
|
|
|
@Override
|
2014-06-02 16:52:13 +02:00
|
|
|
public void write(ChannelHandlerContext ctx, ByteBuf buffer)
|
2014-04-20 22:15:44 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-02 16:52:13 +02:00
|
|
|
public void read(ChannelHandlerContext ctx, ByteBuf buffer)
|
2014-04-20 22:15:44 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleClientSide(EntityPlayer player)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleServerSide(EntityPlayer player)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|