mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
71 lines
2.2 KiB
Java
71 lines
2.2 KiB
Java
package crazypants.enderio.machine.vat;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import crazypants.enderio.EnderIO;
|
|
import crazypants.enderio.network.MessageTileEntity;
|
|
import crazypants.enderio.network.NetworkUtil;
|
|
|
|
public class PacketTanks extends MessageTileEntity<TileVat> implements IMessageHandler<PacketTanks, IMessage> {
|
|
|
|
private NBTTagCompound nbtRoot;
|
|
|
|
public PacketTanks() {
|
|
}
|
|
|
|
public PacketTanks(TileVat tile) {
|
|
super(tile);
|
|
nbtRoot = new NBTTagCompound();
|
|
if(tile.inputTank.getFluidAmount() > 0) {
|
|
NBTTagCompound tankRoot = new NBTTagCompound();
|
|
tile.inputTank.writeToNBT(tankRoot);
|
|
nbtRoot.setTag("inputTank", tankRoot);
|
|
}
|
|
if(tile.outputTank.getFluidAmount() > 0) {
|
|
NBTTagCompound tankRoot = new NBTTagCompound();
|
|
tile.outputTank.writeToNBT(tankRoot);
|
|
nbtRoot.setTag("outputTank", tankRoot);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void toBytes(ByteBuf buf) {
|
|
super.toBytes(buf);
|
|
NetworkUtil.writeNBTTagCompound(nbtRoot, buf);
|
|
}
|
|
|
|
@Override
|
|
public void fromBytes(ByteBuf buf) {
|
|
super.fromBytes(buf);
|
|
nbtRoot = NetworkUtil.readNBTTagCompound(buf);
|
|
}
|
|
|
|
@Override
|
|
public IMessage onMessage(PacketTanks message, MessageContext ctx) {
|
|
EntityPlayer player = ctx.side == Side.SERVER ? ctx.getServerHandler().playerEntity : EnderIO.proxy.getClientPlayer();
|
|
TileVat tile = message.getTileEntity(player.worldObj);
|
|
if(tile == null) {
|
|
return null;
|
|
}
|
|
if(message.nbtRoot.hasKey("inputTank")) {
|
|
NBTTagCompound tankRoot = message.nbtRoot.getCompoundTag("inputTank");
|
|
tile.inputTank.readFromNBT(tankRoot);
|
|
} else {
|
|
tile.inputTank.setFluid(null);
|
|
}
|
|
if(message.nbtRoot.hasKey("outputTank")) {
|
|
NBTTagCompound tankRoot = message.nbtRoot.getCompoundTag("outputTank");
|
|
tile.outputTank.readFromNBT(tankRoot);
|
|
} else {
|
|
tile.outputTank.setFluid(null);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
}
|