2013-05-23 05:01:19 +00:00
|
|
|
|
|
|
|
package net.minecraftforge.fluids;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.network.INetworkManager;
|
|
|
|
import net.minecraftforge.common.network.ForgePacket;
|
|
|
|
|
|
|
|
import com.google.common.collect.BiMap;
|
|
|
|
import com.google.common.collect.HashBiMap;
|
|
|
|
import com.google.common.io.ByteArrayDataInput;
|
|
|
|
import com.google.common.io.ByteArrayDataOutput;
|
|
|
|
import com.google.common.io.ByteStreams;
|
|
|
|
|
2013-07-17 04:40:49 +00:00
|
|
|
public class FluidIdMapPacket extends ForgePacket
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
private BiMap<String, Integer> fluidIds = HashBiMap.create();
|
|
|
|
|
|
|
|
@Override
|
2013-07-17 04:40:49 +00:00
|
|
|
public byte[] generatePacket()
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
ByteArrayDataOutput dat = ByteStreams.newDataOutput();
|
|
|
|
|
|
|
|
dat.writeInt(FluidRegistry.maxID);
|
2013-07-17 04:40:49 +00:00
|
|
|
for (Map.Entry<String, Integer> entry : FluidRegistry.fluidIDs.entrySet())
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
dat.writeUTF(entry.getKey());
|
|
|
|
dat.writeInt(entry.getValue());
|
|
|
|
}
|
|
|
|
return dat.toByteArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-07-17 04:40:49 +00:00
|
|
|
public ForgePacket consumePacket(byte[] data)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
ByteArrayDataInput dat = ByteStreams.newDataInput(data);
|
|
|
|
int listSize = dat.readInt();
|
|
|
|
for (int i = 0; i < listSize; i++) {
|
|
|
|
String fluidName = dat.readUTF();
|
|
|
|
int fluidId = dat.readInt();
|
|
|
|
fluidIds.put(fluidName, fluidId);
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-07-17 04:40:49 +00:00
|
|
|
public void execute(INetworkManager network, EntityPlayer player)
|
|
|
|
{
|
2013-05-23 05:01:19 +00:00
|
|
|
FluidRegistry.initFluidIDs(fluidIds);
|
|
|
|
}
|
|
|
|
}
|