|
73 | 73 | import org.geysermc.geyser.inventory.item.StoredItemMappings; |
74 | 74 | import org.geysermc.geyser.item.GeyserCustomMappingData; |
75 | 75 | import org.geysermc.geyser.item.Items; |
| 76 | +import org.geysermc.geyser.item.TooltipOptions; |
76 | 77 | import org.geysermc.geyser.item.custom.GeyserCustomItemDefinition; |
77 | 78 | import org.geysermc.geyser.item.custom.impl.predicates.GeyserRangeDispatchPredicate; |
78 | 79 | import org.geysermc.geyser.item.exception.InvalidItemComponentsException; |
|
88 | 89 | import org.geysermc.geyser.registry.type.ItemMappings; |
89 | 90 | import org.geysermc.geyser.registry.type.NonVanillaItemRegistration; |
90 | 91 | import org.geysermc.geyser.registry.type.PaletteItem; |
| 92 | +import org.geysermc.geyser.translator.item.BedrockItemBuilder; |
| 93 | +import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents; |
91 | 94 | import org.geysermc.geyser.util.MinecraftKey; |
92 | 95 | import org.geysermc.geyser.util.JsonUtils; |
93 | 96 |
|
@@ -223,6 +226,20 @@ public static void populate() { |
223 | 226 | } |
224 | 227 |
|
225 | 228 | ItemDefinition definition = new SimpleItemDefinition(entry.getName().intern(), id, ItemVersion.from(entry.getVersion()), entry.isComponentBased(), components); |
| 229 | + |
| 230 | + // Some item on Bedrock Edition have a different stack size, so we're changing that through the component. |
| 231 | + // This resolve https://github.com/GeyserMC/Geyser/issues/5612 and https://github.com/GeyserMC/Geyser/issues/4905 |
| 232 | + if (definition.getIdentifier().equals("minecraft:cake")) { |
| 233 | + definition = new SimpleItemDefinition(entry.getName().intern(), id, ItemVersion.from(entry.getVersion()), true, fromItemDefinitionToDataDriven(definition, 1, null, null)); |
| 234 | + } else if (definition.getIdentifier().equals("minecraft:armor_stand")) { |
| 235 | + // You have to change the item version to data driven for armor stand else this won't work. |
| 236 | + definition = new SimpleItemDefinition(entry.getName().intern(), id, ItemVersion.DATA_DRIVEN, true, fromItemDefinitionToDataDriven(definition, 16, "armor_stand", "item.armor_stand.name")); |
| 237 | + } else if (definition.getIdentifier().equals("minecraft:firework_rocket")) { |
| 238 | + // For fireworks rocket, we purposely make this item data driven so now bedrock won't do client-sided boosting |
| 239 | + // and now we can control fireworks boost ourselves! This resolve https://github.com/GeyserMC/Geyser/issues/5409 |
| 240 | + definition = new SimpleItemDefinition(entry.getName().intern(), id, ItemVersion.DATA_DRIVEN, true, fromItemDefinitionToDataDriven(definition, 64, "fireworks", "item.fireworks.name")); |
| 241 | + } |
| 242 | + |
226 | 243 | definitions.put(entry.getName(), definition); |
227 | 244 | registry.put(definition.getRuntimeId(), definition); |
228 | 245 | } |
@@ -722,6 +739,32 @@ public static void populate() { |
722 | 739 | } |
723 | 740 | } |
724 | 741 |
|
| 742 | + // Since the fireworks tag now won't show up due to this is being a data driven item, we have to translate it to lore ourselves |
| 743 | + for (int j = 0; j < creativeItems.size(); j++) { |
| 744 | + CreativeItemData itemData = creativeItems.get(j); |
| 745 | + if (!itemData.getItem().getDefinition().getIdentifier().equals("minecraft:firework_rocket")) { |
| 746 | + continue; |
| 747 | + } |
| 748 | + |
| 749 | + NbtMap tag = null; |
| 750 | + if (itemData.getItem().getTag() != null) { |
| 751 | + final DataComponents components = new DataComponents(new HashMap<>()); |
| 752 | + Items.FIREWORK_ROCKET.translateNbtToJava(null, itemData.getItem().getTag(), components, null); |
| 753 | + final BedrockItemBuilder builder = new BedrockItemBuilder(); |
| 754 | + Items.FIREWORK_ROCKET.translateComponentsToBedrock(null, components, TooltipOptions.ALL_SHOWN, builder); |
| 755 | + |
| 756 | + tag = builder.build(); |
| 757 | + } |
| 758 | + |
| 759 | + creativeItems.set(j, new CreativeItemData(ItemData.builder() |
| 760 | + .usingNetId(true) |
| 761 | + .netId(itemData.getItem().getNetId()) |
| 762 | + .definition(itemData.getItem().getDefinition()) |
| 763 | + .tag(tag) |
| 764 | + .count(itemData.getItem().getCount()) |
| 765 | + .build(), itemData.getNetId(), itemData.getGroupId())); |
| 766 | + } |
| 767 | + |
725 | 768 | ItemMappings itemMappings = ItemMappings.builder() |
726 | 769 | .items(mappings.toArray(new ItemMapping[0])) |
727 | 770 | .zeroBlockDefinitionRuntimeId(mappings.stream() |
@@ -784,6 +827,35 @@ private static NbtMap registerFurnaceMinecart(int nextFreeBedrockId) { |
784 | 827 | builder.putCompound("components", componentBuilder.build()); |
785 | 828 | return builder.build(); |
786 | 829 | } |
| 830 | + |
| 831 | + private static NbtMap fromItemDefinitionToDataDriven(ItemDefinition definition, int maxStackSize, String texture, String displayName) { |
| 832 | + NbtMapBuilder builder = NbtMap.builder(); |
| 833 | + builder.putString("name", definition.getIdentifier()).putInt("id", definition.getRuntimeId()); |
| 834 | + |
| 835 | + NbtMapBuilder itemProperties = NbtMap.builder(); |
| 836 | + |
| 837 | + NbtMapBuilder componentBuilder = NbtMap.builder(); |
| 838 | + |
| 839 | + if (texture != null) { |
| 840 | + NbtMap iconMap = NbtMap.builder() |
| 841 | + .putCompound("textures", NbtMap.builder() |
| 842 | + .putString("default", texture) |
| 843 | + .build()) |
| 844 | + .build(); |
| 845 | + itemProperties.putCompound("minecraft:icon", iconMap); |
| 846 | + } |
| 847 | + |
| 848 | + if (displayName != null) { |
| 849 | + componentBuilder.putCompound("minecraft:display_name", NbtMap.builder().putString("value", displayName).build()); |
| 850 | + } |
| 851 | + |
| 852 | + itemProperties.putBoolean("allow_off_hand", true); |
| 853 | + itemProperties.putInt("max_stack_size", maxStackSize); |
| 854 | + |
| 855 | + componentBuilder.putCompound("item_properties", itemProperties.build()); |
| 856 | + builder.putCompound("components", componentBuilder.build()); |
| 857 | + return builder.build(); |
| 858 | + } |
787 | 859 |
|
788 | 860 | public static int getCreativeIndex(String creativeGroup, CreativeItemCategory creativeItemCategory, Map<String, Integer> groupIndexes, Map<CreativeItemCategory, Integer> fallBacks, List<CreativeItemGroup> creativeItemGroups) { |
789 | 861 | if (fallBacks.isEmpty()) { |
|
0 commit comments