Add datafixer for rift registry
This commit is contained in:
parent
f7937f051c
commit
918c81c047
5 changed files with 43 additions and 10 deletions
|
@ -153,8 +153,8 @@ curseforge {
|
|||
}
|
||||
project {
|
||||
id = '284876'
|
||||
changelog = 'FOR TESTING ONLY. A changelog can be found at https://github.com/DimensionalDevelopment/DimDoors/commits/1.17'
|
||||
releaseType = 'alpha'
|
||||
changelog = 'NOTE: THIS UPDATE IS INCOMPATIBLE WITH WORLDS CREATED ON THE FIRST ALPHA. Please back up your worlds before loading it in a new version. A changelog can be found at https://github.com/DimensionalDevelopment/DimDoors/commits/1.17'
|
||||
releaseType = 'beta'
|
||||
addGameVersion '1.17'
|
||||
mainArtifact(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")) {
|
||||
displayName = "[21w08b] Dimensional Doors ${version}"
|
||||
|
|
|
@ -61,7 +61,7 @@ import net.fabricmc.loader.api.ModContainer;
|
|||
|
||||
public class DimensionalDoorsInitializer implements ModInitializer {
|
||||
private static final Supplier<Path> CONFIG_ROOT = () -> FabricLoader.getInstance().getConfigDir().resolve("dimdoors").toAbsolutePath();
|
||||
public static final ConfigHolder<ModConfig> CONFIG_MANAGER = AutoConfig.register(ModConfig.class, SubRootJanksonConfigSerializer::new);
|
||||
private static final ConfigHolder<ModConfig> CONFIG_MANAGER = AutoConfig.register(ModConfig.class, SubRootJanksonConfigSerializer::new);
|
||||
private static MinecraftServer server;
|
||||
private static ModContainer dimDoorsMod;
|
||||
|
||||
|
|
|
@ -25,12 +25,20 @@ import org.dimdev.dimdoors.world.pocket.PrivateRegistry;
|
|||
import static org.dimdev.dimdoors.DimensionalDoorsInitializer.getServer;
|
||||
|
||||
public class DimensionalRegistry implements ComponentV3 {
|
||||
public static final int RIFT_DATA_VERSION = 1; // Increment this number every time
|
||||
private Map<RegistryKey<World>, PocketDirectory> pocketRegistry = new HashMap<>();
|
||||
private RiftRegistry riftRegistry = new RiftRegistry();
|
||||
private PrivateRegistry privateRegistry = new PrivateRegistry();
|
||||
|
||||
@Override
|
||||
public void readFromNbt(CompoundTag tag) {
|
||||
int riftDataVersion = tag.getInt("RiftDataVersion");
|
||||
if (riftDataVersion < RIFT_DATA_VERSION) {
|
||||
tag = RiftSchemas.update(riftDataVersion, tag);
|
||||
} else if (RIFT_DATA_VERSION < riftDataVersion) {
|
||||
throw new UnsupportedOperationException("Downgrading is not supported!");
|
||||
}
|
||||
|
||||
CompoundTag pocketRegistryTag = tag.getCompound("pocket_registry");
|
||||
CompletableFuture<Map<RegistryKey<World>, PocketDirectory>> futurePocketRegistry = CompletableFuture.supplyAsync(() -> pocketRegistryTag.getKeys().stream().map(key -> {
|
||||
CompoundTag pocketDirectoryTag = pocketRegistryTag.getCompound(key);
|
||||
|
@ -55,7 +63,6 @@ public class DimensionalRegistry implements ComponentV3 {
|
|||
|
||||
@Override
|
||||
public void writeToNbt(CompoundTag tag) {
|
||||
|
||||
CompletableFuture<Tag> futurePocketRegistryTag = CompletableFuture.supplyAsync(() -> {
|
||||
List<CompletableFuture<Pair<String, Tag>>> futurePocketRegistryTags = new ArrayList<>();
|
||||
pocketRegistry.forEach((key, value) -> futurePocketRegistryTags.add(CompletableFuture.supplyAsync(() -> new Pair<>(key.getValue().toString(), value.writeToNbt()))));
|
||||
|
@ -67,10 +74,11 @@ public class DimensionalRegistry implements ComponentV3 {
|
|||
CompletableFuture<Tag> futureRiftRegistryTag = CompletableFuture.supplyAsync(riftRegistry::toTag);
|
||||
CompletableFuture<Tag> futurePrivateRegistryTag = CompletableFuture.supplyAsync(() -> privateRegistry.toTag(new CompoundTag()));
|
||||
|
||||
|
||||
tag.put("pocket_registry", futurePocketRegistryTag.join());
|
||||
tag.put("rift_registry", futureRiftRegistryTag.join());
|
||||
tag.put("private_registry", futurePrivateRegistryTag.join());
|
||||
|
||||
tag.putInt("RiftDataVersion", RIFT_DATA_VERSION);
|
||||
}
|
||||
|
||||
public static DimensionalRegistry instance() {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package org.dimdev.dimdoors.world.level;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import com.mojang.datafixers.DSL;
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import com.mojang.datafixers.DataFixerBuilder;
|
||||
import com.mojang.datafixers.schemas.Schema;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
public class RiftSchemas {
|
||||
public static final DSL.TypeReference RIFT_DATA_TYPE_REF = () -> "rift_data";
|
||||
public static final int RIFT_DATA_VERSION = DimensionalRegistry.RIFT_DATA_VERSION;
|
||||
public static final BiFunction<Integer, Schema, Schema> EMPTY = Schema::new;
|
||||
public static final DataFixer DATA_FIXER = Util.make(new DataFixerBuilder(RIFT_DATA_VERSION), builder -> {
|
||||
// TODO: add schemas if schema changes
|
||||
}).build(Runnable::run);
|
||||
|
||||
public static CompoundTag update(int oldVersion, CompoundTag original) {
|
||||
return (CompoundTag) DATA_FIXER.update(RIFT_DATA_TYPE_REF, new Dynamic<>( NbtOps.INSTANCE, original), oldVersion, RIFT_DATA_VERSION).getValue();
|
||||
}
|
||||
}
|
|
@ -83,7 +83,6 @@ public interface PocketAddon {
|
|||
PocketAddonType<PreventBlockModificationAddon> PREVENT_BLOCK_MODIFICATION_ADDON = register(PreventBlockModificationAddon.ID, PreventBlockModificationAddon::new, PreventBlockModificationAddon.PreventBlockModificationBuilderAddon::new);
|
||||
PocketAddonType<BlockBreakContainer> BLOCK_BREAK_CONTAINER = register(BlockBreakContainer.ID, BlockBreakContainer::new, null);
|
||||
|
||||
|
||||
T fromTag(CompoundTag tag);
|
||||
|
||||
CompoundTag toTag(CompoundTag tag);
|
||||
|
@ -96,12 +95,12 @@ public interface PocketAddon {
|
|||
|
||||
static void register() {
|
||||
}
|
||||
|
||||
static <U extends PocketAddon> PocketAddonType<U> register(Identifier id, Supplier<U> supplier, Supplier<PocketBuilderAddon<U>> addonSupplier) {
|
||||
z=
|
||||
static <U extends PocketAddon> PocketAddonType<U> register(Identifier id, Supplier<U> factory, Supplier<PocketBuilderAddon<U>> addonSupplier) {
|
||||
return Registry.register(REGISTRY, id, new PocketAddonType<U>() {
|
||||
@Override
|
||||
public U fromTag(CompoundTag tag) {
|
||||
return (U) supplier.get().fromTag(tag);
|
||||
return (U) factory.get().fromTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,7 +111,7 @@ public interface PocketAddon {
|
|||
|
||||
@Override
|
||||
public U instance() {
|
||||
return supplier.get();
|
||||
return factory.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue