ForgePatch/common/net/minecraftforge/fluids/FluidIdMapPacket.java
Christian 50992f2112 Merge branch 'master' of github.com:KingLemming/MinecraftForge into newliquid
Conflicts:
	common/net/minecraftforge/common/network/ForgePacket.java
2013-05-27 18:16:24 -04:00

52 lines
1.4 KiB
Java

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;
public class FluidIdMapPacket extends ForgePacket {
private BiMap<String, Integer> fluidIds = HashBiMap.create();
@Override
public byte[] generatePacket() {
ByteArrayDataOutput dat = ByteStreams.newDataOutput();
dat.writeInt(FluidRegistry.maxID);
for (Map.Entry<String, Integer> entry : FluidRegistry.fluidIDs.entrySet()) {
dat.writeUTF(entry.getKey());
dat.writeInt(entry.getValue());
}
return dat.toByteArray();
}
@Override
public ForgePacket consumePacket(byte[] data) {
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
public void execute(INetworkManager network, EntityPlayer player) {
FluidRegistry.initFluidIDs(fluidIds);
}
}