mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 09:01:54 +01:00
Update
This commit is contained in:
parent
3940927b5e
commit
d53cb49648
@ -161,7 +161,7 @@ public class PlayerInit {
|
||||
|
||||
Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
||||
inventory.setInventoryCondition((p, slot, inventoryConditionResult) -> {
|
||||
inventoryConditionResult.setCancel(true);
|
||||
inventoryConditionResult.setCancel(false);
|
||||
});
|
||||
inventory.setItemStack(0, item.clone());
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
package fr.themode.minestom.event;
|
||||
|
||||
import fr.themode.minestom.item.ItemStack;
|
||||
|
||||
public class PlayerSwapItemEvent extends CancellableEvent {
|
||||
|
||||
private ItemStack mainHandItem;
|
||||
private ItemStack offHandItem;
|
||||
|
||||
public PlayerSwapItemEvent(ItemStack mainHandItem, ItemStack offHandItem) {
|
||||
this.mainHandItem = mainHandItem;
|
||||
this.offHandItem = offHandItem;
|
||||
}
|
||||
|
||||
public ItemStack getMainHandItem() {
|
||||
return mainHandItem;
|
||||
}
|
||||
|
||||
public void setMainHandItem(ItemStack mainHandItem) {
|
||||
this.mainHandItem = mainHandItem;
|
||||
}
|
||||
|
||||
public ItemStack getOffHandItem() {
|
||||
return offHandItem;
|
||||
}
|
||||
|
||||
public void setOffHandItem(ItemStack offHandItem) {
|
||||
this.offHandItem = offHandItem;
|
||||
}
|
||||
}
|
@ -162,8 +162,6 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
if (clickResult.doRefresh())
|
||||
player.getPlayerConnection().sendPacket(getWindowItemsPacket());
|
||||
|
||||
System.out.println("cancel:" + clickResult.isCancel());
|
||||
|
||||
if (isInWindow) {
|
||||
setItemStack(slot, clickResult.getClicked());
|
||||
setCursorPlayerItem(player, clickResult.getCursor());
|
||||
|
@ -66,14 +66,12 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
for (int i = 0; i < items.length - 10; i++) {
|
||||
ItemStack item = items[i];
|
||||
StackingRule itemStackingRule = item.getStackingRule();
|
||||
if (item.isAir()) {
|
||||
setItemStack(i, itemStack);
|
||||
return true;
|
||||
} else if (itemStack.isSimilar(item)) {
|
||||
int itemAmount = item.getAmount();
|
||||
if (itemStackingRule.canBeStacked(itemStack, item)) {
|
||||
int itemAmount = itemStackingRule.getAmount(item);
|
||||
if (itemAmount == stackingRule.getMaxSize())
|
||||
continue;
|
||||
int totalAmount = itemStack.getAmount() + itemAmount;
|
||||
int itemStackAmount = itemStackingRule.getAmount(itemStack);
|
||||
int totalAmount = itemStackAmount + itemAmount;
|
||||
if (!stackingRule.canApply(itemStack, totalAmount)) {
|
||||
item = itemStackingRule.apply(item, itemStackingRule.getMaxSize());
|
||||
|
||||
@ -84,6 +82,9 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
sendSlotRefresh((short) convertToPacketSlot(i), item);
|
||||
return true;
|
||||
}
|
||||
} else if (item.isAir()) {
|
||||
setItemStack(i, itemStack);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,6 +274,7 @@ public class InventoryClickProcessor {
|
||||
cursor = result.getCursorItem();
|
||||
clicked = result.getClickedItem();
|
||||
|
||||
clickResult.setCancel(result.isCancel());
|
||||
if (result.isCancel()) {
|
||||
clickResult.setClicked(clicked);
|
||||
clickResult.setCursor(cursor);
|
||||
|
@ -5,6 +5,7 @@ import fr.themode.minestom.entity.ItemEntity;
|
||||
import fr.themode.minestom.entity.Player;
|
||||
import fr.themode.minestom.event.ItemDropEvent;
|
||||
import fr.themode.minestom.event.PlayerStartDiggingEvent;
|
||||
import fr.themode.minestom.event.PlayerSwapItemEvent;
|
||||
import fr.themode.minestom.instance.Instance;
|
||||
import fr.themode.minestom.instance.block.CustomBlock;
|
||||
import fr.themode.minestom.inventory.PlayerInventory;
|
||||
@ -88,8 +89,11 @@ public class PlayerDiggingListener {
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack mainHand = playerInventory.getItemInMainHand().clone();
|
||||
ItemStack offHand = playerInventory.getItemInOffHand().clone();
|
||||
playerInventory.setItemInMainHand(offHand);
|
||||
playerInventory.setItemInOffHand(mainHand);
|
||||
PlayerSwapItemEvent swapItemEvent = new PlayerSwapItemEvent(offHand, mainHand);
|
||||
player.callCancellableEvent(PlayerSwapItemEvent.class, swapItemEvent, () -> {
|
||||
playerInventory.setItemInMainHand(swapItemEvent.getMainHandItem());
|
||||
playerInventory.setItemInOffHand(swapItemEvent.getOffHandItem());
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class ClientPacketsHandler {
|
||||
}
|
||||
|
||||
public ClientPacket getPacketInstance(int id) {
|
||||
// System.out.println("RECEIVED PACKET 0x" + Integer.toHexString(id));
|
||||
//System.out.println("RECEIVED PACKET 0x" + Integer.toHexString(id));
|
||||
if (id > SIZE)
|
||||
throw new IllegalStateException("Packet ID 0x" + Integer.toHexString(id) + " has been tried to be parsed, debug needed");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user