fix: do not send close inventory packet when opening a new inventory while one is open

This commit is contained in:
mworzala 2024-04-20 20:29:53 -04:00 committed by Matt Worzala
parent c4af024bd5
commit 2920cee2f6
2 changed files with 7 additions and 2 deletions

View File

@ -67,7 +67,9 @@ final class NbtComponentSerializerImpl implements NbtComponentSerializer {
} else { } else {
// Try to infer the type from the fields present. // Try to infer the type from the fields present.
Set<String> keys = compound.keySet(); Set<String> keys = compound.keySet();
if (keys.contains("text")) { if (keys.isEmpty()) {
return Component.empty();
} else if (keys.contains("text")) {
builder = deserializeTextComponent(compound); builder = deserializeTextComponent(compound);
} else if (keys.contains("translate")) { } else if (keys.contains("translate")) {
builder = deserializeTranslatableComponent(compound); builder = deserializeTranslatableComponent(compound);
@ -79,6 +81,9 @@ final class NbtComponentSerializerImpl implements NbtComponentSerializer {
builder = deserializeKeybindComponent(compound); builder = deserializeKeybindComponent(compound);
} else if (keys.contains("nbt")) { } else if (keys.contains("nbt")) {
builder = deserializeNbtComponent(compound); builder = deserializeNbtComponent(compound);
} else if (keys.contains("")) {
//todo This feels like a bug, im not sure why this is created.
builder = Component.text().content(compound.getString(""));
} else throw new UnsupportedOperationException("Unable to infer component type"); } else throw new UnsupportedOperationException("Unable to infer component type");
} }

View File

@ -1767,7 +1767,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
* It closes the player inventory (when opened) if {@link #getOpenInventory()} returns null. * It closes the player inventory (when opened) if {@link #getOpenInventory()} returns null.
*/ */
public void closeInventory() { public void closeInventory() {
closeInventory(false); closeInventory(true);
} }
@ApiStatus.Internal @ApiStatus.Internal