2014-07-21 12:52:39 -08:00
|
|
|
package tconstruct.util.network;
|
2014-02-01 17:28:41 +11:00
|
|
|
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
2014-09-09 18:30:15 +10:00
|
|
|
import mantle.common.network.*;
|
2014-02-01 17:28:41 +11:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-03-15 17:19:42 +11:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-02-01 17:28:41 +11:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
2014-03-15 17:19:42 +11:00
|
|
|
import tconstruct.TConstruct;
|
2014-06-04 21:44:48 -08:00
|
|
|
import tconstruct.smeltery.logic.SmelteryLogic;
|
2014-02-01 17:28:41 +11:00
|
|
|
|
2014-07-21 12:52:39 -08:00
|
|
|
public class SmelteryPacket extends AbstractPacket
|
2014-02-05 09:11:06 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int dimension, x, y, z, fluidID;
|
|
|
|
|
boolean isShiftPressed;
|
|
|
|
|
|
2014-07-21 12:52:39 -08:00
|
|
|
public SmelteryPacket()
|
2014-02-05 09:11:06 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 12:52:39 -08:00
|
|
|
public SmelteryPacket(int dimension, int x, int y, int z, boolean isShiftPressed, int fluidID)
|
2014-02-05 09:11:06 -05:00
|
|
|
{
|
|
|
|
|
this.dimension = dimension;
|
|
|
|
|
this.x = x;
|
|
|
|
|
this.y = y;
|
|
|
|
|
this.z = z;
|
|
|
|
|
this.isShiftPressed = isShiftPressed;
|
|
|
|
|
this.fluidID = fluidID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void encodeInto (ChannelHandlerContext ctx, ByteBuf buffer)
|
|
|
|
|
{
|
|
|
|
|
buffer.writeInt(dimension);
|
|
|
|
|
buffer.writeInt(x);
|
|
|
|
|
buffer.writeInt(y);
|
|
|
|
|
buffer.writeInt(z);
|
|
|
|
|
buffer.writeBoolean(isShiftPressed);
|
2014-03-03 16:58:38 -05:00
|
|
|
buffer.writeInt(fluidID);
|
2014-02-05 09:11:06 -05:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void decodeInto (ChannelHandlerContext ctx, ByteBuf buffer)
|
|
|
|
|
{
|
|
|
|
|
dimension = buffer.readInt();
|
|
|
|
|
x = buffer.readInt();
|
2014-02-01 17:28:41 +11:00
|
|
|
y = buffer.readInt();
|
|
|
|
|
z = buffer.readInt();
|
|
|
|
|
isShiftPressed = buffer.readBoolean();
|
|
|
|
|
fluidID = buffer.readInt();
|
2014-02-05 09:11:06 -05:00
|
|
|
}
|
2014-02-01 17:28:41 +11:00
|
|
|
|
2014-02-05 09:11:06 -05:00
|
|
|
@Override
|
|
|
|
|
public void handleClientSide (EntityPlayer player)
|
|
|
|
|
{
|
2014-02-01 17:28:41 +11:00
|
|
|
|
2014-02-05 09:11:06 -05:00
|
|
|
}
|
2014-02-01 17:28:41 +11:00
|
|
|
|
2014-02-05 09:11:06 -05:00
|
|
|
@Override
|
|
|
|
|
public void handleServerSide (EntityPlayer player)
|
|
|
|
|
{
|
2014-02-01 17:28:41 +11:00
|
|
|
World world = player.worldObj;
|
2014-02-05 09:11:06 -05:00
|
|
|
|
2014-02-05 08:28:53 -05:00
|
|
|
TileEntity te = world.getTileEntity(x, y, z);
|
2014-02-01 17:28:41 +11:00
|
|
|
if (te instanceof SmelteryLogic)
|
|
|
|
|
{
|
|
|
|
|
FluidStack temp = null;
|
|
|
|
|
|
|
|
|
|
for (FluidStack liquid : ((SmelteryLogic) te).moltenMetal)
|
2014-03-15 17:19:42 +11:00
|
|
|
{
|
2014-02-01 17:28:41 +11:00
|
|
|
if (liquid.fluidID == fluidID)
|
|
|
|
|
{
|
|
|
|
|
temp = liquid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (temp != null)
|
|
|
|
|
{
|
|
|
|
|
((SmelteryLogic) te).moltenMetal.remove(temp);
|
|
|
|
|
if (isShiftPressed)
|
|
|
|
|
((SmelteryLogic) te).moltenMetal.add(temp);
|
|
|
|
|
else
|
|
|
|
|
((SmelteryLogic) te).moltenMetal.add(0, temp);
|
|
|
|
|
}
|
2014-03-15 17:19:42 +11:00
|
|
|
|
|
|
|
|
NBTTagCompound data = new NBTTagCompound();
|
|
|
|
|
te.writeToNBT(data);
|
|
|
|
|
TConstruct.packetPipeline.sendToDimension(new PacketUpdateTE(x, y, z, data), dimension);
|
2014-02-01 17:28:41 +11:00
|
|
|
}
|
2014-02-05 09:11:06 -05:00
|
|
|
}
|
2014-02-01 17:28:41 +11:00
|
|
|
|
|
|
|
|
}
|