Fully functional inventory clicks

This commit is contained in:
Felix Cravic 2020-04-20 20:57:04 +02:00
parent 4c25a61720
commit 68d8513e1a
5 changed files with 34 additions and 29 deletions

View File

@ -50,28 +50,6 @@ public class BoundingBox {
return checkX && checkY && checkZ; 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) { public boolean intersect(float x, float y, float z) {
return (x >= getMinX() && x <= getMaxX()) && return (x >= getMinX() && x <= getMaxX()) &&
(y >= getMinY() && y <= getMaxY()) && (y >= getMinY() && y <= getMaxY()) &&

View File

@ -231,8 +231,6 @@ public abstract class Entity implements Viewable, DataContainer {
boolean yIntersect = boundingBox.intersect(yBlock); boolean yIntersect = boundingBox.intersect(yBlock);
boolean zIntersect = boundingBox.intersect(zBlock); boolean zIntersect = boundingBox.intersect(zBlock);
System.out.println(xIntersect + " : " + yIntersect + " : " + zIntersect);
System.out.println(yBlock);
newX = xAir ? newX : xIntersect ? position.getX() : newX; newX = xAir ? newX : xIntersect ? position.getX() : newX;
newY = yAir ? newY : yIntersect ? position.getY() : newY; newY = yAir ? newY : yIntersect ? position.getY() : newY;
newZ = zAir ? newZ : zIntersect ? position.getZ() : newZ; newZ = zAir ? newZ : zIntersect ? position.getZ() : newZ;

View File

@ -206,15 +206,27 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
// Player inventory loop // Player inventory loop
new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE, 1, new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE, 1,
i -> playerInventory.convertToPacketSlot(i), i -> playerInventory.convertToPacketSlot(i),
index -> playerInventory.getItemStack(index, offset), index -> isClickInWindow(index) ? getItemStack(index) : playerInventory.getItemStack(index, offset),
(index, itemStack) -> playerInventory.setItemStack(index, offset, itemStack))); (index, itemStack) -> {
if (isClickInWindow(index)) {
setItemStack(index, itemStack);
} else {
playerInventory.setItemStack(index, offset, itemStack);
}
}));
} else { } else {
clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor, clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor,
// Window loop // Window loop
new InventoryClickLoopHandler(0, itemStacks.length, 1, new InventoryClickLoopHandler(0, itemStacks.length, 1,
i -> i, i -> i,
index -> itemStacks[index], index -> isClickInWindow(index) ? getItemStack(index) : playerInventory.getItemStack(index, offset),
(index, itemStack) -> setItemStack(index, itemStack))); (index, itemStack) -> {
if (isClickInWindow(index)) {
setItemStack(index, itemStack);
} else {
playerInventory.setItemStack(index, offset, itemStack);
}
}));
} }
if (clickResult == null) if (clickResult == null)

View File

@ -326,9 +326,16 @@ public class PlayerInventory implements InventoryModifier, InventoryClickHandler
ItemStack cursor = getCursorItem(); ItemStack cursor = getCursorItem();
ItemStack clicked = getItemStack(slot, OFFSET); ItemStack clicked = getItemStack(slot, OFFSET);
boolean slotClick = convertToPacketSlot(slot) < 9;
InventoryClickResult clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor, InventoryClickResult clickResult = clickProcessor.shiftClick(getInventoryCondition(), player, slot, clicked, cursor,
new InventoryClickLoopHandler(0, items.length, 1, 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 -> items[index],
(index, itemStack) -> setItemStack(index, OFFSET, itemStack))); (index, itemStack) -> setItemStack(index, OFFSET, itemStack)));

View File

@ -185,6 +185,11 @@ public class InventoryClickProcessor {
ItemStack item = itemGetter.apply(index); ItemStack item = itemGetter.apply(index);
StackingRule itemRule = item.getStackingRule(); StackingRule itemRule = item.getStackingRule();
if (itemRule.canBeStacked(item, clicked)) { if (itemRule.canBeStacked(item, clicked)) {
clickResult = startCondition(clickResult, inventoryCondition, player, index, item, cursor);
if (clickResult.isCancel())
continue;
int amount = itemRule.getAmount(item); int amount = itemRule.getAmount(item);
if (!clickedRule.canApply(clicked, amount + 1)) if (!clickedRule.canApply(clicked, amount + 1))
continue; continue;
@ -206,6 +211,11 @@ public class InventoryClickProcessor {
break; break;
} }
} else if (item.isAir()) { } else if (item.isAir()) {
clickResult = startCondition(clickResult, inventoryCondition, player, index, item, cursor);
if (clickResult.isCancel())
continue;
// Switch // Switch
itemSetter.accept(index, resultClicked); itemSetter.accept(index, resultClicked);
itemSetter.accept(slot, ItemStack.AIR_ITEM); itemSetter.accept(slot, ItemStack.AIR_ITEM);