Skip to content

Commit

Permalink
More cartography parity fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Mar 10, 2021
1 parent 370f3c1 commit e493415
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,28 @@ public ItemStackResponsePacket.Response translateRequest(GeyserSession session,
if (inventory instanceof CartographyContainer) {
// TODO add this for more inventories? Only seems to glitch out the cartography table, though.
ConsumeStackRequestActionData consumeData = (ConsumeStackRequestActionData) action;

int sourceSlot = bedrockSlotToJava(consumeData.getSource());
if (sourceSlot == 0 && inventory.getItem(1).isEmpty()) {
// Java doesn't allow an item to be renamed; this is why CARTOGRAPHY_ADDITIONAL could remain empty for Bedrock
// We check this during slot 0 since setting the inventory slots here messes up shouldRejectItemPlace
if ((sourceSlot == 0 && inventory.getItem(1).isEmpty()) || (sourceSlot == 1 && inventory.getItem(0).isEmpty())) {
// Java doesn't allow an item to be renamed; this is why one of the slots could remain empty for Bedrock
// We check this now since setting the inventory slots here messes up shouldRejectItemPlace
return rejectRequest(request, false);
}

GeyserItemStack item = inventory.getItem(sourceSlot);
item.setAmount(item.getAmount() - consumeData.getCount());
if (item.isEmpty()) {
inventory.setItem(sourceSlot, GeyserItemStack.EMPTY, session);
if (sourceSlot == 1) {
// Decrease the item count, but only after both slots are checked.
// Otherwise, the slot 1 check will fail
GeyserItemStack item = inventory.getItem(sourceSlot);
item.setAmount(item.getAmount() - consumeData.getCount());
if (item.isEmpty()) {
inventory.setItem(sourceSlot, GeyserItemStack.EMPTY, session);
}

GeyserItemStack itemZero = inventory.getItem(0);
itemZero.setAmount(itemZero.getAmount() - consumeData.getCount());
if (itemZero.isEmpty()) {
inventory.setItem(0, GeyserItemStack.EMPTY, session);
}
}
affectedSlots.add(sourceSlot);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public CartographyInventoryTranslator() {
public boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, ContainerSlotType bedrockSourceContainer,
int javaSourceSlot, ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot) {
if (javaDestinationSlot == 0) {
// Bedrock Edition can use paper in slot 0
// Bedrock Edition can use paper or an empty map in slot 0
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:paper");
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:paper") || itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:map");
} else if (javaDestinationSlot == 1) {
// Bedrock Edition can use a compass to create locator maps in the ADDITIONAL slot
// Bedrock Edition can use a compass to create locator maps, or use a filled map, in the ADDITIONAL slot
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : inventory.getItem(javaSourceSlot);
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:compass");
return itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:compass") || itemStack.getItemEntry().getJavaIdentifier().equals("minecraft:filled_map");
}
return false;
}
Expand Down

0 comments on commit e493415

Please sign in to comment.