Fix <1.12 VB mapping files and a few long broken 1.13.2->1.13 items

This commit is contained in:
Nassim Jahnke 2023-03-06 10:52:53 +01:00
parent 8edf790a73
commit 5f8c9f00cc
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
21 changed files with 123 additions and 586 deletions

View File

@ -23,8 +23,12 @@ its own by starting the `MappingsOptimizer` class with the two arguments flipped
java -cp MappingsGenerator.jar com.viaversion.mappingsgenerator.MappingsOptimizer <from version> <to version>
```
Optionally, the `--generateDiffStubs` argument can be passed as a third argument to generate empty diff files for
missing mappings.
### Optional arguments
Optional arguments must follow the two version arguments.
* `--generateDiffStubs` to generate empty diff files for missing mappings
* `--keepUnknownFields` to keep non-standard fields from json mappings in the compact files
## Json format

View File

@ -19,5 +19,8 @@
"entity.wither_skeleton.death": "entity.skeleton.death",
"entity.wither_skeleton.hurt": "entity.skeleton.hurt",
"entity.wither_skeleton.step": "entity.skeleton.step"
},
"entitynames": {
"polar_bear": "Polar Bear"
}
}

View File

@ -31,5 +31,13 @@
"item.armor.equip_elytra": "item.armor.equip_generic",
"item.bottle.empty": "item.bottle.fill",
"item.totem.use": "block.anvil.destroy"
},
"entitynames": {
"stray": "Stray",
"husk": "Husk",
"evocation_illager": "Evoker",
"vex": "Vex",
"vindication_illager": "Vindicator",
"liama": "Llama"
}
}

View File

@ -48,5 +48,9 @@
"entity.parrot.step": "entity.chicken.step",
"entity.player.hurt_drown": "entity.player.hurt",
"entity.player.hurt_on_fire": "entity.player.hurt"
},
"entitynames": {
"parrot": "Parrot",
"illusion_illager": "Illusioner"
}
}

View File

@ -16,5 +16,29 @@
"fire_coral": "fire_coral",
"horn_coral": "horn_coral",
"conduit": "conduit"
},
"items": {
"smooth_stone_slab": "stone_slab",
"dead_brain_coral": "dead_brain_coral_block",
"dead_bubble_coral": "dead_bubble_coral_block",
"dead_fire_coral": "dead_fire_coral_block",
"dead_horn_coral": "dead_horn_coral_block",
"dead_tube_coral": "dead_tube_coral_block",
"oak_sign": "sign",
"red_dye": "rose_red",
"green_dye": "cactus_green",
"yellow_dye": "dandelion_yellow"
},
"itemnames": {
"smooth_stone_slab": "1.13.2 Smooth Stone Slab",
"dead_brain_coral": "1.13.2 Dead Brain Coral",
"dead_bubble_coral": "1.13.2 Dead Bubble Coral",
"dead_fire_coral": "1.13.2 Dead Fire Coral",
"dead_horn_coral": "1.13.2 Dead Horn Coral",
"dead_tube_coral": "1.13.2 Dead Tube Coral",
"oak_sign": "1.13.2 Oak Sign",
"red_dye": "1.13.2 Red Dye",
"green_dye": "1.13.2 Green Dye",
"yellow_dye": "1.13.2 Yellow Dye"
}
}

View File

@ -1,553 +0,0 @@
{
"sounds": [
"ambient.cave",
"block.anvil.break",
"block.anvil.destroy",
"block.anvil.fall",
"block.anvil.hit",
"block.anvil.land",
"block.anvil.place",
"block.anvil.step",
"block.anvil.use",
"block.brewing_stand.brew",
"block.chest.close",
"block.chest.locked",
"block.chest.open",
"block.chorus_flower.death",
"block.chorus_flower.grow",
"block.wool.break",
"block.wool.fall",
"block.wool.hit",
"block.wool.place",
"block.wool.step",
"block.comparator.click",
"block.dispenser.dispense",
"block.dispenser.fail",
"block.dispenser.launch",
"block.enchantment_table.use",
"block.end_gateway.spawn",
"block.end_portal.spawn",
"block.end_portal_frame.fill",
"block.ender_chest.close",
"block.ender_chest.open",
"block.fence_gate.close",
"block.fence_gate.open",
"block.fire.ambient",
"block.fire.extinguish",
"block.furnace.fire_crackle",
"block.glass.break",
"block.glass.fall",
"block.glass.hit",
"block.glass.place",
"block.glass.step",
"block.grass.break",
"block.grass.fall",
"block.grass.hit",
"block.grass.place",
"block.grass.step",
"block.gravel.break",
"block.gravel.fall",
"block.gravel.hit",
"block.gravel.place",
"block.gravel.step",
"block.iron_door.close",
"block.iron_door.open",
"block.iron_trapdoor.close",
"block.iron_trapdoor.open",
"block.ladder.break",
"block.ladder.fall",
"block.ladder.hit",
"block.ladder.place",
"block.ladder.step",
"block.lava.ambient",
"block.lava.extinguish",
"block.lava.pop",
"block.lever.click",
"block.metal.break",
"block.metal.fall",
"block.metal.hit",
"block.metal.place",
"block.metal.step",
"block.metal_pressure_plate.click_off",
"block.metal_pressure_plate.click_on",
"block.note_block.basedrum",
"block.note_block.bass",
"block.note_block.bell",
"block.note_block.chime",
"block.note_block.flute",
"block.note_block.guitar",
"block.note_block.harp",
"block.note_block.hat",
"block.note_block.pling",
"block.note_block.snare",
"block.note_block.xylophone",
"block.piston.contract",
"block.piston.extend",
"block.portal.ambient",
"block.portal.travel",
"block.portal.trigger",
"block.redstone_torch.burnout",
"block.sand.break",
"block.sand.fall",
"block.sand.hit",
"block.sand.place",
"block.sand.step",
"block.shulker_box.close",
"block.shulker_box.open",
"block.slime_block.break",
"block.slime_block.fall",
"block.slime_block.hit",
"block.slime_block.place",
"block.slime_block.step",
"block.snow.break",
"block.snow.fall",
"block.snow.hit",
"block.snow.place",
"block.snow.step",
"block.stone.break",
"block.stone.fall",
"block.stone.hit",
"block.stone.place",
"block.stone.step",
"block.stone_button.click_off",
"block.stone_button.click_on",
"block.stone_pressure_plate.click_off",
"block.stone_pressure_plate.click_on",
"block.tripwire.attach",
"block.tripwire.click_off",
"block.tripwire.click_on",
"block.tripwire.detach",
"block.water.ambient",
"block.lily_pad.place",
"block.wood.break",
"block.wood.fall",
"block.wood.hit",
"block.wood.place",
"block.wood.step",
"block.wooden_button.click_off",
"block.wooden_button.click_on",
"block.wooden_pressure_plate.click_off",
"block.wooden_pressure_plate.click_on",
"block.wooden_door.close",
"block.wooden_door.open",
"block.wooden_trapdoor.close",
"block.wooden_trapdoor.open",
"enchant.thorns.hit",
"entity.armor_stand.break",
"entity.armor_stand.fall",
"entity.armor_stand.hit",
"entity.armor_stand.place",
"entity.arrow.hit",
"entity.arrow.hit_player",
"entity.arrow.shoot",
"entity.bat.ambient",
"entity.bat.death",
"entity.bat.hurt",
"entity.bat.loop",
"entity.bat.takeoff",
"entity.blaze.ambient",
"entity.blaze.burn",
"entity.blaze.death",
"entity.blaze.hurt",
"entity.blaze.shoot",
"entity.boat.paddle_land",
"entity.boat.paddle_water",
"entity.fishing_bobber.retrieve",
"entity.fishing_bobber.splash",
"entity.fishing_bobber.throw",
"entity.cat.ambient",
"entity.cat.death",
"entity.cat.hiss",
"entity.cat.hurt",
"entity.cat.purr",
"entity.cat.purreow",
"entity.chicken.ambient",
"entity.chicken.death",
"entity.chicken.egg",
"entity.chicken.hurt",
"entity.chicken.step",
"entity.cow.ambient",
"entity.cow.death",
"entity.cow.hurt",
"entity.cow.milk",
"entity.cow.step",
"entity.creeper.death",
"entity.creeper.hurt",
"entity.creeper.primed",
"entity.donkey.ambient",
"entity.donkey.angry",
"entity.donkey.chest",
"entity.donkey.death",
"entity.donkey.hurt",
"entity.egg.throw",
"entity.elder_guardian.ambient",
"entity.elder_guardian.ambient_land",
"entity.elder_guardian.curse",
"entity.elder_guardian.death",
"entity.elder_guardian.death_land",
"entity.elder_guardian.flop",
"entity.elder_guardian.hurt",
"entity.elder_guardian.hurt_land",
"entity.ender_dragon.ambient",
"entity.ender_dragon.death",
"entity.ender_dragon.flap",
"entity.ender_dragon.growl",
"entity.ender_dragon.hurt",
"entity.ender_dragon.shoot",
"entity.dragon_fireball.explode",
"entity.ender_eye.death",
"entity.ender_eye.launch",
"entity.enderman.ambient",
"entity.enderman.death",
"entity.enderman.hurt",
"entity.enderman.scream",
"entity.enderman.stare",
"entity.enderman.teleport",
"entity.endermite.ambient",
"entity.endermite.death",
"entity.endermite.hurt",
"entity.endermite.step",
"entity.ender_pearl.throw",
"entity.evoker_fangs.attack",
"entity.evoker.ambient",
"entity.evoker.cast_spell",
"entity.evoker.death",
"entity.evoker.hurt",
"entity.evoker.prepare_attack",
"entity.evoker.prepare_summon",
"entity.evoker.prepare_wololo",
"entity.experience_bottle.throw",
"entity.experience_orb.pickup",
"entity.firework_rocket.blast",
"entity.firework_rocket.blast_far",
"entity.firework_rocket.large_blast",
"entity.firework_rocket.large_blast_far",
"entity.firework_rocket.launch",
"entity.firework_rocket.shoot",
"entity.firework_rocket.twinkle",
"entity.firework_rocket.twinkle_far",
"entity.generic.big_fall",
"entity.generic.burn",
"entity.generic.death",
"entity.generic.drink",
"entity.generic.eat",
"entity.generic.explode",
"entity.generic.extinguish_fire",
"entity.generic.hurt",
"entity.generic.small_fall",
"entity.generic.splash",
"entity.generic.swim",
"entity.ghast.ambient",
"entity.ghast.death",
"entity.ghast.hurt",
"entity.ghast.scream",
"entity.ghast.shoot",
"entity.ghast.warn",
"entity.guardian.ambient",
"entity.guardian.ambient_land",
"entity.guardian.attack",
"entity.guardian.death",
"entity.guardian.death_land",
"entity.guardian.flop",
"entity.guardian.hurt",
"entity.guardian.hurt_land",
"entity.horse.ambient",
"entity.horse.angry",
"entity.horse.armor",
"entity.horse.breathe",
"entity.horse.death",
"entity.horse.eat",
"entity.horse.gallop",
"entity.horse.hurt",
"entity.horse.jump",
"entity.horse.land",
"entity.horse.saddle",
"entity.horse.step",
"entity.horse.step_wood",
"entity.hostile.big_fall",
"entity.hostile.death",
"entity.hostile.hurt",
"entity.hostile.small_fall",
"entity.hostile.splash",
"entity.hostile.swim",
"entity.husk.ambient",
"entity.husk.death",
"entity.husk.hurt",
"entity.husk.step",
"entity.illusioner.ambient",
"entity.illusioner.cast_spell",
"entity.illusioner.death",
"entity.illusioner.hurt",
"entity.illusioner.mirror_move",
"entity.illusioner.prepare_blindness",
"entity.illusioner.prepare_mirror",
"entity.iron_golem.attack",
"entity.iron_golem.death",
"entity.iron_golem.hurt",
"entity.iron_golem.step",
"entity.item.break",
"entity.item.pickup",
"entity.item_frame.add_item",
"entity.item_frame.break",
"entity.item_frame.place",
"entity.item_frame.remove_item",
"entity.item_frame.rotate_item",
"entity.leash_knot.break",
"entity.leash_knot.place",
"entity.lightning_bolt.impact",
"entity.lightning_bolt.thunder",
"entity.lingering_potion.throw",
"entity.llama.ambient",
"entity.llama.angry",
"entity.llama.chest",
"entity.llama.death",
"entity.llama.eat",
"entity.llama.hurt",
"entity.llama.spit",
"entity.llama.step",
"entity.llama.swag",
"entity.magma_cube.death",
"entity.magma_cube.hurt",
"entity.magma_cube.jump",
"entity.magma_cube.squish",
"entity.minecart.inside",
"entity.minecart.riding",
"entity.mooshroom.shear",
"entity.mule.ambient",
"entity.mule.chest",
"entity.mule.death",
"entity.mule.hurt",
"entity.painting.break",
"entity.painting.place",
"entity.parrot.ambient",
"entity.parrot.death",
"entity.parrot.eat",
"entity.parrot.fly",
"entity.parrot.hurt",
"entity.parrot.imitate.blaze",
"entity.parrot.imitate.creeper",
"entity.parrot.imitate.elder_guardian",
"entity.parrot.imitate.ender_dragon",
"entity.parrot.imitate.enderman",
"entity.parrot.imitate.endermite",
"entity.parrot.imitate.evoker",
"entity.parrot.imitate.ghast",
"entity.parrot.imitate.husk",
"entity.parrot.imitate.illusioner",
"entity.parrot.imitate.magma_cube",
"entity.parrot.imitate.polar_bear",
"entity.parrot.imitate.shulker",
"entity.parrot.imitate.silverfish",
"entity.parrot.imitate.skeleton",
"entity.parrot.imitate.slime",
"entity.parrot.imitate.spider",
"entity.parrot.imitate.stray",
"entity.parrot.imitate.vex",
"entity.parrot.imitate.vindicator",
"entity.parrot.imitate.witch",
"entity.parrot.imitate.wither",
"entity.parrot.imitate.wither_skeleton",
"entity.parrot.imitate.wolf",
"entity.parrot.imitate.zombie",
"entity.parrot.imitate.zombie_pigman",
"entity.parrot.imitate.zombie_villager",
"entity.parrot.step",
"entity.pig.ambient",
"entity.pig.death",
"entity.pig.hurt",
"entity.pig.saddle",
"entity.pig.step",
"entity.player.attack.crit",
"entity.player.attack.knockback",
"entity.player.attack.nodamage",
"entity.player.attack.strong",
"entity.player.attack.sweep",
"entity.player.attack.weak",
"entity.player.big_fall",
"entity.player.breath",
"entity.player.burp",
"entity.player.death",
"entity.player.hurt",
"entity.player.hurt_drown",
"entity.player.hurt_on_fire",
"entity.player.levelup",
"entity.player.small_fall",
"entity.player.splash",
"entity.player.swim",
"entity.polar_bear.ambient",
"entity.polar_bear.ambient_baby",
"entity.polar_bear.death",
"entity.polar_bear.hurt",
"entity.polar_bear.step",
"entity.polar_bear.warning",
"entity.rabbit.ambient",
"entity.rabbit.attack",
"entity.rabbit.death",
"entity.rabbit.hurt",
"entity.rabbit.jump",
"entity.sheep.ambient",
"entity.sheep.death",
"entity.sheep.hurt",
"entity.sheep.shear",
"entity.sheep.step",
"entity.shulker.ambient",
"entity.shulker.close",
"entity.shulker.death",
"entity.shulker.hurt",
"entity.shulker.hurt_closed",
"entity.shulker.open",
"entity.shulker.shoot",
"entity.shulker.teleport",
"entity.shulker_bullet.hit",
"entity.shulker_bullet.hurt",
"entity.silverfish.ambient",
"entity.silverfish.death",
"entity.silverfish.hurt",
"entity.silverfish.step",
"entity.skeleton.ambient",
"entity.skeleton.death",
"entity.skeleton.hurt",
"entity.skeleton.shoot",
"entity.skeleton.step",
"entity.skeleton_horse.ambient",
"entity.skeleton_horse.death",
"entity.skeleton_horse.hurt",
"entity.slime.attack",
"entity.slime.death",
"entity.slime.hurt",
"entity.slime.jump",
"entity.slime.squish",
"entity.magma_cube.death_small",
"entity.magma_cube.hurt_small",
"entity.magma_cube.squish_small",
"entity.slime.death_small",
"entity.slime.hurt_small",
"entity.slime.jump_small",
"entity.slime.squish_small",
"entity.snowball.throw",
"entity.snow_golem.ambient",
"entity.snow_golem.death",
"entity.snow_golem.hurt",
"entity.snow_golem.shoot",
"entity.spider.ambient",
"entity.spider.death",
"entity.spider.hurt",
"entity.spider.step",
"entity.splash_potion.break",
"entity.splash_potion.throw",
"entity.squid.ambient",
"entity.squid.death",
"entity.squid.hurt",
"entity.stray.ambient",
"entity.stray.death",
"entity.stray.hurt",
"entity.stray.step",
"entity.tnt.primed",
"entity.vex.ambient",
"entity.vex.charge",
"entity.vex.death",
"entity.vex.hurt",
"entity.villager.ambient",
"entity.villager.death",
"entity.villager.hurt",
"entity.villager.no",
"entity.villager.trade",
"entity.villager.yes",
"entity.vindicator.ambient",
"entity.vindicator.death",
"entity.vindicator.hurt",
"entity.witch.ambient",
"entity.witch.death",
"entity.witch.drink",
"entity.witch.hurt",
"entity.witch.throw",
"entity.wither.ambient",
"entity.wither.break_block",
"entity.wither.death",
"entity.wither.hurt",
"entity.wither.shoot",
"entity.wither.spawn",
"entity.wither_skeleton.ambient",
"entity.wither_skeleton.death",
"entity.wither_skeleton.hurt",
"entity.wither_skeleton.step",
"entity.wolf.ambient",
"entity.wolf.death",
"entity.wolf.growl",
"entity.wolf.howl",
"entity.wolf.hurt",
"entity.wolf.pant",
"entity.wolf.shake",
"entity.wolf.step",
"entity.wolf.whine",
"entity.zombie.ambient",
"entity.zombie.attack_wooden_door",
"entity.zombie.attack_iron_door",
"entity.zombie.break_wooden_door",
"entity.zombie.death",
"entity.zombie.hurt",
"entity.zombie.infect",
"entity.zombie.step",
"entity.zombie_horse.ambient",
"entity.zombie_horse.death",
"entity.zombie_horse.hurt",
"entity.zombie_pigman.ambient",
"entity.zombie_pigman.angry",
"entity.zombie_pigman.death",
"entity.zombie_pigman.hurt",
"entity.zombie_villager.ambient",
"entity.zombie_villager.converted",
"entity.zombie_villager.cure",
"entity.zombie_villager.death",
"entity.zombie_villager.hurt",
"entity.zombie_villager.step",
"item.armor.equip_chain",
"item.armor.equip_diamond",
"item.armor.equip_elytra",
"item.armor.equip_generic",
"item.armor.equip_gold",
"item.armor.equip_iron",
"item.armor.equip_leather",
"item.bottle.empty",
"item.bottle.fill",
"item.bottle.fill_dragonbreath",
"item.bucket.empty",
"item.bucket.empty_lava",
"item.bucket.fill",
"item.bucket.fill_lava",
"item.chorus_fruit.teleport",
"item.elytra.flying",
"item.firecharge.use",
"item.flintandsteel.use",
"item.hoe.till",
"item.shield.block",
"item.shield.break",
"item.shovel.flatten",
"item.totem.use",
"music.creative",
"music.credits",
"music.dragon",
"music.end",
"music.game",
"music.menu",
"music.nether",
"music_disc.11",
"music_disc.13",
"music_disc.blocks",
"music_disc.cat",
"music_disc.chirp",
"music_disc.far",
"music_disc.mall",
"music_disc.mellohi",
"music_disc.stal",
"music_disc.strad",
"music_disc.wait",
"music_disc.ward",
"ui.button.click",
"ui.toast.in",
"ui.toast.out",
"ui.toast.challenge_complete",
"weather.rain",
"weather.rain.above"
]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -7,7 +7,7 @@
<groupId>com.viaversion</groupId>
<artifactId>mappingsgenerator</artifactId>
<name>MappingsGenerator</name>
<version>3.1.0</version>
<version>3.2.0</version>
<url>https://github.com/ViaVersion/Mappings</url>
<inceptionYear>2020</inceptionYear>

View File

@ -24,16 +24,18 @@ public final class CursedMappings {
public static void optimizeAndSaveOhSoSpecial1_12AsNBT() throws IOException {
final MappingsOptimizer optimizer = new MappingsOptimizer("1.12", "1.13");
optimizer.keepUnknownFields();
optimizer.handleUnknownFields();
optimizer.cursedMappings("blocks", "blockstates", "blockstates", 4084);
optimizer.cursedMappings("items", "items", "items");
optimizer.cursedMappings("legacy_enchantments", "enchantments", "enchantments", 72);
optimizer.mappings(true, false, "sounds");
optimizer.mappings(false, "sounds");
optimizer.write(MappingsOptimizer.OUTPUT_DIR);
}
public static void optimizeAndSaveOhSoSpecial1_12AsNBTBackwards() throws IOException {
final MappingsOptimizer optimizer = new MappingsOptimizer("1.13", "1.12");
optimizer.keepUnknownFields();
optimizer.handleUnknownFields();
optimizer.cursedMappings("blockstates", "blocks", "blockstates", 8582);
optimizer.cursedMappings("items", "items", "items");
@ -41,7 +43,7 @@ public final class CursedMappings {
optimizer.names("items", "itemnames");
optimizer.fullNames("entitynames", "entitynames");
optimizer.fullNames("sounds", "soundnames");
optimizer.mappings(true, false, "sounds");
optimizer.mappings(false, "sounds");
optimizer.write(MappingsOptimizer.OUTPUT_BACKWARDS_DIR);
}
}

View File

@ -24,12 +24,14 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class ManualRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(ManualRunner.class.getSimpleName());
private static final Set<String> SPECIAL_BACKWARDS_ONLY = Set.of("1.9.4", "1.10", "1.11");
private static final boolean ALL = true;
public static void main(final String[] args) throws IOException {
@ -38,15 +40,15 @@ public final class ManualRunner {
return;
}
final String from = "1.19";
final String to = "1.18";
final String from = "1.13.2";
final String to = "1.13";
MappingsOptimizer mappingsOptimizer = new MappingsOptimizer(from, to);
mappingsOptimizer.writeDiffStubs();
mappingsOptimizer.optimizeAndWrite();
mappingsOptimizer = new MappingsOptimizer(to, from);
mappingsOptimizer.writeDiffStubs();
mappingsOptimizer.optimizeAndWrite();
//mappingsOptimizer = new MappingsOptimizer(to, from);
//mappingsOptimizer.writeDiffStubs();
//mappingsOptimizer.optimizeAndWrite();
}
/**
@ -74,9 +76,18 @@ public final class ManualRunner {
continue;
}
new MappingsOptimizer(from, to).optimizeAndWrite();
LOGGER.info("-----------------------------");
new MappingsOptimizer(to, from).optimizeAndWrite();
final boolean special = SPECIAL_BACKWARDS_ONLY.contains(from);
if (!special) {
new MappingsOptimizer(from, to).optimizeAndWrite();
LOGGER.info("-----------------------------");
}
final MappingsOptimizer backwardsOptimizer = new MappingsOptimizer(to, from);
if (special) {
backwardsOptimizer.ignoreMissingMappingsFor("sounds");
}
backwardsOptimizer.optimizeAndWrite();
LOGGER.info("");
}
}

View File

@ -31,6 +31,7 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Set;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -131,7 +132,7 @@ public final class MappingsLoader {
final int dataIndex;
if (diffIdentifiers == null) {
if (warnOnMissing) {
LOGGER.warn("No key/diff file for {} :( ", value);
LOGGER.warn("No direct mapping or diff file for {} :( ", value);
}
return -1;
}
@ -167,7 +168,7 @@ public final class MappingsLoader {
}
if (mappedId == -1 && warnOnMissing) {
LOGGER.warn("No key for {} :( ", value);
LOGGER.warn("No diff entry for {} :( ", value);
}
return mappedId;
}
@ -178,13 +179,19 @@ public final class MappingsLoader {
* @param unmappedObject unmapped object
* @param mappedObject mapped object
* @param existingDiffObject existing diff object
* @param toIgnore fields to ignore missing mappings for
* @return diff object stub, or null if no diff is needed
*/
public static @Nullable JsonObject getDiffObjectStub(final JsonObject unmappedObject, final JsonObject mappedObject, @Nullable final JsonObject existingDiffObject) {
public static @Nullable JsonObject getDiffObjectStub(
final JsonObject unmappedObject,
final JsonObject mappedObject,
@Nullable final JsonObject existingDiffObject,
final Set<String> toIgnore
) {
final JsonObject diffObject = new JsonObject();
for (final Map.Entry<String, JsonElement> entry : unmappedObject.entrySet()) {
final String key = entry.getKey();
if (!entry.getValue().isJsonArray() || !mappedObject.has(key) || key.equals("blocks")) { // Special case!
if (!entry.getValue().isJsonArray() || !mappedObject.has(key) || toIgnore.contains(key)) {
continue;
}

View File

@ -66,12 +66,14 @@ public final class MappingsOptimizer {
private static final Set<String> STANDARD_FIELDS = Set.of("blockstates", "blocks", "items", "sounds", "blockentities", "enchantments", "paintings", "entities", "particles", "argumenttypes", "statistics", "tags");
private static final Set<String> SAVED_IDENTIFIER_FILES = new HashSet<>();
private final Set<String> ignoreMissing = new HashSet<>(Arrays.asList("blocks", "statistics"));
private final CompoundTag output;
private final String fromVersion;
private final String toVersion;
private final JsonObject unmappedObject;
private final JsonObject mappedObject;
private JsonObject diffObject;
private boolean keepUnknownFields;
public static void main(final String[] args) throws IOException {
if (args.length < 2) {
@ -90,6 +92,9 @@ public final class MappingsOptimizer {
if (argsSet.contains("--generateDiffStubs")) {
optimizer.writeDiffStubs();
}
if (argsSet.contains("--keepUnknownFields")) {
optimizer.keepUnknownFields();
}
optimizer.optimizeAndWrite();
}
@ -125,19 +130,21 @@ public final class MappingsOptimizer {
public void optimizeAndWrite() throws IOException {
LOGGER.info("Compacting json mapping files for versions {} → {}...", fromVersion, toVersion);
handleUnknownFields();
if (keepUnknownFields) {
handleUnknownFields();
}
mappings(true, true, "blockstates");
mappings(false, false, "blocks");
mappings(true, false, "items");
mappings(true, false, "sounds");
mappings(true, false, "blockentities");
mappings(true, false, "enchantments");
mappings(true, false, "paintings");
mappings(true, false, "entities");
mappings(true, false, "particles");
mappings(true, false, "argumenttypes");
mappings(false, false, "statistics");
mappings(true, "blockstates");
mappings(false, "blocks");
mappings(false, "items");
mappings(false, "sounds");
mappings(false, "blockentities");
mappings(false, "enchantments");
mappings(false, "paintings");
mappings(false, "entities");
mappings(false, "particles");
mappings(false, "argumenttypes");
mappings(false, "statistics");
if (diffObject != null) {
names("items", "itemnames");
@ -166,7 +173,7 @@ public final class MappingsOptimizer {
* @return true if the diff stubs were written, false if they were not written because there were no changes
*/
public boolean writeDiffStubs() throws IOException {
final JsonObject diffObject = MappingsLoader.getDiffObjectStub(unmappedObject, mappedObject, this.diffObject);
final JsonObject diffObject = MappingsLoader.getDiffObjectStub(unmappedObject, mappedObject, this.diffObject, ignoreMissing);
if (diffObject != null) {
LOGGER.info("Writing diff stubs for versions {} → {}", fromVersion, toVersion);
Files.writeString(MAPPINGS_DIR.resolve(DIFF_FILE_FORMAT.formatted(fromVersion, toVersion)), MappingsGenerator.GSON.toJson(diffObject));
@ -176,6 +183,22 @@ public final class MappingsOptimizer {
return false;
}
/**
* Prevents warnings for missing diff mappings for the given key from being printed and does not include stubs in {@link #writeDiffStubs()}.
*
* @param key key to ignore missing mappings for
*/
public void ignoreMissingMappingsFor(final String key) {
ignoreMissing.add(key);
}
/**
* Writing mappings will keep non-standard fields unchanged into the output file.
*/
public void keepUnknownFields() {
this.keepUnknownFields = true;
}
/**
* Writes the current mappings output as an NBT file into the given directory.
*
@ -213,11 +236,10 @@ public final class MappingsOptimizer {
/**
* Reads mappings from the unmapped and mapped objects and writes them to the nbt tag.
*
* @param warnOnMissing whether to warn on missing mappings
* @param alwaysWriteIdentity whether to always write the identity mapping with size and mapped size, even if the two arrays are equal
* @param key to read from and write to
*/
public void mappings(final boolean warnOnMissing, final boolean alwaysWriteIdentity, final String key) {
public void mappings(final boolean alwaysWriteIdentity, final String key) {
if (!unmappedObject.has(key) || !mappedObject.has(key)
|| !unmappedObject.get(key).isJsonArray() || !mappedObject.get(key).isJsonArray()) {
return;
@ -230,11 +252,16 @@ public final class MappingsOptimizer {
return;
}
LOGGER.debug("Mapping {}: {} → {}", key, unmappedIdentifiers.size(), mappedIdentifiers.size());
final JsonObject diffIdentifiers = diffObject != null ? diffObject.getAsJsonObject(key) : null;
final MappingsResult result = MappingsLoader.map(unmappedIdentifiers, mappedIdentifiers, diffIdentifiers, warnOnMissing);
final MappingsResult result = MappingsLoader.map(unmappedIdentifiers, mappedIdentifiers, diffIdentifiers, shouldWarn(key));
serialize(result, output, key, alwaysWriteIdentity);
}
private boolean shouldWarn(final String key) {
return !ignoreMissing.contains(key);
}
public void cursedMappings(final String unmappedKey, final String mappedKey, final String outputKey) {
final JsonElement element = unmappedObject.get(unmappedKey);
cursedMappings(unmappedKey, mappedKey, outputKey, element.isJsonArray() ? element.getAsJsonArray().size() : element.getAsJsonObject().size());