improve protocol
This commit is contained in:
parent
0c7459d371
commit
eed9ea565f
3 changed files with 114 additions and 99 deletions
|
@ -41,6 +41,7 @@ import common.inventory.IInventory;
|
|||
import common.inventory.InventoryPlayer;
|
||||
import common.inventory.Slot;
|
||||
import common.inventory.SlotCrafting;
|
||||
import common.item.Item;
|
||||
import common.item.ItemControl;
|
||||
import common.item.ItemStack;
|
||||
import common.log.Log;
|
||||
|
@ -2876,61 +2877,64 @@ public class Player extends User implements ICrafting, Executor, IPlayer
|
|||
NetHandler.checkThread(packet, this, this.server);
|
||||
if(this.charEditor || !this.isAdmin())
|
||||
return;
|
||||
ItemStack stack = packet.getStack();
|
||||
if(stack.getItem() != null && stack.size <= stack.getMaxStackSize() && stack.size > 0 && (!stack.hasTag() || stack.getItem().isValidTag(stack.getTag())))
|
||||
{
|
||||
int amount = stack.size;
|
||||
Item item = packet.getItem();
|
||||
if(item == null)
|
||||
return;
|
||||
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)
|
||||
return;
|
||||
if(packet.getSlot() == -1) {
|
||||
this.entity.inventory.addItemStackToInventory(stack);
|
||||
amount -= stack.size;
|
||||
if(amount <= 0)
|
||||
return;
|
||||
}
|
||||
else if(packet.getSlot() <= -2 - 9) {
|
||||
this.entity.dropItem(stack, false, true);
|
||||
}
|
||||
else {
|
||||
Slot slot = packet.getSlot() < 0 ? this.entity.inventoryContainer.getSlot(36 + -2 - packet.getSlot()) : this.entity.openContainer.getSlot(packet.getSlot());
|
||||
if(slot == null || !slot.canCheatItem())
|
||||
return;
|
||||
stack.size = Math.min(slot.getSlotStackLimit(), stack.size);
|
||||
amount = stack.size;
|
||||
if(amount <= 0)
|
||||
return;
|
||||
if(slot.getHasStack()) {
|
||||
ItemStack old = slot.getStack();
|
||||
if(ItemStack.areItemsEqual(stack, old) && ItemStack.areItemStackTagsEqual(stack, old)) {
|
||||
stack.size = Math.min(slot.getSlotStackLimit(), Math.min(stack.getMaxStackSize(), old.size + stack.size));
|
||||
amount = stack.size - old.size;
|
||||
if(amount <= 0 || !slot.isItemValid(stack))
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if(!slot.isItemValid(stack))
|
||||
return;
|
||||
if(old.size == 1)
|
||||
this.addFeed(TextColor.DRED + "* %s zerstört",
|
||||
old.getColoredName(TextColor.DRED));
|
||||
else
|
||||
this.addFeed(TextColor.DRED + "* %d %s zerstört", old.size,
|
||||
old.getColoredName(TextColor.DRED));
|
||||
}
|
||||
}
|
||||
else if(!slot.isItemValid(stack))
|
||||
return;
|
||||
slot.putStack(stack);
|
||||
}
|
||||
this.entity.openContainer.detectAndSendChanges();
|
||||
this.entity.worldObj.playSoundAtEntity(this.entity, SoundEvent.POP, 0.2F);
|
||||
if(amount == 1)
|
||||
this.addFeed(TextColor.DGREEN + "* %s geschummelt",
|
||||
stack.getColoredName(TextColor.DGREEN));
|
||||
else
|
||||
this.addFeed(TextColor.DGREEN + "* %d %s geschummelt", amount,
|
||||
stack.getColoredName(TextColor.DGREEN));
|
||||
}
|
||||
}
|
||||
else if(packet.getSlot() <= -2 - 9) {
|
||||
this.entity.dropItem(stack, false, true);
|
||||
}
|
||||
else {
|
||||
Slot slot = packet.getSlot() < 0 ? this.entity.inventoryContainer.getSlot(36 + -2 - packet.getSlot()) : this.entity.openContainer.getSlot(packet.getSlot());
|
||||
if(slot == null || !slot.canCheatItem())
|
||||
return;
|
||||
stack.size = Math.min(slot.getSlotStackLimit(), stack.size);
|
||||
amount = stack.size;
|
||||
if(amount <= 0)
|
||||
return;
|
||||
if(slot.getHasStack()) {
|
||||
ItemStack old = slot.getStack();
|
||||
if(ItemStack.areItemsEqual(stack, old) && ItemStack.areItemStackTagsEqual(stack, old)) {
|
||||
stack.size = Math.min(slot.getSlotStackLimit(), Math.min(stack.getMaxStackSize(), old.size + stack.size));
|
||||
amount = stack.size - old.size;
|
||||
if(amount <= 0 || !slot.isItemValid(stack))
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if(!slot.isItemValid(stack))
|
||||
return;
|
||||
if(old.size == 1)
|
||||
this.addFeed(TextColor.DRED + "* %s zerstört",
|
||||
old.getColoredName(TextColor.DRED));
|
||||
else
|
||||
this.addFeed(TextColor.DRED + "* %d %s zerstört", old.size,
|
||||
old.getColoredName(TextColor.DRED));
|
||||
}
|
||||
}
|
||||
else if(!slot.isItemValid(stack))
|
||||
return;
|
||||
slot.putStack(stack);
|
||||
}
|
||||
this.entity.openContainer.detectAndSendChanges();
|
||||
this.entity.worldObj.playSoundAtEntity(this.entity, SoundEvent.POP, 0.2F);
|
||||
if(amount == 1)
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue