| 1 | package net.minecraft.util.datafix.schemas;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import com.mojang.datafixers.DSL;
|
| 5 | import com.mojang.datafixers.DataFixUtils;
|
| 6 | import com.mojang.datafixers.schemas.Schema;
|
| 7 | import com.mojang.datafixers.types.templates.TypeTemplate;
|
| 8 | import com.mojang.datafixers.types.templates.Hook.HookFunction;
|
| 9 | import com.mojang.datafixers.util.Pair;
|
| 10 | import com.mojang.logging.LogUtils;
|
| 11 | import com.mojang.serialization.Dynamic;
|
| 12 | import com.mojang.serialization.DynamicOps;
|
| 13 | import java.util.Map;
|
| 14 | import java.util.function.Supplier;
|
| 15 | import net.minecraft.util.datafix.fixes.References;
|
| 16 | import org.slf4j.Logger;
|
| 17 |
|
| 18 | public class V99 extends Schema {
|
| 19 | private static final Logger LOGGER = LogUtils.getLogger();
|
| 20 | private static final Map<String, String> ITEM_TO_BLOCKENTITY = DataFixUtils.make(Maps.newHashMap(), map -> {
|
| 21 | map.put("minecraft:furnace", "Furnace");
|
| 22 | map.put("minecraft:lit_furnace", "Furnace");
|
| 23 | map.put("minecraft:chest", "Chest");
|
| 24 | map.put("minecraft:trapped_chest", "Chest");
|
| 25 | map.put("minecraft:ender_chest", "EnderChest");
|
| 26 | map.put("minecraft:jukebox", "RecordPlayer");
|
| 27 | map.put("minecraft:dispenser", "Trap");
|
| 28 | map.put("minecraft:dropper", "Dropper");
|
| 29 | map.put("minecraft:sign", "Sign");
|
| 30 | map.put("minecraft:mob_spawner", "MobSpawner");
|
| 31 | map.put("minecraft:noteblock", "Music");
|
| 32 | map.put("minecraft:brewing_stand", "Cauldron");
|
| 33 | map.put("minecraft:enhanting_table", "EnchantTable");
|
| 34 | map.put("minecraft:command_block", "CommandBlock");
|
| 35 | map.put("minecraft:beacon", "Beacon");
|
| 36 | map.put("minecraft:skull", "Skull");
|
| 37 | map.put("minecraft:daylight_detector", "DLDetector");
|
| 38 | map.put("minecraft:hopper", "Hopper");
|
| 39 | map.put("minecraft:banner", "Banner");
|
| 40 | map.put("minecraft:flower_pot", "FlowerPot");
|
| 41 | map.put("minecraft:repeating_command_block", "CommandBlock");
|
| 42 | map.put("minecraft:chain_command_block", "CommandBlock");
|
| 43 | map.put("minecraft:standing_sign", "Sign");
|
| 44 | map.put("minecraft:wall_sign", "Sign");
|
| 45 | map.put("minecraft:piston_head", "Piston");
|
| 46 | map.put("minecraft:daylight_detector_inverted", "DLDetector");
|
| 47 | map.put("minecraft:unpowered_comparator", "Comparator");
|
| 48 | map.put("minecraft:powered_comparator", "Comparator");
|
| 49 | map.put("minecraft:wall_banner", "Banner");
|
| 50 | map.put("minecraft:standing_banner", "Banner");
|
| 51 | map.put("minecraft:structure_block", "Structure");
|
| 52 | map.put("minecraft:end_portal", "Airportal");
|
| 53 | map.put("minecraft:end_gateway", "EndGateway");
|
| 54 | map.put("minecraft:shield", "Banner");
|
| 55 | });
|
| 56 | public static final Map<String, String> ITEM_TO_ENTITY = Map.of("minecraft:armor_stand", "ArmorStand", "minecraft:painting", "Painting");
|
| 57 | protected static final HookFunction ADD_NAMES = new HookFunction() {
|
| 58 | @Override
|
| 59 | public <T> T apply(final DynamicOps<T> ops, final T value) {
|
| 60 | return V99.addNames(new Dynamic<>(ops, value), V99.ITEM_TO_BLOCKENTITY, V99.ITEM_TO_ENTITY);
|
| 61 | }
|
| 62 | };
|
| 63 |
|
| 64 | public V99(final int versionKey, final Schema parent) {
|
| 65 | super(versionKey, parent);
|
| 66 | }
|
| 67 |
|
| 68 | protected static void registerThrowableProjectile(final Schema schema, final Map<String, Supplier<TypeTemplate>> map, final String name) {
|
| 69 | schema.register(map, name, () -> DSL.optionalFields("inTile", References.BLOCK_NAME.in(schema)));
|
| 70 | }
|
| 71 |
|
| 72 | protected static void registerMinecart(final Schema schema, final Map<String, Supplier<TypeTemplate>> map, final String name) {
|
| 73 | schema.register(map, name, () -> DSL.optionalFields("DisplayTile", References.BLOCK_NAME.in(schema)));
|
| 74 | }
|
| 75 |
|
| 76 | protected static void registerInventory(final Schema schema, final Map<String, Supplier<TypeTemplate>> map, final String name) {
|
| 77 | schema.register(map, name, () -> DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.in(schema))));
|
| 78 | }
|
| 79 |
|
| 80 | @Override
|
| 81 | public Map<String, Supplier<TypeTemplate>> registerEntities(final Schema schema) {
|
| 82 | Map<String, Supplier<TypeTemplate>> map = Maps.newHashMap();
|
| 83 | schema.register(map, "Item", name -> DSL.optionalFields("Item", References.ITEM_STACK.in(schema)));
|
| 84 | schema.registerSimple(map, "XPOrb");
|
| 85 | registerThrowableProjectile(schema, map, "ThrownEgg");
|
| 86 | schema.registerSimple(map, "LeashKnot");
|
| 87 | schema.registerSimple(map, "Painting");
|
| 88 | schema.register(map, "Arrow", name -> DSL.optionalFields("inTile", References.BLOCK_NAME.in(schema)));
|
| 89 | schema.register(map, "TippedArrow", name -> DSL.optionalFields("inTile", References.BLOCK_NAME.in(schema)));
|
| 90 | schema.register(map, "SpectralArrow", name -> DSL.optionalFields("inTile", References.BLOCK_NAME.in(schema)));
|
| 91 | registerThrowableProjectile(schema, map, "Snowball");
|
| 92 | registerThrowableProjectile(schema, map, "Fireball");
|
| 93 | registerThrowableProjectile(schema, map, "SmallFireball");
|
| 94 | registerThrowableProjectile(schema, map, "ThrownEnderpearl");
|
| 95 | schema.registerSimple(map, "EyeOfEnderSignal");
|
| 96 | schema.register(map, "ThrownPotion", name -> DSL.optionalFields("inTile", References.BLOCK_NAME.in(schema), "Potion", References.ITEM_STACK.in(schema)));
|
| 97 | registerThrowableProjectile(schema, map, "ThrownExpBottle");
|
| 98 | schema.register(map, "ItemFrame", name -> DSL.optionalFields("Item", References.ITEM_STACK.in(schema)));
|
| 99 | registerThrowableProjectile(schema, map, "WitherSkull");
|
| 100 | schema.registerSimple(map, "PrimedTnt");
|
| 101 | schema.register(
|
| 102 | map, "FallingSand", name -> DSL.optionalFields("Block", References.BLOCK_NAME.in(schema), "TileEntityData", References.BLOCK_ENTITY.in(schema))
|
| 103 | );
|
| 104 | schema.register(map, "FireworksRocketEntity", name -> DSL.optionalFields("FireworksItem", References.ITEM_STACK.in(schema)));
|
| 105 | schema.registerSimple(map, "Boat");
|
| 106 | schema.register(
|
| 107 | map, "Minecart", () -> DSL.optionalFields("DisplayTile", References.BLOCK_NAME.in(schema), "Items", DSL.list(References.ITEM_STACK.in(schema)))
|
| 108 | );
|
| 109 | registerMinecart(schema, map, "MinecartRideable");
|
| 110 | schema.register(
|
| 111 | map, "MinecartChest", name -> DSL.optionalFields("DisplayTile", References.BLOCK_NAME.in(schema), "Items", DSL.list(References.ITEM_STACK.in(schema)))
|
| 112 | );
|
| 113 | registerMinecart(schema, map, "MinecartFurnace");
|
| 114 | registerMinecart(schema, map, "MinecartTNT");
|
| 115 | schema.register(map, "MinecartSpawner", () -> DSL.optionalFields("DisplayTile", References.BLOCK_NAME.in(schema), References.UNTAGGED_SPAWNER.in(schema)));
|
| 116 | schema.register(
|
| 117 | map, "MinecartHopper", name -> DSL.optionalFields("DisplayTile", References.BLOCK_NAME.in(schema), "Items", DSL.list(References.ITEM_STACK.in(schema)))
|
| 118 | );
|
| 119 | schema.register(
|
| 120 | map, "MinecartCommandBlock", () -> DSL.optionalFields("DisplayTile", References.BLOCK_NAME.in(schema), "LastOutput", References.TEXT_COMPONENT.in(schema))
|
| 121 | );
|
| 122 | schema.registerSimple(map, "ArmorStand");
|
| 123 | schema.registerSimple(map, "Creeper");
|
| 124 | schema.registerSimple(map, "Skeleton");
|
| 125 | schema.registerSimple(map, "Spider");
|
| 126 | schema.registerSimple(map, "Giant");
|
| 127 | schema.registerSimple(map, "Zombie");
|
| 128 | schema.registerSimple(map, "Slime");
|
| 129 | schema.registerSimple(map, "Ghast");
|
| 130 | schema.registerSimple(map, "PigZombie");
|
| 131 | schema.register(map, "Enderman", name -> DSL.optionalFields("carried", References.BLOCK_NAME.in(schema)));
|
| 132 | schema.registerSimple(map, "CaveSpider");
|
| 133 | schema.registerSimple(map, "Silverfish");
|
| 134 | schema.registerSimple(map, "Blaze");
|
| 135 | schema.registerSimple(map, "LavaSlime");
|
| 136 | schema.registerSimple(map, "EnderDragon");
|
| 137 | schema.registerSimple(map, "WitherBoss");
|
| 138 | schema.registerSimple(map, "Bat");
|
| 139 | schema.registerSimple(map, "Witch");
|
| 140 | schema.registerSimple(map, "Endermite");
|
| 141 | schema.registerSimple(map, "Guardian");
|
| 142 | schema.registerSimple(map, "Pig");
|
| 143 | schema.registerSimple(map, "Sheep");
|
| 144 | schema.registerSimple(map, "Cow");
|
| 145 | schema.registerSimple(map, "Chicken");
|
| 146 | schema.registerSimple(map, "Squid");
|
| 147 | schema.registerSimple(map, "Wolf");
|
| 148 | schema.registerSimple(map, "MushroomCow");
|
| 149 | schema.registerSimple(map, "SnowMan");
|
| 150 | schema.registerSimple(map, "Ozelot");
|
| 151 | schema.registerSimple(map, "VillagerGolem");
|
| 152 | schema.register(
|
| 153 | map,
|
| 154 | "EntityHorse",
|
| 155 | name -> DSL.optionalFields(
|
| 156 | "Items", DSL.list(References.ITEM_STACK.in(schema)), "ArmorItem", References.ITEM_STACK.in(schema), "SaddleItem", References.ITEM_STACK.in(schema)
|
| 157 | )
|
| 158 | );
|
| 159 | schema.registerSimple(map, "Rabbit");
|
| 160 | schema.register(
|
| 161 | map,
|
| 162 | "Villager",
|
| 163 | name -> DSL.optionalFields(
|
| 164 | "Inventory", DSL.list(References.ITEM_STACK.in(schema)), "Offers", DSL.optionalFields("Recipes", DSL.list(References.VILLAGER_TRADE.in(schema)))
|
| 165 | )
|
| 166 | );
|
| 167 | schema.registerSimple(map, "EnderCrystal");
|
| 168 | schema.register(map, "AreaEffectCloud", name -> DSL.optionalFields("Particle", References.PARTICLE.in(schema)));
|
| 169 | schema.registerSimple(map, "ShulkerBullet");
|
| 170 | schema.registerSimple(map, "DragonFireball");
|
| 171 | schema.registerSimple(map, "Shulker");
|
| 172 | return map;
|
| 173 | }
|
| 174 |
|
| 175 | @Override
|
| 176 | public Map<String, Supplier<TypeTemplate>> registerBlockEntities(final Schema schema) {
|
| 177 | Map<String, Supplier<TypeTemplate>> map = Maps.newHashMap();
|
| 178 | registerInventory(schema, map, "Furnace");
|
| 179 | registerInventory(schema, map, "Chest");
|
| 180 | schema.registerSimple(map, "EnderChest");
|
| 181 | schema.register(map, "RecordPlayer", name -> DSL.optionalFields("RecordItem", References.ITEM_STACK.in(schema)));
|
| 182 | registerInventory(schema, map, "Trap");
|
| 183 | registerInventory(schema, map, "Dropper");
|
| 184 | schema.register(map, "Sign", () -> sign(schema));
|
| 185 | schema.register(map, "MobSpawner", name -> References.UNTAGGED_SPAWNER.in(schema));
|
| 186 | schema.registerSimple(map, "Music");
|
| 187 | schema.registerSimple(map, "Piston");
|
| 188 | registerInventory(schema, map, "Cauldron");
|
| 189 | schema.registerSimple(map, "EnchantTable");
|
| 190 | schema.registerSimple(map, "Airportal");
|
| 191 | schema.register(map, "Control", () -> DSL.optionalFields("LastOutput", References.TEXT_COMPONENT.in(schema)));
|
| 192 | schema.registerSimple(map, "Beacon");
|
| 193 | schema.register(map, "Skull", () -> DSL.optionalFields("custom_name", References.TEXT_COMPONENT.in(schema)));
|
| 194 | schema.registerSimple(map, "DLDetector");
|
| 195 | registerInventory(schema, map, "Hopper");
|
| 196 | schema.registerSimple(map, "Comparator");
|
| 197 | schema.register(map, "FlowerPot", name -> DSL.optionalFields("Item", DSL.or(DSL.constType(DSL.intType()), References.ITEM_NAME.in(schema))));
|
| 198 | schema.register(map, "Banner", () -> DSL.optionalFields("CustomName", References.TEXT_COMPONENT.in(schema)));
|
| 199 | schema.registerSimple(map, "Structure");
|
| 200 | schema.registerSimple(map, "EndGateway");
|
| 201 | return map;
|
| 202 | }
|
| 203 |
|
| 204 | public static TypeTemplate sign(final Schema schema) {
|
| 205 | return DSL.optionalFields(
|
| 206 | Pair.of("Text1", References.TEXT_COMPONENT.in(schema)),
|
| 207 | Pair.of("Text2", References.TEXT_COMPONENT.in(schema)),
|
| 208 | Pair.of("Text3", References.TEXT_COMPONENT.in(schema)),
|
| 209 | Pair.of("Text4", References.TEXT_COMPONENT.in(schema)),
|
| 210 | Pair.of("FilteredText1", References.TEXT_COMPONENT.in(schema)),
|
| 211 | Pair.of("FilteredText2", References.TEXT_COMPONENT.in(schema)),
|
| 212 | Pair.of("FilteredText3", References.TEXT_COMPONENT.in(schema)),
|
| 213 | Pair.of("FilteredText4", References.TEXT_COMPONENT.in(schema))
|
| 214 | );
|
| 215 | }
|
| 216 |
|
| 217 | @Override
|
| 218 | public void registerTypes(
|
| 219 | final Schema schema, final Map<String, Supplier<TypeTemplate>> entityTypes, final Map<String, Supplier<TypeTemplate>> blockEntityTypes
|
| 220 | ) {
|
| 221 | schema.registerType(
|
| 222 | false,
|
| 223 | References.LEVEL,
|
| 224 | () -> DSL.optionalFields(
|
| 225 | "CustomBossEvents", DSL.compoundList(DSL.optionalFields("Name", References.TEXT_COMPONENT.in(schema))), References.LIGHTWEIGHT_LEVEL.in(schema)
|
| 226 | )
|
| 227 | );
|
| 228 | schema.registerType(false, References.LIGHTWEIGHT_LEVEL, DSL::remainder);
|
| 229 | schema.registerType(
|
| 230 | false,
|
| 231 | References.PLAYER,
|
| 232 | () -> DSL.optionalFields("Inventory", DSL.list(References.ITEM_STACK.in(schema)), "EnderItems", DSL.list(References.ITEM_STACK.in(schema)))
|
| 233 | );
|
| 234 | schema.registerType(
|
| 235 | false,
|
| 236 | References.CHUNK,
|
| 237 | () -> DSL.fields(
|
| 238 | "Level",
|
| 239 | DSL.optionalFields(
|
| 240 | "Entities",
|
| 241 | DSL.list(References.ENTITY_TREE.in(schema)),
|
| 242 | "TileEntities",
|
| 243 | DSL.list(DSL.or(References.BLOCK_ENTITY.in(schema), DSL.remainder())),
|
| 244 | "TileTicks",
|
| 245 | DSL.list(DSL.fields("i", References.BLOCK_NAME.in(schema)))
|
| 246 | )
|
| 247 | )
|
| 248 | );
|
| 249 | schema.registerType(
|
| 250 | true,
|
| 251 | References.BLOCK_ENTITY,
|
| 252 | () -> DSL.optionalFields("components", References.DATA_COMPONENTS.in(schema), DSL.taggedChoiceLazy("id", DSL.string(), blockEntityTypes))
|
| 253 | );
|
| 254 | schema.registerType(true, References.ENTITY_TREE, () -> DSL.optionalFields("Riding", References.ENTITY_TREE.in(schema), References.ENTITY.in(schema)));
|
| 255 | schema.registerType(false, References.ENTITY_NAME, () -> DSL.constType(NamespacedSchema.namespacedString()));
|
| 256 | schema.registerType(
|
| 257 | true,
|
| 258 | References.ENTITY,
|
| 259 | () -> DSL.and(
|
| 260 | References.ENTITY_EQUIPMENT.in(schema),
|
| 261 | DSL.optionalFields("CustomName", DSL.constType(DSL.string()), DSL.taggedChoiceLazy("id", DSL.string(), entityTypes))
|
| 262 | )
|
| 263 | );
|
| 264 | schema.registerType(
|
| 265 | true,
|
| 266 | References.ITEM_STACK,
|
| 267 | () -> DSL.hook(
|
| 268 | DSL.optionalFields("id", DSL.or(DSL.constType(DSL.intType()), References.ITEM_NAME.in(schema)), "tag", itemStackTag(schema)),
|
| 269 | ADD_NAMES,
|
| 270 | HookFunction.IDENTITY
|
| 271 | )
|
| 272 | );
|
| 273 | schema.registerType(false, References.OPTIONS, DSL::remainder);
|
| 274 | schema.registerType(false, References.BLOCK_NAME, () -> DSL.or(DSL.constType(DSL.intType()), DSL.constType(NamespacedSchema.namespacedString())));
|
| 275 | schema.registerType(false, References.ITEM_NAME, () -> DSL.constType(NamespacedSchema.namespacedString()));
|
| 276 | schema.registerType(false, References.STATS, DSL::remainder);
|
| 277 | schema.registerType(false, References.SAVED_DATA_COMMAND_STORAGE, DSL::remainder);
|
| 278 | schema.registerType(
|
| 279 | false,
|
| 280 | References.SAVED_DATA_CUSTOM_BOSS_EVENTS,
|
| 281 | () -> DSL.optionalFields("data", DSL.compoundList(DSL.optionalFields("Name", References.TEXT_COMPONENT.in(schema))))
|
| 282 | );
|
| 283 | schema.registerType(false, References.SAVED_DATA_ENDER_DRAGON_FIGHT, DSL::remainder);
|
| 284 | schema.registerType(false, References.SAVED_DATA_GAME_RULES, DSL::remainder);
|
| 285 | schema.registerType(false, References.SAVED_DATA_TICKETS, DSL::remainder);
|
| 286 | schema.registerType(
|
| 287 | false,
|
| 288 | References.SAVED_DATA_MAP_DATA,
|
| 289 | () -> DSL.optionalFields("data", DSL.optionalFields("banners", DSL.list(DSL.optionalFields("Name", References.TEXT_COMPONENT.in(schema)))))
|
| 290 | );
|
| 291 | schema.registerType(false, References.SAVED_DATA_MAP_INDEX, DSL::remainder);
|
| 292 | schema.registerType(false, References.SAVED_DATA_RAIDS, DSL::remainder);
|
| 293 | schema.registerType(false, References.SAVED_DATA_RANDOM_SEQUENCES, DSL::remainder);
|
| 294 | schema.registerType(false, References.SAVED_DATA_SCHEDULED_EVENTS, DSL::remainder);
|
| 295 | schema.registerType(
|
| 296 | false,
|
| 297 | References.SAVED_DATA_SCOREBOARD,
|
| 298 | () -> DSL.optionalFields(
|
| 299 | "data",
|
| 300 | DSL.optionalFields(
|
| 301 | "Objectives",
|
| 302 | DSL.list(References.OBJECTIVE.in(schema)),
|
| 303 | "Teams",
|
| 304 | DSL.list(References.TEAM.in(schema)),
|
| 305 | "PlayerScores",
|
| 306 | DSL.list(DSL.optionalFields("display", References.TEXT_COMPONENT.in(schema)))
|
| 307 | )
|
| 308 | )
|
| 309 | );
|
| 310 | schema.registerType(false, References.SAVED_DATA_STOPWATCHES, DSL::remainder);
|
| 311 | schema.registerType(
|
| 312 | false,
|
| 313 | References.SAVED_DATA_STRUCTURE_FEATURE_INDICES,
|
| 314 | () -> DSL.optionalFields("data", DSL.optionalFields("Features", DSL.compoundList(References.STRUCTURE_FEATURE.in(schema))))
|
| 315 | );
|
| 316 | schema.registerType(false, References.SAVED_DATA_WANDERING_TRADER, DSL::remainder);
|
| 317 | schema.registerType(false, References.SAVED_DATA_WEATHER, DSL::remainder);
|
| 318 | schema.registerType(false, References.SAVED_DATA_WORLD_BORDER, DSL::remainder);
|
| 319 | schema.registerType(false, References.SAVED_DATA_WORLD_CLOCKS, DSL::remainder);
|
| 320 | schema.registerType(false, References.SAVED_DATA_WORLD_GEN_SETTINGS, () -> DSL.fields("data", References.WORLD_GEN_SETTINGS.in(schema)));
|
| 321 | schema.registerType(false, References.DEBUG_PROFILE, DSL::remainder);
|
| 322 | schema.registerType(false, References.STRUCTURE_FEATURE, DSL::remainder);
|
| 323 | schema.registerType(false, References.OBJECTIVE, DSL::remainder);
|
| 324 | schema.registerType(
|
| 325 | false,
|
| 326 | References.TEAM,
|
| 327 | () -> DSL.optionalFields(
|
| 328 | "MemberNamePrefix",
|
| 329 | References.TEXT_COMPONENT.in(schema),
|
| 330 | "MemberNameSuffix",
|
| 331 | References.TEXT_COMPONENT.in(schema),
|
| 332 | "DisplayName",
|
| 333 | References.TEXT_COMPONENT.in(schema)
|
| 334 | )
|
| 335 | );
|
| 336 | schema.registerType(true, References.UNTAGGED_SPAWNER, DSL::remainder);
|
| 337 | schema.registerType(false, References.POI_CHUNK, DSL::remainder);
|
| 338 | schema.registerType(false, References.WORLD_GEN_SETTINGS, DSL::remainder);
|
| 339 | schema.registerType(false, References.ENTITY_CHUNK, () -> DSL.optionalFields("Entities", DSL.list(References.ENTITY_TREE.in(schema))));
|
| 340 | schema.registerType(true, References.DATA_COMPONENTS, DSL::remainder);
|
| 341 | schema.registerType(
|
| 342 | true,
|
| 343 | References.VILLAGER_TRADE,
|
| 344 | () -> DSL.optionalFields("buy", References.ITEM_STACK.in(schema), "buyB", References.ITEM_STACK.in(schema), "sell", References.ITEM_STACK.in(schema))
|
| 345 | );
|
| 346 | schema.registerType(true, References.PARTICLE, () -> DSL.constType(DSL.string()));
|
| 347 | schema.registerType(true, References.TEXT_COMPONENT, () -> DSL.constType(DSL.string()));
|
| 348 | schema.registerType(
|
| 349 | false,
|
| 350 | References.STRUCTURE,
|
| 351 | () -> DSL.optionalFields(
|
| 352 | "entities",
|
| 353 | DSL.list(DSL.optionalFields("nbt", References.ENTITY_TREE.in(schema))),
|
| 354 | "blocks",
|
| 355 | DSL.list(DSL.optionalFields("nbt", References.BLOCK_ENTITY.in(schema))),
|
| 356 | "palette",
|
| 357 | DSL.list(References.BLOCK_STATE.in(schema)),
|
| 358 | "palettes",
|
| 359 | DSL.list(DSL.list(References.BLOCK_STATE.in(schema)))
|
| 360 | )
|
| 361 | );
|
| 362 | schema.registerType(false, References.BLOCK_STATE, DSL::remainder);
|
| 363 | schema.registerType(false, References.FLAT_BLOCK_STATE, DSL::remainder);
|
| 364 | schema.registerType(true, References.ENTITY_EQUIPMENT, () -> DSL.optional(DSL.field("Equipment", DSL.list(References.ITEM_STACK.in(schema)))));
|
| 365 | }
|
| 366 |
|
| 367 | public static TypeTemplate itemStackTag(final Schema schema) {
|
| 368 | return DSL.optionalFields(
|
| 369 | Pair.of("EntityTag", References.ENTITY_TREE.in(schema)),
|
| 370 | Pair.of("BlockEntityTag", References.BLOCK_ENTITY.in(schema)),
|
| 371 | Pair.of("CanDestroy", DSL.list(References.BLOCK_NAME.in(schema))),
|
| 372 | Pair.of("CanPlaceOn", DSL.list(References.BLOCK_NAME.in(schema))),
|
| 373 | Pair.of("Items", DSL.list(References.ITEM_STACK.in(schema))),
|
| 374 | Pair.of("ChargedProjectiles", DSL.list(References.ITEM_STACK.in(schema))),
|
| 375 | Pair.of("pages", DSL.list(References.TEXT_COMPONENT.in(schema))),
|
| 376 | Pair.of("filtered_pages", DSL.compoundList(References.TEXT_COMPONENT.in(schema))),
|
| 377 | Pair.of("display", DSL.optionalFields("Name", References.TEXT_COMPONENT.in(schema), "Lore", DSL.list(References.TEXT_COMPONENT.in(schema))))
|
| 378 | );
|
| 379 | }
|
| 380 |
|
| 381 | protected static <T> T addNames(final Dynamic<T> input, final Map<String, String> itemToBlockEntityMap, final Map<String, String> itemToEntityMap) {
|
| 382 | return input.update("tag", itemStackTag -> itemStackTag.update("BlockEntityTag", blockEntity -> {
|
| 383 | String itemId = input.get("id").asString().result().map(NamespacedSchema::ensureNamespaced).orElse("minecraft:air");
|
| 384 | if (!"minecraft:air".equals(itemId)) {
|
| 385 | String expectedId = itemToBlockEntityMap.get(itemId);
|
| 386 | if (expectedId != null) {
|
| 387 | return blockEntity.set("id", input.createString(expectedId));
|
| 388 | }
|
| 389 |
|
| 390 | LOGGER.warn("Unable to resolve BlockEntity for ItemStack: {}", itemId);
|
| 391 | }
|
| 392 |
|
| 393 | return blockEntity;
|
| 394 | }).update("EntityTag", entity -> {
|
| 395 | if (entity.get("id").result().isPresent()) {
|
| 396 | return entity;
|
| 397 | }
|
| 398 |
|
| 399 | String itemId = NamespacedSchema.ensureNamespaced(input.get("id").asString(""));
|
| 400 | String expectedId = itemToEntityMap.get(itemId);
|
| 401 | return expectedId != null ? entity.set("id", input.createString(expectedId)) : entity;
|
| 402 | })).getValue();
|
| 403 | }
|
| 404 | }
|
| 405 |
|