mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-25 18:47:40 +01:00
Fully functional inventory clicks
This commit is contained in:
parent
4c25a61720
commit
68d8513e1a
@ -50,28 +50,6 @@ public class BoundingBox {
|
||||
return checkX && checkY && checkZ;
|
||||
}
|
||||
|
||||
|
||||
/*public boolean intersect(BlockPosition blockPosition) {
|
||||
final float x = 1.6f;
|
||||
final float y = 1;
|
||||
final float z = 1.6f;
|
||||
float minX = blockPosition.getX();
|
||||
float maxX = blockPosition.getX() +x;
|
||||
|
||||
float minY = blockPosition.getY();
|
||||
float maxY = blockPosition.getY() + y;
|
||||
|
||||
float minZ = blockPosition.getZ();
|
||||
float maxZ = blockPosition.getZ() +z;
|
||||
|
||||
boolean checkX = getMinX() + x / 2 < maxX && getMaxX() - x / 2 > minX;
|
||||
boolean checkY = getMinY() + y < maxY && getMaxY() + y > minY;
|
||||
boolean checkZ = getMinZ() + z / 2 < maxZ && getMaxZ() - z / 2 > minZ;
|
||||
|
||||
System.out.println("test: "+checkX+" : "+checkY+" : "+checkZ);
|
||||
return checkX && checkY && checkZ;
|
||||
}*/
|
||||
|
||||
public boolean intersect(float x, float y, float z) {
|
||||
return (x >= getMinX() && x <= getMaxX()) &&
|
||||
(y >= getMinY() && y <= getMaxY()) &&
|
||||
|
@ -231,8 +231,6 @@ public abstract class Entity implements Viewable, DataContainer {
|
||||
boolean yIntersect = boundingBox.intersect(yBlock);
|
||||
boolean zIntersect = boundingBox.intersect(zBlock);
|
||||
|
||||
System.out.println(xIntersect + " : " + yIntersect + " : " + zIntersect);
|
||||
System.out.println(yBlock);
|
||||
newX = xAir ? newX : xIntersect ? position.getX() : newX;
|
||||
newY = yAir ? newY : yIntersect ? position.getY() : newY;
|
||||
newZ = zAir ? newZ : zIntersect ? position.getZ() : newZ;
|
||||
|
@ -206,15 +206,27 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
|
||||
// Player inventory loop
|
||||
new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE, 1,
|
||||
i -> playerInventory.convertToPacketSlot(i),
|
||||
index -> playerInventory.getItemStack(index, offset),
|
||||
(index, itemStack) -> playerInventory.setItemStack(index, offset, itemStack)));
|
||||
index -> isClickInWindow(index) ? getItemStack(index) : playerInventory.getItemStack(index, offset),
|
||||
(index, itemStack) -> {
|
||||
if (isClickInWindow(index)) {
|
||||
setItemStack(index, itemStack);
|
||||
} else {
|
||||
playerInventory.setItemStack(index, offset, itemStack);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor,
|
||||
// Window loop
|
||||
new InventoryClickLoopHandler(0, itemStacks.length, 1,
|
||||
i -> i,
|
||||
index -> itemStacks[index],
|
||||
(index, itemStack) -> setItemStack(index, itemStack)));
|
||||
index -> isClickInWindow(index) ? getItemStack(index) : playerInventory.getItemStack(index, offset),
|
||||
(index, itemStack) -> {
|
||||
if (isClickInWindow(index)) {
|
||||
setItemStack(index, itemStack);
|
||||
} else {
|
||||
playerInventory.setItemStack(index, offset, itemStack);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
if (clickResult == null)
|
||||
|
@ -326,9 +326,16 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
|
||||
ItemStack cursor = getCursorItem();
|
||||
ItemStack clicked = getItemStack(slot, OFFSET);
|
||||
|
||||
boolean slotClick = convertToPacketSlot(slot) < 9;
|
||||
InventoryClickResult clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor,
|
||||
new InventoryClickLoopHandler(0, items.length, 1,
|
||||
i -> i < 9 ? i + 9 : i - 9,
|
||||
i -> {
|
||||
if (slotClick) {
|
||||
return i < 9 ? i + 9 : i - 9;
|
||||
} else {
|
||||
return convertSlot(i, OFFSET);
|
||||
}
|
||||
},
|
||||
index -> items[index],
|
||||
(index, itemStack) -> setItemStack(index, OFFSET, itemStack)));
|
||||
|
||||
|
@ -185,6 +185,11 @@ public class InventoryClickProcessor {
|
||||
ItemStack item = itemGetter.apply(index);
|
||||
StackingRule itemRule = item.getStackingRule();
|
||||
if (itemRule.canBeStacked(item, clicked)) {
|
||||
|
||||
clickResult = startCondition(clickResult, inventoryCondition, player, index, item, cursor);
|
||||
if (clickResult.isCancel())
|
||||
continue;
|
||||
|
||||
int amount = itemRule.getAmount(item);
|
||||
if (!clickedRule.canApply(clicked, amount + 1))
|
||||
continue;
|
||||
@ -206,6 +211,11 @@ public class InventoryClickProcessor {
|
||||
break;
|
||||
}
|
||||
} else if (item.isAir()) {
|
||||
|
||||
clickResult = startCondition(clickResult, inventoryCondition, player, index, item, cursor);
|
||||
if (clickResult.isCancel())
|
||||
continue;
|
||||
|
||||
// Switch
|
||||
itemSetter.accept(index, resultClicked);
|
||||
itemSetter.accept(slot, ItemStack.AIR_ITEM);
|
||||
|
Loading…
Reference in New Issue
Block a user