A ForcedLevelPatch
is always executed against level.dat, (no matter what patchLevel is set for a world)
This commit is contained in:
parent
f648669c95
commit
d04d75222e
5 changed files with 80 additions and 7 deletions
|
@ -12,7 +12,6 @@ import ru.bclib.api.dataexchange.handler.autosync.HelloClient;
|
||||||
import ru.bclib.api.dataexchange.handler.autosync.HelloServer;
|
import ru.bclib.api.dataexchange.handler.autosync.HelloServer;
|
||||||
import ru.bclib.api.dataexchange.handler.autosync.RequestFiles;
|
import ru.bclib.api.dataexchange.handler.autosync.RequestFiles;
|
||||||
import ru.bclib.api.dataexchange.handler.autosync.SendFiles;
|
import ru.bclib.api.dataexchange.handler.autosync.SendFiles;
|
||||||
import ru.bclib.api.datafixer.DataFixerAPI;
|
|
||||||
import ru.bclib.config.Configs;
|
import ru.bclib.config.Configs;
|
||||||
import ru.bclib.recipes.CraftingRecipes;
|
import ru.bclib.recipes.CraftingRecipes;
|
||||||
import ru.bclib.registry.BaseBlockEntities;
|
import ru.bclib.registry.BaseBlockEntities;
|
||||||
|
@ -50,8 +49,7 @@ public class BCLib implements ModInitializer {
|
||||||
Chunker.DESCRIPTOR
|
Chunker.DESCRIPTOR
|
||||||
));
|
));
|
||||||
|
|
||||||
DataFixerAPI.registerPatch(() -> new BCLibPatch());
|
BCLibPatch.register();
|
||||||
|
|
||||||
Configs.save();
|
Configs.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
package ru.bclib;
|
package ru.bclib;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import ru.bclib.api.datafixer.DataFixerAPI;
|
||||||
import ru.bclib.api.datafixer.Patch;
|
import ru.bclib.api.datafixer.Patch;
|
||||||
import ru.bclib.api.datafixer.PatchFunction;
|
import ru.bclib.api.datafixer.PatchFunction;
|
||||||
|
|
||||||
public final class BCLibPatch extends Patch {
|
|
||||||
|
|
||||||
|
public final class BCLibPatch {
|
||||||
|
public static void register(){
|
||||||
|
DataFixerAPI.registerPatch(BiomeSourcePatch::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final class BiomeSourcePatch extends Patch {
|
||||||
private static final String NETHER_BIOME_SOURCE = "bclib:nether_biome_source";
|
private static final String NETHER_BIOME_SOURCE = "bclib:nether_biome_source";
|
||||||
private static final String END_BIOME_SOURCE = "bclib:end_biome_source";
|
private static final String END_BIOME_SOURCE = "bclib:end_biome_source";
|
||||||
|
|
||||||
protected BCLibPatch() {
|
protected BiomeSourcePatch() {
|
||||||
super(BCLib.MOD_ID, "0.4.0");
|
super(BCLib.MOD_ID, "0.4.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
47
src/main/java/ru/bclib/api/datafixer/ForcedLevelPatch.java
Normal file
47
src/main/java/ru/bclib/api/datafixer/ForcedLevelPatch.java
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package ru.bclib.api.datafixer;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.ListTag;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Patch for level.dat that is always executed no matter what Patchlevel is set in a world.
|
||||||
|
*/
|
||||||
|
public abstract class ForcedLevelPatch extends Patch {
|
||||||
|
protected ForcedLevelPatch(@NotNull String modID, String version) {
|
||||||
|
super(modID, version, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final Map<String, String> getIDReplacements() {
|
||||||
|
return new HashMap<String, String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final PatchFunction<CompoundTag, Boolean> getWorldDataPatcher() { return null; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final PatchBiFunction<ListTag, ListTag, Boolean> getBlockStatePatcher() { return null; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final List<String> getWorldDataIDPaths() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PatchFunction<CompoundTag, Boolean> getLevelDatPatcher() { return this::runLevelDatPatch; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called with the contents of level.dat in {@Code root}
|
||||||
|
* @param root The contents of level.dat
|
||||||
|
* @param profile The active migration profile
|
||||||
|
* @return true, if the run did change the contents of root
|
||||||
|
*/
|
||||||
|
abstract protected Boolean runLevelDatPatch(CompoundTag root, MigrationProfile profile);
|
||||||
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class MigrationProfile {
|
||||||
List<String> paths = patch.getWorldDataIDPaths();
|
List<String> paths = patch.getWorldDataIDPaths();
|
||||||
if (paths!=null) worldDataIDPaths.put(modID, paths);
|
if (paths!=null) worldDataIDPaths.put(modID, paths);
|
||||||
|
|
||||||
if (applyAll || currentPatchLevel(modID) < patch.level) {
|
if (applyAll || currentPatchLevel(modID) < patch.level || patch.alwaysApply) {
|
||||||
replacements.putAll(patch.getIDReplacements());
|
replacements.putAll(patch.getIDReplacements());
|
||||||
if (patch.getLevelDatPatcher()!=null)
|
if (patch.getLevelDatPatcher()!=null)
|
||||||
levelPatches.add(patch.getLevelDatPatcher());
|
levelPatches.add(patch.getLevelDatPatcher());
|
||||||
|
|
|
@ -31,6 +31,11 @@ public abstract class Patch {
|
||||||
@NotNull
|
@NotNull
|
||||||
public final String modID;
|
public final String modID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This Mod is tested for each level start
|
||||||
|
*/
|
||||||
|
public final boolean alwaysApply;
|
||||||
|
|
||||||
static List<Patch> getALL() {
|
static List<Patch> getALL() {
|
||||||
return ALL;
|
return ALL;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +87,19 @@ public abstract class Patch {
|
||||||
* {@link Patch#maxPatchVersion(String)}
|
* {@link Patch#maxPatchVersion(String)}
|
||||||
*/
|
*/
|
||||||
protected Patch(@NotNull String modID, String version) {
|
protected Patch(@NotNull String modID, String version) {
|
||||||
|
this(modID, version, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal Constructor used to create patches that can allways run (no matter what patchlevel a level has)
|
||||||
|
* @param modID The ID of the Mod
|
||||||
|
* @param version The mod-version that introduces the patch. When {@Code runAllways} is set, this version will
|
||||||
|
* determine the patchlevel that is written to the level
|
||||||
|
* @param alwaysApply When true, this patch is always active, no matter the patchlevel of the world.
|
||||||
|
* This should be used sparingly and just for patches that apply to level.dat (as they only take
|
||||||
|
* effect when changes are detected). Use {@link ForcedLevelPatch} to instatiate.
|
||||||
|
*/
|
||||||
|
Patch(@NotNull String modID, String version, boolean alwaysApply) {
|
||||||
//Patchlevels need to be unique and registered in ascending order
|
//Patchlevels need to be unique and registered in ascending order
|
||||||
if (modID == null || "".equals(modID)) {
|
if (modID == null || "".equals(modID)) {
|
||||||
throw new RuntimeException("[INTERNAL ERROR] Patches need a valid modID!");
|
throw new RuntimeException("[INTERNAL ERROR] Patches need a valid modID!");
|
||||||
|
@ -92,6 +110,7 @@ public abstract class Patch {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.alwaysApply = alwaysApply;
|
||||||
this.level = ModUtil.convertModVersion(version);
|
this.level = ModUtil.convertModVersion(version);
|
||||||
if (!ALL.stream()
|
if (!ALL.stream()
|
||||||
.filter(p -> p.modID
|
.filter(p -> p.modID
|
||||||
|
@ -185,7 +204,7 @@ public abstract class Patch {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of paths,where your mod may IDs in your {@link ru.bclib.api.WorldDataAPI}-File.
|
* Returns a list of paths where your mod stores IDs in your {@link ru.bclib.api.WorldDataAPI}-File.
|
||||||
* <p>
|
* <p>
|
||||||
* {@link DataFixerAPI} will use information from the latest patch that returns a non-null-result. This list is used
|
* {@link DataFixerAPI} will use information from the latest patch that returns a non-null-result. This list is used
|
||||||
* to automatically fix changed IDs from all active patches (see {@link Patch#getIDReplacements()}
|
* to automatically fix changed IDs from all active patches (see {@link Patch#getIDReplacements()}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue