2025-03-11 00:23:54 +01:00
|
|
|
package game.packet;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import game.item.ItemStack;
|
2025-03-26 12:22:32 +01:00
|
|
|
import game.network.Player;
|
2025-03-11 00:23:54 +01:00
|
|
|
import game.network.Packet;
|
|
|
|
import game.network.PacketBuffer;
|
|
|
|
import game.world.BlockPos;
|
|
|
|
|
2025-03-26 12:22:32 +01:00
|
|
|
public class CPacketPlace implements Packet<Player>
|
2025-03-11 00:23:54 +01:00
|
|
|
{
|
|
|
|
private static final BlockPos DUMMY_POS = new BlockPos(-1, -1, -1);
|
|
|
|
|
|
|
|
private BlockPos position;
|
|
|
|
private int placedBlockDirection;
|
|
|
|
private ItemStack stack;
|
|
|
|
private float facingX;
|
|
|
|
private float facingY;
|
|
|
|
private float facingZ;
|
|
|
|
|
|
|
|
public CPacketPlace()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public CPacketPlace(ItemStack stackIn)
|
|
|
|
{
|
|
|
|
this(DUMMY_POS, 255, stackIn, 0.0F, 0.0F, 0.0F);
|
|
|
|
}
|
|
|
|
|
|
|
|
public CPacketPlace(BlockPos positionIn, int placedBlockDirectionIn, ItemStack stackIn, float facingXIn, float facingYIn, float facingZIn)
|
|
|
|
{
|
|
|
|
this.position = positionIn;
|
|
|
|
this.placedBlockDirection = placedBlockDirectionIn;
|
|
|
|
this.stack = stackIn != null ? stackIn.copy() : null;
|
|
|
|
this.facingX = facingXIn;
|
|
|
|
this.facingY = facingYIn;
|
|
|
|
this.facingZ = facingZIn;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void readPacketData(PacketBuffer buf) throws IOException
|
|
|
|
{
|
|
|
|
this.position = buf.readBlockPos();
|
|
|
|
this.placedBlockDirection = buf.readUnsignedByte();
|
|
|
|
this.stack = buf.readItemStackFromBuffer();
|
|
|
|
this.facingX = (float)buf.readUnsignedByte() / 16.0F;
|
|
|
|
this.facingY = (float)buf.readUnsignedByte() / 16.0F;
|
|
|
|
this.facingZ = (float)buf.readUnsignedByte() / 16.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writePacketData(PacketBuffer buf) throws IOException
|
|
|
|
{
|
|
|
|
buf.writeBlockPos(this.position);
|
|
|
|
buf.writeByte(this.placedBlockDirection);
|
|
|
|
buf.writeItemStackToBuffer(this.stack);
|
|
|
|
buf.writeByte((int)(this.facingX * 16.0F));
|
|
|
|
buf.writeByte((int)(this.facingY * 16.0F));
|
|
|
|
buf.writeByte((int)(this.facingZ * 16.0F));
|
|
|
|
}
|
|
|
|
|
2025-03-26 12:22:32 +01:00
|
|
|
public void processPacket(Player handler)
|
2025-03-11 00:23:54 +01:00
|
|
|
{
|
|
|
|
handler.processPlace(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockPos getPosition()
|
|
|
|
{
|
|
|
|
return this.position;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPlacedBlockDirection()
|
|
|
|
{
|
|
|
|
return this.placedBlockDirection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack getStack()
|
|
|
|
{
|
|
|
|
return this.stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getPlacedBlockOffsetX()
|
|
|
|
{
|
|
|
|
return this.facingX;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getPlacedBlockOffsetY()
|
|
|
|
{
|
|
|
|
return this.facingY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getPlacedBlockOffsetZ()
|
|
|
|
{
|
|
|
|
return this.facingZ;
|
|
|
|
}
|
|
|
|
}
|