Small inventory fixes (#1029)

* Increase minimum delay between closing and opening a new window

* Fix potential crash when opening player inventory
This commit is contained in:
AJ Ferguson 2020-07-27 07:17:55 -08:00 committed by GitHub
parent d316d3a5a8
commit b9846fe797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -135,12 +135,15 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
}
break;
case OPEN_INVENTORY:
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) 0);
containerOpenPacket.setType(ContainerType.INVENTORY);
containerOpenPacket.setUniqueEntityId(-1);
containerOpenPacket.setBlockPosition(entity.getPosition().toInt());
session.sendUpstreamPacket(containerOpenPacket);
if (!session.getInventory().isOpen()) {
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
containerOpenPacket.setId((byte) 0);
containerOpenPacket.setType(ContainerType.INVENTORY);
containerOpenPacket.setUniqueEntityId(-1);
containerOpenPacket.setBlockPosition(entity.getPosition().toInt());
session.sendUpstreamPacket(containerOpenPacket);
session.getInventory().setOpen(true);
}
break;
}
}

View File

@ -56,7 +56,7 @@ public class InventoryUtils {
translator.prepareInventory(session, inventory);
//Ensure at least half a second passes between closing and opening a new window
//The client will not open the new window if it is still closing the old one
long delay = 500 - (System.currentTimeMillis() - session.getLastWindowCloseTime());
long delay = 700 - (System.currentTimeMillis() - session.getLastWindowCloseTime());
//TODO: find better way to handle double chest delay
if (translator instanceof DoubleChestInventoryTranslator) {
delay = Math.max(delay, 200);
@ -87,6 +87,7 @@ public class InventoryUtils {
}
} else {
Inventory inventory = session.getInventory();
inventory.setOpen(false);
InventoryTranslator translator = InventoryTranslator.INVENTORY_TRANSLATORS.get(inventory.getWindowType());
translator.updateInventory(session, inventory);
}