improve protocol
This commit is contained in:
parent
0c7459d371
commit
eed9ea565f
3 changed files with 114 additions and 99 deletions
|
@ -245,14 +245,16 @@ public class Item {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isValidTag(TagObject tag) {
|
public final boolean hasTags() {
|
||||||
if(this.validTags == null)
|
return this.validTags != null;
|
||||||
return false;
|
}
|
||||||
for(TagObject valid : this.validTags) {
|
|
||||||
if(valid.equals(tag))
|
public final TagObject getItemTag(int index) {
|
||||||
return true;
|
return this.validTags == null || index < 0 || index >= this.validTags.size() ? null : this.validTags.get(index);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
public final int getTagIndex(TagObject tag) {
|
||||||
|
return tag == null || this.validTags == null ? -1 : this.validTags.indexOf(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getRadiation(ItemStack stack) {
|
public float getRadiation(ItemStack stack) {
|
||||||
|
|
|
@ -2,51 +2,60 @@ package common.packet;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import common.init.ItemRegistry;
|
||||||
|
import common.item.Item;
|
||||||
import common.item.ItemStack;
|
import common.item.ItemStack;
|
||||||
import common.network.IPlayer;
|
import common.network.IPlayer;
|
||||||
import common.network.Packet;
|
import common.network.Packet;
|
||||||
import common.network.PacketBuffer;
|
import common.network.PacketBuffer;
|
||||||
|
|
||||||
public class CPacketCheat implements Packet<IPlayer>
|
public class CPacketCheat implements Packet<IPlayer> {
|
||||||
{
|
private Item item;
|
||||||
private ItemStack stack;
|
private int tagIndex;
|
||||||
private int slot;
|
private int slot;
|
||||||
|
private boolean stacked;
|
||||||
|
|
||||||
public CPacketCheat()
|
public CPacketCheat() {
|
||||||
{
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public CPacketCheat(ItemStack stackIn, int slot, boolean full)
|
public CPacketCheat(ItemStack stack, int slot, boolean full) {
|
||||||
{
|
this.item = stack.getItem();
|
||||||
this.stack = stackIn.copy();
|
this.tagIndex = this.item.getTagIndex(stack.getTag());
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
this.stack.size = full ? this.stack.getMaxStackSize() : 1;
|
this.stacked = full;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processPacket(IPlayer handler)
|
public void processPacket(IPlayer handler) {
|
||||||
{
|
handler.processCheat(this);
|
||||||
handler.processCheat(this);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void readPacketData(PacketBuffer buf) throws IOException
|
public void readPacketData(PacketBuffer buf) throws IOException {
|
||||||
{
|
this.item = ItemRegistry.byId(buf.readShort());
|
||||||
this.stack = buf.readItemStack();
|
this.tagIndex = buf.readVarInt();
|
||||||
this.slot = buf.readByte();
|
this.slot = buf.readShort();
|
||||||
}
|
this.stacked = buf.readBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
public void writePacketData(PacketBuffer buf) throws IOException
|
public void writePacketData(PacketBuffer buf) throws IOException {
|
||||||
{
|
buf.writeShort(ItemRegistry.getId(this.item));
|
||||||
buf.writeItemStack(this.stack);
|
buf.writeVarInt(this.tagIndex);
|
||||||
buf.writeByte(this.slot);
|
buf.writeShort(this.slot);
|
||||||
}
|
buf.writeBoolean(this.stacked);
|
||||||
|
}
|
||||||
|
|
||||||
public ItemStack getStack()
|
public Item getItem() {
|
||||||
{
|
return this.item;
|
||||||
return this.stack;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public int getSlot()
|
public int getTagIndex() {
|
||||||
{
|
return this.tagIndex;
|
||||||
return this.slot;
|
}
|
||||||
}
|
|
||||||
|
public boolean isStacked() {
|
||||||
|
return this.stacked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSlot() {
|
||||||
|
return this.slot;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import common.inventory.IInventory;
|
||||||
import common.inventory.InventoryPlayer;
|
import common.inventory.InventoryPlayer;
|
||||||
import common.inventory.Slot;
|
import common.inventory.Slot;
|
||||||
import common.inventory.SlotCrafting;
|
import common.inventory.SlotCrafting;
|
||||||
|
import common.item.Item;
|
||||||
import common.item.ItemControl;
|
import common.item.ItemControl;
|
||||||
import common.item.ItemStack;
|
import common.item.ItemStack;
|
||||||
import common.log.Log;
|
import common.log.Log;
|
||||||
|
@ -2876,61 +2877,64 @@ public class Player extends User implements ICrafting, Executor, IPlayer
|
||||||
NetHandler.checkThread(packet, this, this.server);
|
NetHandler.checkThread(packet, this, this.server);
|
||||||
if(this.charEditor || !this.isAdmin())
|
if(this.charEditor || !this.isAdmin())
|
||||||
return;
|
return;
|
||||||
ItemStack stack = packet.getStack();
|
Item item = packet.getItem();
|
||||||
if(stack.getItem() != null && stack.size <= stack.getMaxStackSize() && stack.size > 0 && (!stack.hasTag() || stack.getItem().isValidTag(stack.getTag())))
|
if(item == null)
|
||||||
{
|
return;
|
||||||
int amount = stack.size;
|
ItemStack stack = new ItemStack(item, packet.isStacked() ? item.getItemStackLimit() : 1);
|
||||||
|
stack.setTag(item.getItemTag(packet.getTagIndex()));
|
||||||
|
if(item.hasTags() != stack.hasTag())
|
||||||
|
return;
|
||||||
|
int amount = stack.size;
|
||||||
|
if(amount <= 0)
|
||||||
|
return;
|
||||||
|
if(packet.getSlot() == -1) {
|
||||||
|
this.entity.inventory.addItemStackToInventory(stack);
|
||||||
|
amount -= stack.size;
|
||||||
if(amount <= 0)
|
if(amount <= 0)
|
||||||
return;
|
return;
|
||||||
if(packet.getSlot() == -1) {
|
}
|
||||||
this.entity.inventory.addItemStackToInventory(stack);
|
else if(packet.getSlot() <= -2 - 9) {
|
||||||
amount -= stack.size;
|
this.entity.dropItem(stack, false, true);
|
||||||
if(amount <= 0)
|
}
|
||||||
return;
|
else {
|
||||||
}
|
Slot slot = packet.getSlot() < 0 ? this.entity.inventoryContainer.getSlot(36 + -2 - packet.getSlot()) : this.entity.openContainer.getSlot(packet.getSlot());
|
||||||
else if(packet.getSlot() <= -2 - 9) {
|
if(slot == null || !slot.canCheatItem())
|
||||||
this.entity.dropItem(stack, false, true);
|
return;
|
||||||
}
|
stack.size = Math.min(slot.getSlotStackLimit(), stack.size);
|
||||||
else {
|
amount = stack.size;
|
||||||
Slot slot = packet.getSlot() < 0 ? this.entity.inventoryContainer.getSlot(36 + -2 - packet.getSlot()) : this.entity.openContainer.getSlot(packet.getSlot());
|
if(amount <= 0)
|
||||||
if(slot == null || !slot.canCheatItem())
|
return;
|
||||||
return;
|
if(slot.getHasStack()) {
|
||||||
stack.size = Math.min(slot.getSlotStackLimit(), stack.size);
|
ItemStack old = slot.getStack();
|
||||||
amount = stack.size;
|
if(ItemStack.areItemsEqual(stack, old) && ItemStack.areItemStackTagsEqual(stack, old)) {
|
||||||
if(amount <= 0)
|
stack.size = Math.min(slot.getSlotStackLimit(), Math.min(stack.getMaxStackSize(), old.size + stack.size));
|
||||||
return;
|
amount = stack.size - old.size;
|
||||||
if(slot.getHasStack()) {
|
if(amount <= 0 || !slot.isItemValid(stack))
|
||||||
ItemStack old = slot.getStack();
|
return;
|
||||||
if(ItemStack.areItemsEqual(stack, old) && ItemStack.areItemStackTagsEqual(stack, old)) {
|
}
|
||||||
stack.size = Math.min(slot.getSlotStackLimit(), Math.min(stack.getMaxStackSize(), old.size + stack.size));
|
else {
|
||||||
amount = stack.size - old.size;
|
if(!slot.isItemValid(stack))
|
||||||
if(amount <= 0 || !slot.isItemValid(stack))
|
return;
|
||||||
return;
|
if(old.size == 1)
|
||||||
}
|
this.addFeed(TextColor.DRED + "* %s zerstört",
|
||||||
else {
|
old.getColoredName(TextColor.DRED));
|
||||||
if(!slot.isItemValid(stack))
|
else
|
||||||
return;
|
this.addFeed(TextColor.DRED + "* %d %s zerstört", old.size,
|
||||||
if(old.size == 1)
|
old.getColoredName(TextColor.DRED));
|
||||||
this.addFeed(TextColor.DRED + "* %s zerstört",
|
}
|
||||||
old.getColoredName(TextColor.DRED));
|
}
|
||||||
else
|
else if(!slot.isItemValid(stack))
|
||||||
this.addFeed(TextColor.DRED + "* %d %s zerstört", old.size,
|
return;
|
||||||
old.getColoredName(TextColor.DRED));
|
slot.putStack(stack);
|
||||||
}
|
}
|
||||||
}
|
this.entity.openContainer.detectAndSendChanges();
|
||||||
else if(!slot.isItemValid(stack))
|
this.entity.worldObj.playSoundAtEntity(this.entity, SoundEvent.POP, 0.2F);
|
||||||
return;
|
if(amount == 1)
|
||||||
slot.putStack(stack);
|
this.addFeed(TextColor.DGREEN + "* %s geschummelt",
|
||||||
}
|
stack.getColoredName(TextColor.DGREEN));
|
||||||
this.entity.openContainer.detectAndSendChanges();
|
else
|
||||||
this.entity.worldObj.playSoundAtEntity(this.entity, SoundEvent.POP, 0.2F);
|
this.addFeed(TextColor.DGREEN + "* %d %s geschummelt", amount,
|
||||||
if(amount == 1)
|
stack.getColoredName(TextColor.DGREEN));
|
||||||
this.addFeed(TextColor.DGREEN + "* %s geschummelt",
|
|
||||||
stack.getColoredName(TextColor.DGREEN));
|
|
||||||
else
|
|
||||||
this.addFeed(TextColor.DGREEN + "* %d %s geschummelt", amount,
|
|
||||||
stack.getColoredName(TextColor.DGREEN));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processSign(CPacketSign packetIn)
|
public void processSign(CPacketSign packetIn)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue