Add generation code and mapping files for ViaAprilFools (#18)
This commit is contained in:
parent
a04024a9db
commit
1f02b4d785
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"blockstates": {
|
||||
"soul_fire_torch": "soul_torch",
|
||||
"soul_fire_wall_torch": "soul_wall_torch[",
|
||||
"netherite_stairs": "blackstone_stairs[",
|
||||
"cursor": "lime_concrete",
|
||||
"zone": "moving_piston[facing=north,type=normal]",
|
||||
"ant[facing=north]": "magenta_glazed_terracotta[facing=south]",
|
||||
"ant[facing=south]": "magenta_glazed_terracotta[facing=north]",
|
||||
"ant[facing=west]": "magenta_glazed_terracotta[facing=east]",
|
||||
"ant[facing=east]": "magenta_glazed_terracotta[facing=west]",
|
||||
"neither_portal": "nether_portal[",
|
||||
"soul_fire_lantern": "soul_lantern[",
|
||||
"book_box[facing=north]": "bookshelf",
|
||||
"book_box[facing=south]": "bookshelf",
|
||||
"book_box[facing=west]": "bookshelf",
|
||||
"book_box[facing=east]": "bookshelf"
|
||||
},
|
||||
"items": {
|
||||
"soul_fire_torch": "soul_torch",
|
||||
"soul_fire_lantern": "soul_lantern",
|
||||
"netherite_stairs": "blackstone_stairs",
|
||||
"book_box": "bookshelf",
|
||||
"footprint": "gray_stained_glass_pane",
|
||||
"cursor": "lime_concrete",
|
||||
"fine_item": "paper"
|
||||
},
|
||||
"sounds": {
|
||||
"nothingtoseeheremovealong:awesome_intro": "entity.dragon_fireball.explode",
|
||||
"music.nether": ""
|
||||
},
|
||||
"itemnames": {
|
||||
"soul_fire_torch": "20w14infinite Soul Fire Torch",
|
||||
"soul_fire_lantern": "20w14infinite Soul Fire Latern",
|
||||
"netherite_stairs": "20w14infinite Netherite Stairs",
|
||||
"book_box": "20w14infinite Box of Infinite Books",
|
||||
"footprint": "20w14infinite Footprint",
|
||||
"cursor": "20w14infinite Cursor",
|
||||
"fine_item": "20w14infinite Fine Item"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"items": {
|
||||
"red_key": "tripwire_hook",
|
||||
"blue_key": "tripwire_hook",
|
||||
"yellow_key": "tripwire_hook",
|
||||
"3d": "golden_carrot"
|
||||
},
|
||||
"sounds": {
|
||||
"awesome_intro": "entity.dragon_fireball.explode"
|
||||
},
|
||||
"itemnames": {
|
||||
"red_key": "3D Shareware Red Key",
|
||||
"blue_key": "3D Shareware Blue Key",
|
||||
"yellow_key": "3D Shareware Yellow Key",
|
||||
"3d": "3D Shareware 3D"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -24,11 +24,19 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class ManualRunner {
|
||||
|
||||
private static final Set<String> SPECIAL_BACKWARDS_ONLY = Set.of("1.9.4", "1.10", "1.11");
|
||||
|
||||
// April Fool version -> Release version
|
||||
private static final Map<String, String> SPECIAL_VERSIONS = Map.of(
|
||||
"3D_Shareware", "1.14",
|
||||
"20w14infinite", "1.16"
|
||||
);
|
||||
|
||||
private static final boolean ALL = true;
|
||||
|
||||
public static void main(final String[] args) throws IOException {
|
||||
|
@ -87,6 +95,12 @@ public final class ManualRunner {
|
|||
|
||||
backwardsOptimizer.optimizeAndWrite();
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> entry : SPECIAL_VERSIONS.entrySet()) {
|
||||
final MappingsOptimizer mappingsOptimizer = new MappingsOptimizer(entry.getKey(), entry.getValue(), true);
|
||||
mappingsOptimizer.setErrorStrategy(errorStrategy);
|
||||
mappingsOptimizer.optimizeAndWrite();
|
||||
}
|
||||
}
|
||||
|
||||
private static void runMappingsGen() throws Exception {
|
||||
|
|
|
@ -27,11 +27,13 @@ import it.unimi.dsi.fastutil.ints.Int2IntLinkedOpenHashMap;
|
|||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
|
||||
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;
|
||||
|
@ -41,14 +43,20 @@ public final class MappingsLoader {
|
|||
public static final Logger LOGGER = LoggerFactory.getLogger(MappingsLoader.class.getSimpleName());
|
||||
private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
|
||||
|
||||
|
||||
public static @Nullable JsonObject load(final String name) throws IOException {
|
||||
return load(MappingsOptimizer.MAPPINGS_DIR, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and return the json mappings file.
|
||||
*
|
||||
* @param name name of the mappings file
|
||||
* @param mappingsDir mappings directory
|
||||
* @param name name of the mappings file
|
||||
* @return the mappings file as a JsonObject, or null if it does not exist
|
||||
*/
|
||||
public static @Nullable JsonObject load(final String name) throws IOException {
|
||||
final Path path = MappingsOptimizer.MAPPINGS_DIR.resolve(name);
|
||||
public static @Nullable JsonObject load(final Path mappingsDir, final String name) throws IOException {
|
||||
final Path path = mappingsDir.resolve(name);
|
||||
if (!Files.exists(path)) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import com.viaversion.mappingsgenerator.util.JsonConverter;
|
|||
import com.viaversion.mappingsgenerator.util.Version;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -40,6 +41,7 @@ import java.util.Arrays;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -56,7 +58,7 @@ public final class MappingsOptimizer {
|
|||
public static final Path MAPPINGS_DIR = Path.of("mappings");
|
||||
public static final Path OUTPUT_DIR = Path.of("output");
|
||||
public static final Path OUTPUT_BACKWARDS_DIR = OUTPUT_DIR.resolve("backwards");
|
||||
public static final String DIFF_FILE_FORMAT = "diff/mapping-%sto%s.json";
|
||||
public static final String DIFF_FILE_FORMAT = "mapping-%sto%s.json";
|
||||
public static final String MAPPING_FILE_FORMAT = "mapping-%s.json";
|
||||
public static final String OUTPUT_FILE_FORMAT = "mappings-%sto%s.nbt";
|
||||
public static final String OUTPUT_IDENTIFIERS_FILE_FORMAT = "identifiers-%s.nbt";
|
||||
|
@ -87,6 +89,7 @@ public final class MappingsOptimizer {
|
|||
private final String toVersion;
|
||||
private final JsonObject unmappedObject;
|
||||
private final JsonObject mappedObject;
|
||||
private final boolean special;
|
||||
private final boolean backwards;
|
||||
private ErrorStrategy errorStrategy = ErrorStrategy.WARN;
|
||||
private JsonObject diffObject;
|
||||
|
@ -115,30 +118,45 @@ public final class MappingsOptimizer {
|
|||
optimizer.optimizeAndWrite();
|
||||
}
|
||||
|
||||
public MappingsOptimizer(final String from, final String to) throws IOException {
|
||||
this(from, to, false);
|
||||
}
|
||||
|
||||
private Path getMappingsDir() {
|
||||
return special ? MAPPINGS_DIR.resolve("special") : MAPPINGS_DIR;
|
||||
}
|
||||
|
||||
private Path getDiffDir() {
|
||||
final Path diffDir = MAPPINGS_DIR.resolve("diff");
|
||||
return special ? diffDir.resolve("special") : diffDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MappingsOptimizer instance.
|
||||
*
|
||||
* @param from version to map from
|
||||
* @param to version to map to
|
||||
* @param from version to map from
|
||||
* @param to version to map to
|
||||
* @param special If true, the special folders will be used for input and output
|
||||
* @see #optimizeAndWrite()
|
||||
*/
|
||||
public MappingsOptimizer(final String from, final String to) throws IOException {
|
||||
public MappingsOptimizer(final String from, final String to, final boolean special) throws IOException {
|
||||
this.fromVersion = from;
|
||||
this.toVersion = to;
|
||||
backwards = Version.isBackwards(fromVersion, toVersion);
|
||||
this.special = special;
|
||||
this.backwards = special || Version.isBackwards(from, to);
|
||||
output.putInt("version", VERSION);
|
||||
|
||||
unmappedObject = MappingsLoader.load(MAPPING_FILE_FORMAT.formatted(from));
|
||||
unmappedObject = MappingsLoader.load(getMappingsDir(), MAPPING_FILE_FORMAT.formatted(from));
|
||||
if (unmappedObject == null) {
|
||||
throw new IllegalArgumentException("Mapping file for version " + from + " does not exist");
|
||||
}
|
||||
|
||||
mappedObject = MappingsLoader.load(MAPPING_FILE_FORMAT.formatted(to));
|
||||
mappedObject = MappingsLoader.load(MAPPINGS_DIR, MAPPING_FILE_FORMAT.formatted(to));
|
||||
if (mappedObject == null) {
|
||||
throw new IllegalArgumentException("Mapping file for version " + to + " does not exist");
|
||||
}
|
||||
|
||||
diffObject = MappingsLoader.load(DIFF_FILE_FORMAT.formatted(from, to));
|
||||
diffObject = MappingsLoader.load(getDiffDir(), DIFF_FILE_FORMAT.formatted(from, to));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,7 +198,8 @@ public final class MappingsOptimizer {
|
|||
}
|
||||
}
|
||||
|
||||
write(backwards ? OUTPUT_BACKWARDS_DIR : OUTPUT_DIR);
|
||||
final Path outputDir = backwards ? OUTPUT_BACKWARDS_DIR : OUTPUT_DIR;
|
||||
write(special ? outputDir.resolve("special") : outputDir);
|
||||
|
||||
// Save full identifiers to a separate file per version
|
||||
saveIdentifierFiles(fromVersion, unmappedObject);
|
||||
|
@ -197,7 +216,7 @@ public final class MappingsOptimizer {
|
|||
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));
|
||||
Files.writeString(getDiffDir().resolve(DIFF_FILE_FORMAT.formatted(fromVersion, toVersion)), MappingsGenerator.GSON.toJson(diffObject));
|
||||
this.diffObject = diffObject;
|
||||
return true;
|
||||
}
|
||||
|
@ -237,7 +256,8 @@ public final class MappingsOptimizer {
|
|||
storeIdentifiers(identifiers, object, "recipe_serializers");
|
||||
storeIdentifiers(identifiers, object, "data_component_type");
|
||||
if (SAVED_IDENTIFIER_FILES.add(version)) {
|
||||
write(identifiers, OUTPUT_DIR.resolve(OUTPUT_IDENTIFIERS_FILE_FORMAT.formatted(version)));
|
||||
final Path outputDir = special ? OUTPUT_DIR.resolve("special") : OUTPUT_DIR;
|
||||
write(identifiers, outputDir.resolve(OUTPUT_IDENTIFIERS_FILE_FORMAT.formatted(version)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue