improve protocol

This commit is contained in:
Sen 2025-07-05 14:46:56 +02:00
parent 0c7459d371
commit eed9ea565f
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
3 changed files with 114 additions and 99 deletions

View file

@ -245,14 +245,16 @@ public class Item {
return false;
}
public final boolean isValidTag(TagObject tag) {
if(this.validTags == null)
return false;
for(TagObject valid : this.validTags) {
if(valid.equals(tag))
return true;
}
return false;
public final boolean hasTags() {
return this.validTags != null;
}
public final TagObject getItemTag(int index) {
return this.validTags == null || index < 0 || index >= this.validTags.size() ? null : this.validTags.get(index);
}
public final int getTagIndex(TagObject tag) {
return tag == null || this.validTags == null ? -1 : this.validTags.indexOf(tag);
}
public float getRadiation(ItemStack stack) {

View file

@ -2,51 +2,60 @@ package common.packet;
import java.io.IOException;
import common.init.ItemRegistry;
import common.item.Item;
import common.item.ItemStack;
import common.network.IPlayer;
import common.network.Packet;
import common.network.PacketBuffer;
public class CPacketCheat implements Packet<IPlayer>
{
private ItemStack stack;
private int slot;
public class CPacketCheat implements Packet<IPlayer> {
private Item item;
private int tagIndex;
private int slot;
private boolean stacked;
public CPacketCheat()
{
}
public CPacketCheat() {
}
public CPacketCheat(ItemStack stackIn, int slot, boolean full)
{
this.stack = stackIn.copy();
this.slot = slot;
this.stack.size = full ? this.stack.getMaxStackSize() : 1;
}
public void processPacket(IPlayer handler)
{
handler.processCheat(this);
}
public void readPacketData(PacketBuffer buf) throws IOException
{
this.stack = buf.readItemStack();
this.slot = buf.readByte();
}
public void writePacketData(PacketBuffer buf) throws IOException
{
buf.writeItemStack(this.stack);
buf.writeByte(this.slot);
}
public CPacketCheat(ItemStack stack, int slot, boolean full) {
this.item = stack.getItem();
this.tagIndex = this.item.getTagIndex(stack.getTag());
this.slot = slot;
this.stacked = full;
}
public ItemStack getStack()
{
return this.stack;
}
public void processPacket(IPlayer handler) {
handler.processCheat(this);
}
public int getSlot()
{
return this.slot;
}
public void readPacketData(PacketBuffer buf) throws IOException {
this.item = ItemRegistry.byId(buf.readShort());
this.tagIndex = buf.readVarInt();
this.slot = buf.readShort();
this.stacked = buf.readBoolean();
}
public void writePacketData(PacketBuffer buf) throws IOException {
buf.writeShort(ItemRegistry.getId(this.item));
buf.writeVarInt(this.tagIndex);
buf.writeShort(this.slot);
buf.writeBoolean(this.stacked);
}
public Item getItem() {
return this.item;
}
public int getTagIndex() {
return this.tagIndex;
}
public boolean isStacked() {
return this.stacked;
}
public int getSlot() {
return this.slot;
}
}