mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Update lectern if updated via the WindowItemsPacket
This commit is contained in:
parent
8510451dde
commit
a2b3e1946d
2 changed files with 65 additions and 55 deletions
|
@ -78,12 +78,24 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateInventory(GeyserSession session, Inventory inventory) {
|
public void updateInventory(GeyserSession session, Inventory inventory) {
|
||||||
|
GeyserItemStack itemStack = inventory.getItem(0);
|
||||||
|
if (!itemStack.isEmpty()) {
|
||||||
|
updateBook(session, inventory, itemStack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSlot(GeyserSession session, Inventory inventory, int slot) {
|
public void updateSlot(GeyserSession session, Inventory inventory, int slot) {
|
||||||
this.updater.updateSlot(this, session, inventory, slot);
|
this.updater.updateSlot(this, session, inventory, slot);
|
||||||
if (slot == 0) {
|
if (slot == 0) {
|
||||||
|
updateBook(session, inventory, inventory.getItem(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate the data of the book in the lectern into a block entity tag.
|
||||||
|
*/
|
||||||
|
private void updateBook(GeyserSession session, Inventory inventory, GeyserItemStack book) {
|
||||||
LecternContainer lecternContainer = (LecternContainer) inventory;
|
LecternContainer lecternContainer = (LecternContainer) inventory;
|
||||||
if (session.isDroppingLecternBook()) {
|
if (session.isDroppingLecternBook()) {
|
||||||
// We have to enter the inventory GUI to eject the book
|
// We have to enter the inventory GUI to eject the book
|
||||||
|
@ -92,18 +104,17 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
|
||||||
session.setDroppingLecternBook(false);
|
session.setDroppingLecternBook(false);
|
||||||
InventoryUtils.closeInventory(session, inventory.getId(), false);
|
InventoryUtils.closeInventory(session, inventory.getId(), false);
|
||||||
} else if (lecternContainer.getBlockEntityTag() == null) {
|
} else if (lecternContainer.getBlockEntityTag() == null) {
|
||||||
// If the method returns true, this is already handled for us
|
CompoundTag tag = book.getNbt();
|
||||||
GeyserItemStack geyserItemStack = inventory.getItem(0);
|
|
||||||
CompoundTag tag = geyserItemStack.getNbt();
|
|
||||||
// Position has to be the last interacted position... right?
|
// Position has to be the last interacted position... right?
|
||||||
Vector3i position = session.getLastInteractionBlockPosition();
|
Vector3i position = session.getLastInteractionBlockPosition();
|
||||||
|
// If shouldExpectLecternHandled returns true, this is already handled for us
|
||||||
// shouldRefresh means that we should boot out the client on our side because their lectern GUI isn't updated yet
|
// shouldRefresh means that we should boot out the client on our side because their lectern GUI isn't updated yet
|
||||||
boolean shouldRefresh = !session.getConnector().getWorldManager().shouldExpectLecternHandled() && !session.getLecternCache().contains(position);
|
boolean shouldRefresh = !session.getConnector().getWorldManager().shouldExpectLecternHandled() && !session.getLecternCache().contains(position);
|
||||||
|
|
||||||
NbtMap blockEntityTag;
|
NbtMap blockEntityTag;
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
int pagesSize = ((ListTag) tag.get("pages")).size();
|
int pagesSize = ((ListTag) tag.get("pages")).size();
|
||||||
ItemData itemData = geyserItemStack.getItemData(session);
|
ItemData itemData = book.getItemData(session);
|
||||||
NbtMapBuilder lecternTag = getBaseLecternTag(position.getX(), position.getY(), position.getZ(), pagesSize);
|
NbtMapBuilder lecternTag = getBaseLecternTag(position.getX(), position.getY(), position.getZ(), pagesSize);
|
||||||
lecternTag.putCompound("book", NbtMap.builder()
|
lecternTag.putCompound("book", NbtMap.builder()
|
||||||
.putByte("Count", (byte) itemData.getCount())
|
.putByte("Count", (byte) itemData.getCount())
|
||||||
|
@ -145,7 +156,6 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
|
public Inventory createInventory(String name, int windowId, WindowType windowType, PlayerInventory playerInventory) {
|
||||||
|
|
Loading…
Reference in a new issue