| 1 | package net.minecraft.util.datafix.fixes;
|
| 2 |
|
| 3 | import com.mojang.datafixers.DSL;
|
| 4 | import com.mojang.datafixers.DataFix;
|
| 5 | import com.mojang.datafixers.DataFixUtils;
|
| 6 | import com.mojang.datafixers.OpticFinder;
|
| 7 | import com.mojang.datafixers.TypeRewriteRule;
|
| 8 | import com.mojang.datafixers.schemas.Schema;
|
| 9 | import com.mojang.datafixers.types.Type;
|
| 10 | import com.mojang.datafixers.util.Either;
|
| 11 | import com.mojang.datafixers.util.Pair;
|
| 12 | import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
| 13 | import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
| 14 | import net.minecraft.util.datafix.schemas.NamespacedSchema;
|
| 15 |
|
| 16 | public class ItemIdFix extends DataFix {
|
| 17 | private static final Int2ObjectMap<String> ITEM_NAMES = DataFixUtils.make(new Int2ObjectOpenHashMap<>(), map -> {
|
| 18 | map.put(1, "minecraft:stone");
|
| 19 | map.put(2, "minecraft:grass");
|
| 20 | map.put(3, "minecraft:dirt");
|
| 21 | map.put(4, "minecraft:cobblestone");
|
| 22 | map.put(5, "minecraft:planks");
|
| 23 | map.put(6, "minecraft:sapling");
|
| 24 | map.put(7, "minecraft:bedrock");
|
| 25 | map.put(8, "minecraft:flowing_water");
|
| 26 | map.put(9, "minecraft:water");
|
| 27 | map.put(10, "minecraft:flowing_lava");
|
| 28 | map.put(11, "minecraft:lava");
|
| 29 | map.put(12, "minecraft:sand");
|
| 30 | map.put(13, "minecraft:gravel");
|
| 31 | map.put(14, "minecraft:gold_ore");
|
| 32 | map.put(15, "minecraft:iron_ore");
|
| 33 | map.put(16, "minecraft:coal_ore");
|
| 34 | map.put(17, "minecraft:log");
|
| 35 | map.put(18, "minecraft:leaves");
|
| 36 | map.put(19, "minecraft:sponge");
|
| 37 | map.put(20, "minecraft:glass");
|
| 38 | map.put(21, "minecraft:lapis_ore");
|
| 39 | map.put(22, "minecraft:lapis_block");
|
| 40 | map.put(23, "minecraft:dispenser");
|
| 41 | map.put(24, "minecraft:sandstone");
|
| 42 | map.put(25, "minecraft:noteblock");
|
| 43 | map.put(27, "minecraft:golden_rail");
|
| 44 | map.put(28, "minecraft:detector_rail");
|
| 45 | map.put(29, "minecraft:sticky_piston");
|
| 46 | map.put(30, "minecraft:web");
|
| 47 | map.put(31, "minecraft:tallgrass");
|
| 48 | map.put(32, "minecraft:deadbush");
|
| 49 | map.put(33, "minecraft:piston");
|
| 50 | map.put(35, "minecraft:wool");
|
| 51 | map.put(37, "minecraft:yellow_flower");
|
| 52 | map.put(38, "minecraft:red_flower");
|
| 53 | map.put(39, "minecraft:brown_mushroom");
|
| 54 | map.put(40, "minecraft:red_mushroom");
|
| 55 | map.put(41, "minecraft:gold_block");
|
| 56 | map.put(42, "minecraft:iron_block");
|
| 57 | map.put(43, "minecraft:double_stone_slab");
|
| 58 | map.put(44, "minecraft:stone_slab");
|
| 59 | map.put(45, "minecraft:brick_block");
|
| 60 | map.put(46, "minecraft:tnt");
|
| 61 | map.put(47, "minecraft:bookshelf");
|
| 62 | map.put(48, "minecraft:mossy_cobblestone");
|
| 63 | map.put(49, "minecraft:obsidian");
|
| 64 | map.put(50, "minecraft:torch");
|
| 65 | map.put(51, "minecraft:fire");
|
| 66 | map.put(52, "minecraft:mob_spawner");
|
| 67 | map.put(53, "minecraft:oak_stairs");
|
| 68 | map.put(54, "minecraft:chest");
|
| 69 | map.put(56, "minecraft:diamond_ore");
|
| 70 | map.put(57, "minecraft:diamond_block");
|
| 71 | map.put(58, "minecraft:crafting_table");
|
| 72 | map.put(60, "minecraft:farmland");
|
| 73 | map.put(61, "minecraft:furnace");
|
| 74 | map.put(62, "minecraft:lit_furnace");
|
| 75 | map.put(65, "minecraft:ladder");
|
| 76 | map.put(66, "minecraft:rail");
|
| 77 | map.put(67, "minecraft:stone_stairs");
|
| 78 | map.put(69, "minecraft:lever");
|
| 79 | map.put(70, "minecraft:stone_pressure_plate");
|
| 80 | map.put(72, "minecraft:wooden_pressure_plate");
|
| 81 | map.put(73, "minecraft:redstone_ore");
|
| 82 | map.put(76, "minecraft:redstone_torch");
|
| 83 | map.put(77, "minecraft:stone_button");
|
| 84 | map.put(78, "minecraft:snow_layer");
|
| 85 | map.put(79, "minecraft:ice");
|
| 86 | map.put(80, "minecraft:snow");
|
| 87 | map.put(81, "minecraft:cactus");
|
| 88 | map.put(82, "minecraft:clay");
|
| 89 | map.put(84, "minecraft:jukebox");
|
| 90 | map.put(85, "minecraft:fence");
|
| 91 | map.put(86, "minecraft:pumpkin");
|
| 92 | map.put(87, "minecraft:netherrack");
|
| 93 | map.put(88, "minecraft:soul_sand");
|
| 94 | map.put(89, "minecraft:glowstone");
|
| 95 | map.put(90, "minecraft:portal");
|
| 96 | map.put(91, "minecraft:lit_pumpkin");
|
| 97 | map.put(95, "minecraft:stained_glass");
|
| 98 | map.put(96, "minecraft:trapdoor");
|
| 99 | map.put(97, "minecraft:monster_egg");
|
| 100 | map.put(98, "minecraft:stonebrick");
|
| 101 | map.put(99, "minecraft:brown_mushroom_block");
|
| 102 | map.put(100, "minecraft:red_mushroom_block");
|
| 103 | map.put(101, "minecraft:iron_bars");
|
| 104 | map.put(102, "minecraft:glass_pane");
|
| 105 | map.put(103, "minecraft:melon_block");
|
| 106 | map.put(106, "minecraft:vine");
|
| 107 | map.put(107, "minecraft:fence_gate");
|
| 108 | map.put(108, "minecraft:brick_stairs");
|
| 109 | map.put(109, "minecraft:stone_brick_stairs");
|
| 110 | map.put(110, "minecraft:mycelium");
|
| 111 | map.put(111, "minecraft:waterlily");
|
| 112 | map.put(112, "minecraft:nether_brick");
|
| 113 | map.put(113, "minecraft:nether_brick_fence");
|
| 114 | map.put(114, "minecraft:nether_brick_stairs");
|
| 115 | map.put(116, "minecraft:enchanting_table");
|
| 116 | map.put(119, "minecraft:end_portal");
|
| 117 | map.put(120, "minecraft:end_portal_frame");
|
| 118 | map.put(121, "minecraft:end_stone");
|
| 119 | map.put(122, "minecraft:dragon_egg");
|
| 120 | map.put(123, "minecraft:redstone_lamp");
|
| 121 | map.put(125, "minecraft:double_wooden_slab");
|
| 122 | map.put(126, "minecraft:wooden_slab");
|
| 123 | map.put(127, "minecraft:cocoa");
|
| 124 | map.put(128, "minecraft:sandstone_stairs");
|
| 125 | map.put(129, "minecraft:emerald_ore");
|
| 126 | map.put(130, "minecraft:ender_chest");
|
| 127 | map.put(131, "minecraft:tripwire_hook");
|
| 128 | map.put(133, "minecraft:emerald_block");
|
| 129 | map.put(134, "minecraft:spruce_stairs");
|
| 130 | map.put(135, "minecraft:birch_stairs");
|
| 131 | map.put(136, "minecraft:jungle_stairs");
|
| 132 | map.put(137, "minecraft:command_block");
|
| 133 | map.put(138, "minecraft:beacon");
|
| 134 | map.put(139, "minecraft:cobblestone_wall");
|
| 135 | map.put(141, "minecraft:carrots");
|
| 136 | map.put(142, "minecraft:potatoes");
|
| 137 | map.put(143, "minecraft:wooden_button");
|
| 138 | map.put(145, "minecraft:anvil");
|
| 139 | map.put(146, "minecraft:trapped_chest");
|
| 140 | map.put(147, "minecraft:light_weighted_pressure_plate");
|
| 141 | map.put(148, "minecraft:heavy_weighted_pressure_plate");
|
| 142 | map.put(151, "minecraft:daylight_detector");
|
| 143 | map.put(152, "minecraft:redstone_block");
|
| 144 | map.put(153, "minecraft:quartz_ore");
|
| 145 | map.put(154, "minecraft:hopper");
|
| 146 | map.put(155, "minecraft:quartz_block");
|
| 147 | map.put(156, "minecraft:quartz_stairs");
|
| 148 | map.put(157, "minecraft:activator_rail");
|
| 149 | map.put(158, "minecraft:dropper");
|
| 150 | map.put(159, "minecraft:stained_hardened_clay");
|
| 151 | map.put(160, "minecraft:stained_glass_pane");
|
| 152 | map.put(161, "minecraft:leaves2");
|
| 153 | map.put(162, "minecraft:log2");
|
| 154 | map.put(163, "minecraft:acacia_stairs");
|
| 155 | map.put(164, "minecraft:dark_oak_stairs");
|
| 156 | map.put(170, "minecraft:hay_block");
|
| 157 | map.put(171, "minecraft:carpet");
|
| 158 | map.put(172, "minecraft:hardened_clay");
|
| 159 | map.put(173, "minecraft:coal_block");
|
| 160 | map.put(174, "minecraft:packed_ice");
|
| 161 | map.put(175, "minecraft:double_plant");
|
| 162 | map.put(256, "minecraft:iron_shovel");
|
| 163 | map.put(257, "minecraft:iron_pickaxe");
|
| 164 | map.put(258, "minecraft:iron_axe");
|
| 165 | map.put(259, "minecraft:flint_and_steel");
|
| 166 | map.put(260, "minecraft:apple");
|
| 167 | map.put(261, "minecraft:bow");
|
| 168 | map.put(262, "minecraft:arrow");
|
| 169 | map.put(263, "minecraft:coal");
|
| 170 | map.put(264, "minecraft:diamond");
|
| 171 | map.put(265, "minecraft:iron_ingot");
|
| 172 | map.put(266, "minecraft:gold_ingot");
|
| 173 | map.put(267, "minecraft:iron_sword");
|
| 174 | map.put(268, "minecraft:wooden_sword");
|
| 175 | map.put(269, "minecraft:wooden_shovel");
|
| 176 | map.put(270, "minecraft:wooden_pickaxe");
|
| 177 | map.put(271, "minecraft:wooden_axe");
|
| 178 | map.put(272, "minecraft:stone_sword");
|
| 179 | map.put(273, "minecraft:stone_shovel");
|
| 180 | map.put(274, "minecraft:stone_pickaxe");
|
| 181 | map.put(275, "minecraft:stone_axe");
|
| 182 | map.put(276, "minecraft:diamond_sword");
|
| 183 | map.put(277, "minecraft:diamond_shovel");
|
| 184 | map.put(278, "minecraft:diamond_pickaxe");
|
| 185 | map.put(279, "minecraft:diamond_axe");
|
| 186 | map.put(280, "minecraft:stick");
|
| 187 | map.put(281, "minecraft:bowl");
|
| 188 | map.put(282, "minecraft:mushroom_stew");
|
| 189 | map.put(283, "minecraft:golden_sword");
|
| 190 | map.put(284, "minecraft:golden_shovel");
|
| 191 | map.put(285, "minecraft:golden_pickaxe");
|
| 192 | map.put(286, "minecraft:golden_axe");
|
| 193 | map.put(287, "minecraft:string");
|
| 194 | map.put(288, "minecraft:feather");
|
| 195 | map.put(289, "minecraft:gunpowder");
|
| 196 | map.put(290, "minecraft:wooden_hoe");
|
| 197 | map.put(291, "minecraft:stone_hoe");
|
| 198 | map.put(292, "minecraft:iron_hoe");
|
| 199 | map.put(293, "minecraft:diamond_hoe");
|
| 200 | map.put(294, "minecraft:golden_hoe");
|
| 201 | map.put(295, "minecraft:wheat_seeds");
|
| 202 | map.put(296, "minecraft:wheat");
|
| 203 | map.put(297, "minecraft:bread");
|
| 204 | map.put(298, "minecraft:leather_helmet");
|
| 205 | map.put(299, "minecraft:leather_chestplate");
|
| 206 | map.put(300, "minecraft:leather_leggings");
|
| 207 | map.put(301, "minecraft:leather_boots");
|
| 208 | map.put(302, "minecraft:chainmail_helmet");
|
| 209 | map.put(303, "minecraft:chainmail_chestplate");
|
| 210 | map.put(304, "minecraft:chainmail_leggings");
|
| 211 | map.put(305, "minecraft:chainmail_boots");
|
| 212 | map.put(306, "minecraft:iron_helmet");
|
| 213 | map.put(307, "minecraft:iron_chestplate");
|
| 214 | map.put(308, "minecraft:iron_leggings");
|
| 215 | map.put(309, "minecraft:iron_boots");
|
| 216 | map.put(310, "minecraft:diamond_helmet");
|
| 217 | map.put(311, "minecraft:diamond_chestplate");
|
| 218 | map.put(312, "minecraft:diamond_leggings");
|
| 219 | map.put(313, "minecraft:diamond_boots");
|
| 220 | map.put(314, "minecraft:golden_helmet");
|
| 221 | map.put(315, "minecraft:golden_chestplate");
|
| 222 | map.put(316, "minecraft:golden_leggings");
|
| 223 | map.put(317, "minecraft:golden_boots");
|
| 224 | map.put(318, "minecraft:flint");
|
| 225 | map.put(319, "minecraft:porkchop");
|
| 226 | map.put(320, "minecraft:cooked_porkchop");
|
| 227 | map.put(321, "minecraft:painting");
|
| 228 | map.put(322, "minecraft:golden_apple");
|
| 229 | map.put(323, "minecraft:sign");
|
| 230 | map.put(324, "minecraft:wooden_door");
|
| 231 | map.put(325, "minecraft:bucket");
|
| 232 | map.put(326, "minecraft:water_bucket");
|
| 233 | map.put(327, "minecraft:lava_bucket");
|
| 234 | map.put(328, "minecraft:minecart");
|
| 235 | map.put(329, "minecraft:saddle");
|
| 236 | map.put(330, "minecraft:iron_door");
|
| 237 | map.put(331, "minecraft:redstone");
|
| 238 | map.put(332, "minecraft:snowball");
|
| 239 | map.put(333, "minecraft:boat");
|
| 240 | map.put(334, "minecraft:leather");
|
| 241 | map.put(335, "minecraft:milk_bucket");
|
| 242 | map.put(336, "minecraft:brick");
|
| 243 | map.put(337, "minecraft:clay_ball");
|
| 244 | map.put(338, "minecraft:reeds");
|
| 245 | map.put(339, "minecraft:paper");
|
| 246 | map.put(340, "minecraft:book");
|
| 247 | map.put(341, "minecraft:slime_ball");
|
| 248 | map.put(342, "minecraft:chest_minecart");
|
| 249 | map.put(343, "minecraft:furnace_minecart");
|
| 250 | map.put(344, "minecraft:egg");
|
| 251 | map.put(345, "minecraft:compass");
|
| 252 | map.put(346, "minecraft:fishing_rod");
|
| 253 | map.put(347, "minecraft:clock");
|
| 254 | map.put(348, "minecraft:glowstone_dust");
|
| 255 | map.put(349, "minecraft:fish");
|
| 256 | map.put(350, "minecraft:cooked_fished");
|
| 257 | map.put(351, "minecraft:dye");
|
| 258 | map.put(352, "minecraft:bone");
|
| 259 | map.put(353, "minecraft:sugar");
|
| 260 | map.put(354, "minecraft:cake");
|
| 261 | map.put(355, "minecraft:bed");
|
| 262 | map.put(356, "minecraft:repeater");
|
| 263 | map.put(357, "minecraft:cookie");
|
| 264 | map.put(358, "minecraft:filled_map");
|
| 265 | map.put(359, "minecraft:shears");
|
| 266 | map.put(360, "minecraft:melon");
|
| 267 | map.put(361, "minecraft:pumpkin_seeds");
|
| 268 | map.put(362, "minecraft:melon_seeds");
|
| 269 | map.put(363, "minecraft:beef");
|
| 270 | map.put(364, "minecraft:cooked_beef");
|
| 271 | map.put(365, "minecraft:chicken");
|
| 272 | map.put(366, "minecraft:cooked_chicken");
|
| 273 | map.put(367, "minecraft:rotten_flesh");
|
| 274 | map.put(368, "minecraft:ender_pearl");
|
| 275 | map.put(369, "minecraft:blaze_rod");
|
| 276 | map.put(370, "minecraft:ghast_tear");
|
| 277 | map.put(371, "minecraft:gold_nugget");
|
| 278 | map.put(372, "minecraft:nether_wart");
|
| 279 | map.put(373, "minecraft:potion");
|
| 280 | map.put(374, "minecraft:glass_bottle");
|
| 281 | map.put(375, "minecraft:spider_eye");
|
| 282 | map.put(376, "minecraft:fermented_spider_eye");
|
| 283 | map.put(377, "minecraft:blaze_powder");
|
| 284 | map.put(378, "minecraft:magma_cream");
|
| 285 | map.put(379, "minecraft:brewing_stand");
|
| 286 | map.put(380, "minecraft:cauldron");
|
| 287 | map.put(381, "minecraft:ender_eye");
|
| 288 | map.put(382, "minecraft:speckled_melon");
|
| 289 | map.put(383, "minecraft:spawn_egg");
|
| 290 | map.put(384, "minecraft:experience_bottle");
|
| 291 | map.put(385, "minecraft:fire_charge");
|
| 292 | map.put(386, "minecraft:writable_book");
|
| 293 | map.put(387, "minecraft:written_book");
|
| 294 | map.put(388, "minecraft:emerald");
|
| 295 | map.put(389, "minecraft:item_frame");
|
| 296 | map.put(390, "minecraft:flower_pot");
|
| 297 | map.put(391, "minecraft:carrot");
|
| 298 | map.put(392, "minecraft:potato");
|
| 299 | map.put(393, "minecraft:baked_potato");
|
| 300 | map.put(394, "minecraft:poisonous_potato");
|
| 301 | map.put(395, "minecraft:map");
|
| 302 | map.put(396, "minecraft:golden_carrot");
|
| 303 | map.put(397, "minecraft:skull");
|
| 304 | map.put(398, "minecraft:carrot_on_a_stick");
|
| 305 | map.put(399, "minecraft:nether_star");
|
| 306 | map.put(400, "minecraft:pumpkin_pie");
|
| 307 | map.put(401, "minecraft:fireworks");
|
| 308 | map.put(402, "minecraft:firework_charge");
|
| 309 | map.put(403, "minecraft:enchanted_book");
|
| 310 | map.put(404, "minecraft:comparator");
|
| 311 | map.put(405, "minecraft:netherbrick");
|
| 312 | map.put(406, "minecraft:quartz");
|
| 313 | map.put(407, "minecraft:tnt_minecart");
|
| 314 | map.put(408, "minecraft:hopper_minecart");
|
| 315 | map.put(417, "minecraft:iron_horse_armor");
|
| 316 | map.put(418, "minecraft:golden_horse_armor");
|
| 317 | map.put(419, "minecraft:diamond_horse_armor");
|
| 318 | map.put(420, "minecraft:lead");
|
| 319 | map.put(421, "minecraft:name_tag");
|
| 320 | map.put(422, "minecraft:command_block_minecart");
|
| 321 | map.put(2256, "minecraft:record_13");
|
| 322 | map.put(2257, "minecraft:record_cat");
|
| 323 | map.put(2258, "minecraft:record_blocks");
|
| 324 | map.put(2259, "minecraft:record_chirp");
|
| 325 | map.put(2260, "minecraft:record_far");
|
| 326 | map.put(2261, "minecraft:record_mall");
|
| 327 | map.put(2262, "minecraft:record_mellohi");
|
| 328 | map.put(2263, "minecraft:record_stal");
|
| 329 | map.put(2264, "minecraft:record_strad");
|
| 330 | map.put(2265, "minecraft:record_ward");
|
| 331 | map.put(2266, "minecraft:record_11");
|
| 332 | map.put(2267, "minecraft:record_wait");
|
| 333 | map.defaultReturnValue("minecraft:air");
|
| 334 | });
|
| 335 |
|
| 336 | public ItemIdFix(final Schema outputSchema, final boolean changesType) {
|
| 337 | super(outputSchema, changesType);
|
| 338 | }
|
| 339 |
|
| 340 | public static String getItem(final int id) {
|
| 341 | return ITEM_NAMES.get(id);
|
| 342 | }
|
| 343 |
|
| 344 | @Override
|
| 345 | public TypeRewriteRule makeRule() {
|
| 346 | Type<Either<Integer, Pair<String, String>>> oldItemType = DSL.or(
|
| 347 | DSL.intType(), DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString())
|
| 348 | );
|
| 349 | Type<Pair<String, String>> newItemType = DSL.named(References.ITEM_NAME.typeName(), NamespacedSchema.namespacedString());
|
| 350 | OpticFinder<Either<Integer, Pair<String, String>>> id = DSL.fieldFinder("id", oldItemType);
|
| 351 | return this.fixTypeEverywhereTyped(
|
| 352 | "ItemIdFix",
|
| 353 | this.getInputSchema().getType(References.ITEM_STACK),
|
| 354 | this.getOutputSchema().getType(References.ITEM_STACK),
|
| 355 | itemStack -> itemStack.update(id, newItemType, oldId -> oldId.map(l -> Pair.of(References.ITEM_NAME.typeName(), getItem(l)), r -> r))
|
| 356 | );
|
| 357 | }
|
| 358 | }
|
| 359 |
|