Prepared state fixer
This commit is contained in:
parent
f88506f654
commit
d47321c0f7
4 changed files with 48 additions and 3 deletions
|
@ -416,7 +416,7 @@ public class DataFixerAPI {
|
||||||
for (int z = 0; z < 32; z++) {
|
for (int z = 0; z < 32; z++) {
|
||||||
ChunkPos pos = new ChunkPos(x, z);
|
ChunkPos pos = new ChunkPos(x, z);
|
||||||
changed[0] = false;
|
changed[0] = false;
|
||||||
if (region.hasChunk(pos)) {
|
if (region.hasChunk(pos) && !state.didFail) {
|
||||||
DataInputStream input = region.getChunkDataInputStream(pos);
|
DataInputStream input = region.getChunkDataInputStream(pos);
|
||||||
CompoundTag root = NbtIo.read(input);
|
CompoundTag root = NbtIo.read(input);
|
||||||
// if ((root.toString().contains("betternether:chest") || root.toString().contains("bclib:chest"))) {
|
// if ((root.toString().contains("betternether:chest") || root.toString().contains("bclib:chest"))) {
|
||||||
|
@ -442,6 +442,16 @@ public class DataFixerAPI {
|
||||||
CompoundTag blockTagCompound = ((CompoundTag) blockTag);
|
CompoundTag blockTagCompound = ((CompoundTag) blockTag);
|
||||||
changed[0] |= data.replaceStringFromIDs(blockTagCompound, "Name");
|
changed[0] |= data.replaceStringFromIDs(blockTagCompound, "Name");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
changed[0] |= data.patchBlockState(palette, ((CompoundTag) tag).getList("BlockStates", Tag.TAG_LONG));
|
||||||
|
}
|
||||||
|
catch (PatchDidiFailException e) {
|
||||||
|
BCLib.LOGGER.error("Failed fixing BlockState in " + pos);
|
||||||
|
state.didFail = true;
|
||||||
|
changed[0] = false;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (changed[0]) {
|
if (changed[0]) {
|
||||||
|
@ -450,7 +460,6 @@ public class DataFixerAPI {
|
||||||
DataOutputStream output = region.getChunkDataOutputStream(pos);
|
DataOutputStream output = region.getChunkDataOutputStream(pos);
|
||||||
NbtIo.write(root, output);
|
NbtIo.write(root, output);
|
||||||
output.close();
|
output.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,7 +467,7 @@ public class DataFixerAPI {
|
||||||
region.close();
|
region.close();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
BCLib.LOGGER.error("Failed fixing Player Data.");
|
BCLib.LOGGER.error("Failed fixing Region.");
|
||||||
state.didFail = true;
|
state.didFail = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class MigrationProfile {
|
||||||
final Set<String> mods;
|
final Set<String> mods;
|
||||||
final Map<String, String> idReplacements;
|
final Map<String, String> idReplacements;
|
||||||
final List<PatchFunction<CompoundTag, Boolean>> levelPatchers;
|
final List<PatchFunction<CompoundTag, Boolean>> levelPatchers;
|
||||||
|
final List<PatchBiFunction<ListTag, ListTag, Boolean>> statePatchers;
|
||||||
final List<Patch> worldDataPatchers;
|
final List<Patch> worldDataPatchers;
|
||||||
final Map<String, List<String>> worldDataIDPaths;
|
final Map<String, List<String>> worldDataIDPaths;
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ public class MigrationProfile {
|
||||||
HashMap<String, String> replacements = new HashMap<String, String>();
|
HashMap<String, String> replacements = new HashMap<String, String>();
|
||||||
List<PatchFunction<CompoundTag, Boolean>> levelPatches = new LinkedList<>();
|
List<PatchFunction<CompoundTag, Boolean>> levelPatches = new LinkedList<>();
|
||||||
List<Patch> worldDataPatches = new LinkedList<>();
|
List<Patch> worldDataPatches = new LinkedList<>();
|
||||||
|
List<PatchBiFunction<ListTag, ListTag, Boolean>> statePatches = new LinkedList<>();
|
||||||
HashMap<String, List<String>> worldDataIDPaths = new HashMap<>();
|
HashMap<String, List<String>> worldDataIDPaths = new HashMap<>();
|
||||||
for (String modID : mods) {
|
for (String modID : mods) {
|
||||||
|
|
||||||
|
@ -62,6 +64,8 @@ public class MigrationProfile {
|
||||||
levelPatches.add(patch.getLevelDatPatcher());
|
levelPatches.add(patch.getLevelDatPatcher());
|
||||||
if (patch.getWorldDataPatcher()!=null)
|
if (patch.getWorldDataPatcher()!=null)
|
||||||
worldDataPatches.add(patch);
|
worldDataPatches.add(patch);
|
||||||
|
if (patch.getBlockStatePatcher()!=null)
|
||||||
|
statePatches.add(patch.getBlockStatePatcher());
|
||||||
DataFixerAPI.LOGGER.info("Applying " + patch);
|
DataFixerAPI.LOGGER.info("Applying " + patch);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -74,6 +78,7 @@ public class MigrationProfile {
|
||||||
this.idReplacements = Collections.unmodifiableMap(replacements);
|
this.idReplacements = Collections.unmodifiableMap(replacements);
|
||||||
this.levelPatchers = Collections.unmodifiableList(levelPatches);
|
this.levelPatchers = Collections.unmodifiableList(levelPatches);
|
||||||
this.worldDataPatchers = Collections.unmodifiableList(worldDataPatches);
|
this.worldDataPatchers = Collections.unmodifiableList(worldDataPatches);
|
||||||
|
this.statePatchers = Collections.unmodifiableList(statePatches);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -305,4 +310,12 @@ public class MigrationProfile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean patchBlockState(ListTag palette, ListTag states) throws PatchDidiFailException{
|
||||||
|
boolean changed = false;
|
||||||
|
for (PatchBiFunction<ListTag, ListTag, Boolean> f : statePatchers) {
|
||||||
|
changed |= f.apply(palette, states, this);
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.bclib.api.datafixer;
|
package ru.bclib.api.datafixer;
|
||||||
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.nbt.ListTag;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import ru.bclib.util.ModUtil;
|
import ru.bclib.util.ModUtil;
|
||||||
|
|
||||||
|
@ -145,6 +146,22 @@ public abstract class Patch {
|
||||||
*/
|
*/
|
||||||
public PatchFunction<CompoundTag, Boolean> getWorldDataPatcher() { return null; }
|
public PatchFunction<CompoundTag, Boolean> getWorldDataPatcher() { return null; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a {@link PatchBiFunction} that is called with pallette and blockstate of
|
||||||
|
* each chunk in every region. This method is called AFTER all ID replacements
|
||||||
|
* from {@link #getIDReplacements()} were applied to the pallete.
|
||||||
|
*
|
||||||
|
* The first parameter is the palette and the second is the blockstate.
|
||||||
|
*
|
||||||
|
* The function needs to return {@code true}, if changes were made to the data.
|
||||||
|
* If an error occurs, the method should throw a {@link PatchDidiFailException}
|
||||||
|
*
|
||||||
|
* The default implementation of this method returns null.
|
||||||
|
*
|
||||||
|
* @return {@code true} if changes were applied and we need to save the data
|
||||||
|
*/
|
||||||
|
public PatchBiFunction<ListTag, ListTag, Boolean> getBlockStatePatcher() { return null; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates ready to use data for all currently registered patches. The list of
|
* Generates ready to use data for all currently registered patches. The list of
|
||||||
* patches is selected by the current patch-level of the world.
|
* patches is selected by the current patch-level of the world.
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
package ru.bclib.api.datafixer;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface PatchBiFunction<U, V, R> {
|
||||||
|
R apply(U t, V v, MigrationProfile profile) throws PatchDidiFailException;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue