diff --git a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java index 5f98712de..37dceee40 100644 --- a/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java +++ b/v1_14_R1/src/main/java/net/citizensnpcs/nms/v1_14_R1/util/NMSImpl.java @@ -218,6 +218,7 @@ import net.minecraft.server.v1_14_R1.ChunkProviderServer; import net.minecraft.server.v1_14_R1.Container; import net.minecraft.server.v1_14_R1.ContainerAccess; import net.minecraft.server.v1_14_R1.ContainerAnvil; +import net.minecraft.server.v1_14_R1.Containers; import net.minecraft.server.v1_14_R1.ControllerJump; import net.minecraft.server.v1_14_R1.ControllerMove; import net.minecraft.server.v1_14_R1.CrashReport; @@ -1390,9 +1391,90 @@ public class NMSImpl implements NMSBridge { @Override public void updateInventoryTitle(Player player, InventoryView view, String newTitle) { EntityPlayer handle = (EntityPlayer) getHandle(player); + Containers menuType = null; + switch (view.getTopInventory().getType()) { + case ANVIL: + menuType = Containers.ANVIL; + break; + case BARREL: + menuType = Containers.GENERIC_9X3; + break; + case BEACON: + menuType = Containers.BEACON; + break; + case BLAST_FURNACE: + menuType = Containers.BLAST_FURNACE; + break; + case BREWING: + menuType = Containers.BREWING_STAND; + break; + case CARTOGRAPHY: + menuType = Containers.CARTOGRAPHY; + break; + case CHEST: + int sz = view.getTopInventory().getSize(); + if (sz > 45) { + menuType = Containers.GENERIC_9X6; + } else if (sz > 36) { + menuType = Containers.GENERIC_9X5; + } else if (sz > 27) { + menuType = Containers.GENERIC_9X4; + } else if (sz > 18) { + menuType = Containers.GENERIC_9X3; + } else if (sz > 9) { + menuType = Containers.GENERIC_9X2; + } else { + menuType = Containers.GENERIC_9X1; + } + break; + case PLAYER: + case CRAFTING: + case CREATIVE: + return; + case DISPENSER: + case DROPPER: + menuType = Containers.GENERIC_3X3; + break; + case ENCHANTING: + menuType = Containers.ENCHANTMENT; + break; + case ENDER_CHEST: + menuType = Containers.GENERIC_9X3; + break; + case FURNACE: + menuType = Containers.FURNACE; + break; + case GRINDSTONE: + menuType = Containers.GRINDSTONE; + break; + case HOPPER: + menuType = Containers.HOPPER; + break; + case LECTERN: + menuType = Containers.LECTERN; + break; + case LOOM: + menuType = Containers.LOOM; + break; + case MERCHANT: + menuType = Containers.MERCHANT; + break; + case SHULKER_BOX: + menuType = Containers.SHULKER_BOX; + break; + case SMOKER: + menuType = Containers.SMOKER; + break; + case STONECUTTER: + menuType = Containers.STONECUTTER; + break; + case WORKBENCH: + menuType = Containers.CRAFTING; + break; + } Container active = handle.activeContainer; - handle.playerConnection.sendPacket( - new PacketPlayOutOpenWindow(active.windowId, active.getType(), new ChatComponentText(newTitle))); + handle.playerConnection + .sendPacket(new PacketPlayOutOpenWindow(active.windowId, menuType, new ChatComponentText(newTitle))); player.updateInventory(); } diff --git a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java index 4cef8f2ee..0d30c1e25 100644 --- a/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java +++ b/v1_15_R1/src/main/java/net/citizensnpcs/nms/v1_15_R1/util/NMSImpl.java @@ -220,6 +220,7 @@ import net.minecraft.server.v1_15_R1.ChunkProviderServer; import net.minecraft.server.v1_15_R1.Container; import net.minecraft.server.v1_15_R1.ContainerAccess; import net.minecraft.server.v1_15_R1.ContainerAnvil; +import net.minecraft.server.v1_15_R1.Containers; import net.minecraft.server.v1_15_R1.ControllerJump; import net.minecraft.server.v1_15_R1.ControllerMove; import net.minecraft.server.v1_15_R1.ControllerMoveFlying; @@ -1429,9 +1430,90 @@ public class NMSImpl implements NMSBridge { @Override public void updateInventoryTitle(Player player, InventoryView view, String newTitle) { EntityPlayer handle = (EntityPlayer) getHandle(player); + Containers menuType = null; + switch (view.getTopInventory().getType()) { + case ANVIL: + menuType = Containers.ANVIL; + break; + case BARREL: + menuType = Containers.GENERIC_9X3; + break; + case BEACON: + menuType = Containers.BEACON; + break; + case BLAST_FURNACE: + menuType = Containers.BLAST_FURNACE; + break; + case BREWING: + menuType = Containers.BREWING_STAND; + break; + case CARTOGRAPHY: + menuType = Containers.CARTOGRAPHY_TABLE; + break; + case CHEST: + int sz = view.getTopInventory().getSize(); + if (sz > 45) { + menuType = Containers.GENERIC_9X6; + } else if (sz > 36) { + menuType = Containers.GENERIC_9X5; + } else if (sz > 27) { + menuType = Containers.GENERIC_9X4; + } else if (sz > 18) { + menuType = Containers.GENERIC_9X3; + } else if (sz > 9) { + menuType = Containers.GENERIC_9X2; + } else { + menuType = Containers.GENERIC_9X1; + } + break; + case PLAYER: + case CRAFTING: + case CREATIVE: + return; + case DISPENSER: + case DROPPER: + menuType = Containers.GENERIC_3X3; + break; + case ENCHANTING: + menuType = Containers.ENCHANTMENT; + break; + case ENDER_CHEST: + menuType = Containers.GENERIC_9X3; + break; + case FURNACE: + menuType = Containers.FURNACE; + break; + case GRINDSTONE: + menuType = Containers.GRINDSTONE; + break; + case HOPPER: + menuType = Containers.HOPPER; + break; + case LECTERN: + menuType = Containers.LECTERN; + break; + case LOOM: + menuType = Containers.LOOM; + break; + case MERCHANT: + menuType = Containers.MERCHANT; + break; + case SHULKER_BOX: + menuType = Containers.SHULKER_BOX; + break; + case SMOKER: + menuType = Containers.SMOKER; + break; + case STONECUTTER: + menuType = Containers.STONECUTTER; + break; + case WORKBENCH: + menuType = Containers.CRAFTING; + break; + } Container active = handle.activeContainer; - handle.playerConnection.sendPacket( - new PacketPlayOutOpenWindow(active.windowId, active.getType(), new ChatComponentText(newTitle))); + handle.playerConnection + .sendPacket(new PacketPlayOutOpenWindow(active.windowId, menuType, new ChatComponentText(newTitle))); player.updateInventory(); } diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java index 2003fff9e..b3af7da69 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/NMSImpl.java @@ -227,6 +227,7 @@ import net.minecraft.server.v1_16_R3.ChunkProviderServer; import net.minecraft.server.v1_16_R3.Container; import net.minecraft.server.v1_16_R3.ContainerAccess; import net.minecraft.server.v1_16_R3.ContainerAnvil; +import net.minecraft.server.v1_16_R3.Containers; import net.minecraft.server.v1_16_R3.ControllerJump; import net.minecraft.server.v1_16_R3.ControllerMove; import net.minecraft.server.v1_16_R3.ControllerMoveFlying; @@ -1452,9 +1453,93 @@ public class NMSImpl implements NMSBridge { @Override public void updateInventoryTitle(Player player, InventoryView view, String newTitle) { EntityPlayer handle = (EntityPlayer) getHandle(player); + Containers menuType = null; + switch (view.getTopInventory().getType()) { + case ANVIL: + menuType = Containers.ANVIL; + break; + case BARREL: + menuType = Containers.GENERIC_9X3; + break; + case BEACON: + menuType = Containers.BEACON; + break; + case BLAST_FURNACE: + menuType = Containers.BLAST_FURNACE; + break; + case BREWING: + menuType = Containers.BREWING_STAND; + break; + case CARTOGRAPHY: + menuType = Containers.CARTOGRAPHY_TABLE; + break; + case CHEST: + int sz = view.getTopInventory().getSize(); + if (sz > 45) { + menuType = Containers.GENERIC_9X6; + } else if (sz > 36) { + menuType = Containers.GENERIC_9X5; + } else if (sz > 27) { + menuType = Containers.GENERIC_9X4; + } else if (sz > 18) { + menuType = Containers.GENERIC_9X3; + } else if (sz > 9) { + menuType = Containers.GENERIC_9X2; + } else { + menuType = Containers.GENERIC_9X1; + } + break; + case PLAYER: + case CRAFTING: + case CREATIVE: + return; + case DISPENSER: + case DROPPER: + menuType = Containers.GENERIC_3X3; + break; + case ENCHANTING: + menuType = Containers.ENCHANTMENT; + break; + case ENDER_CHEST: + menuType = Containers.GENERIC_9X3; + break; + case FURNACE: + menuType = Containers.FURNACE; + break; + case GRINDSTONE: + menuType = Containers.GRINDSTONE; + break; + case HOPPER: + menuType = Containers.HOPPER; + break; + case LECTERN: + menuType = Containers.LECTERN; + break; + case LOOM: + menuType = Containers.LOOM; + break; + case MERCHANT: + menuType = Containers.MERCHANT; + break; + case SHULKER_BOX: + menuType = Containers.SHULKER_BOX; + break; + case SMITHING: + menuType = Containers.SMITHING; + break; + case SMOKER: + menuType = Containers.SMOKER; + break; + case STONECUTTER: + menuType = Containers.STONECUTTER; + break; + case WORKBENCH: + menuType = Containers.CRAFTING; + break; + } Container active = handle.activeContainer; - handle.playerConnection.sendPacket( - new PacketPlayOutOpenWindow(active.windowId, active.getType(), new ChatComponentText(newTitle))); + handle.playerConnection + .sendPacket(new PacketPlayOutOpenWindow(active.windowId, menuType, new ChatComponentText(newTitle))); player.updateInventory(); } diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java index 73d10a9f1..275be5e73 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java @@ -280,7 +280,7 @@ import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; -import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.enchantment.EnchantmentHelper; @@ -1448,9 +1448,94 @@ public class NMSImpl implements NMSBridge { @Override public void updateInventoryTitle(Player player, InventoryView view, String newTitle) { ServerPlayer handle = (ServerPlayer) getHandle(player); - InventoryMenu active = handle.inventoryMenu; - handle.connection.send( - new ClientboundOpenScreenPacket(active.containerId, active.getType(), new TextComponent(newTitle))); + MenuType menuType = null; + switch (view.getTopInventory().getType()) { + case ANVIL: + menuType = MenuType.ANVIL; + break; + case BARREL: + menuType = MenuType.GENERIC_9x3; + break; + case BEACON: + menuType = MenuType.BEACON; + break; + case BLAST_FURNACE: + menuType = MenuType.BLAST_FURNACE; + break; + case BREWING: + menuType = MenuType.BREWING_STAND; + break; + case CARTOGRAPHY: + menuType = MenuType.CARTOGRAPHY_TABLE; + break; + case CHEST: + int sz = view.getTopInventory().getSize(); + if (sz > 45) { + menuType = MenuType.GENERIC_9x6; + } else if (sz > 36) { + menuType = MenuType.GENERIC_9x5; + } else if (sz > 27) { + menuType = MenuType.GENERIC_9x4; + } else if (sz > 18) { + menuType = MenuType.GENERIC_9x3; + } else if (sz > 9) { + menuType = MenuType.GENERIC_9x2; + } else { + menuType = MenuType.GENERIC_9x1; + } + break; + case COMPOSTER: + break; + case PLAYER: + case CRAFTING: + case CREATIVE: + return; + case DISPENSER: + case DROPPER: + menuType = MenuType.GENERIC_3x3; + break; + case ENCHANTING: + menuType = MenuType.ENCHANTMENT; + break; + case ENDER_CHEST: + menuType = MenuType.GENERIC_9x3; + break; + case FURNACE: + menuType = MenuType.FURNACE; + break; + case GRINDSTONE: + menuType = MenuType.GRINDSTONE; + break; + case HOPPER: + menuType = MenuType.HOPPER; + break; + case LECTERN: + menuType = MenuType.LECTERN; + break; + case LOOM: + menuType = MenuType.LOOM; + break; + case MERCHANT: + menuType = MenuType.MERCHANT; + break; + case SHULKER_BOX: + menuType = MenuType.SHULKER_BOX; + break; + case SMITHING: + menuType = MenuType.SMITHING; + break; + case SMOKER: + menuType = MenuType.SMOKER; + break; + case STONECUTTER: + menuType = MenuType.STONECUTTER; + break; + case WORKBENCH: + menuType = MenuType.CRAFTING; + break; + } + handle.connection.send(new ClientboundOpenScreenPacket(handle.containerMenu.containerId, menuType, + new TextComponent(newTitle))); player.updateInventory(); } diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java index 5d44a949e..97bdb7dc0 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java @@ -222,7 +222,6 @@ import net.citizensnpcs.util.Util; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; import net.minecraft.ReportedException; -import net.minecraft.commands.Commands; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; import net.minecraft.network.Connection; @@ -284,7 +283,7 @@ import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.entity.vehicle.AbstractMinecart; import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.inventory.ContainerLevelAccess; -import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.MenuType; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.enchantment.EnchantmentHelper; @@ -1456,9 +1455,94 @@ public class NMSImpl implements NMSBridge { @Override public void updateInventoryTitle(Player player, InventoryView view, String newTitle) { ServerPlayer handle = (ServerPlayer) getHandle(player); - InventoryMenu active = handle.inventoryMenu; - handle.connection.send( - new ClientboundOpenScreenPacket(active.containerId, active.getType(), new TextComponent(newTitle))); + MenuType menuType = null; + switch (view.getTopInventory().getType()) { + case ANVIL: + menuType = MenuType.ANVIL; + break; + case BARREL: + menuType = MenuType.GENERIC_9x3; + break; + case BEACON: + menuType = MenuType.BEACON; + break; + case BLAST_FURNACE: + menuType = MenuType.BLAST_FURNACE; + break; + case BREWING: + menuType = MenuType.BREWING_STAND; + break; + case CARTOGRAPHY: + menuType = MenuType.CARTOGRAPHY_TABLE; + break; + case CHEST: + int sz = view.getTopInventory().getSize(); + if (sz > 45) { + menuType = MenuType.GENERIC_9x6; + } else if (sz > 36) { + menuType = MenuType.GENERIC_9x5; + } else if (sz > 27) { + menuType = MenuType.GENERIC_9x4; + } else if (sz > 18) { + menuType = MenuType.GENERIC_9x3; + } else if (sz > 9) { + menuType = MenuType.GENERIC_9x2; + } else { + menuType = MenuType.GENERIC_9x1; + } + break; + case COMPOSTER: + break; + case PLAYER: + case CRAFTING: + case CREATIVE: + return; + case DISPENSER: + case DROPPER: + menuType = MenuType.GENERIC_3x3; + break; + case ENCHANTING: + menuType = MenuType.ENCHANTMENT; + break; + case ENDER_CHEST: + menuType = MenuType.GENERIC_9x3; + break; + case FURNACE: + menuType = MenuType.FURNACE; + break; + case GRINDSTONE: + menuType = MenuType.GRINDSTONE; + break; + case HOPPER: + menuType = MenuType.HOPPER; + break; + case LECTERN: + menuType = MenuType.LECTERN; + break; + case LOOM: + menuType = MenuType.LOOM; + break; + case MERCHANT: + menuType = MenuType.MERCHANT; + break; + case SHULKER_BOX: + menuType = MenuType.SHULKER_BOX; + break; + case SMITHING: + menuType = MenuType.SMITHING; + break; + case SMOKER: + menuType = MenuType.SMOKER; + break; + case STONECUTTER: + menuType = MenuType.STONECUTTER; + break; + case WORKBENCH: + menuType = MenuType.CRAFTING; + break; + } + handle.connection.send(new ClientboundOpenScreenPacket(handle.containerMenu.containerId, menuType, + new TextComponent(newTitle))); player.updateInventory(); } diff --git a/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java b/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java index 9a6f8689c..c37774160 100644 --- a/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java +++ b/v1_19_R1/src/main/java/net/citizensnpcs/nms/v1_19_R1/util/NMSImpl.java @@ -1557,7 +1557,7 @@ public class NMSImpl implements NMSBridge { menuType = MenuType.CRAFTING; break; } - handle.connection.send(new ClientboundOpenScreenPacket(handle.inventoryMenu.containerId, menuType, + handle.connection.send(new ClientboundOpenScreenPacket(handle.containerMenu.containerId, menuType, MutableComponent.create(new LiteralContents(newTitle)))); player.updateInventory(); }