Switching to lib data util
This commit is contained in:
parent
f89a4f5e2c
commit
09f5cd60fa
5 changed files with 11 additions and 69 deletions
|
@ -20,9 +20,9 @@ import net.minecraft.world.level.levelgen.feature.EndPodiumFeature;
|
|||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
||||
import ru.bclib.api.WorldDataAPI;
|
||||
import ru.bclib.util.StructureHelper;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.util.WorldDataUtil;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
||||
@Mixin(EndPodiumFeature.class)
|
||||
|
@ -63,8 +63,8 @@ public class EndPodiumFeatureMixin {
|
|||
}
|
||||
pos = new BlockPos(pos.getX(), y, pos.getZ());
|
||||
GeneratorOptions.setPortalPos(pos);
|
||||
WorldDataUtil.getRootTag().put("portal", NbtUtils.writeBlockPos(pos));
|
||||
WorldDataUtil.saveFile();
|
||||
WorldDataAPI.getRootTag(BetterEnd.MOD_ID).put("portal", NbtUtils.writeBlockPos(pos));
|
||||
WorldDataAPI.saveFile(BetterEnd.MOD_ID);
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.levelgen.feature.SpikeFeature.EndSpike;
|
||||
import ru.betterend.util.WorldDataUtil;
|
||||
import ru.bclib.api.WorldDataAPI;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
||||
@Mixin(EndSpike.class)
|
||||
|
@ -24,7 +25,7 @@ public class EndSpikeMixin {
|
|||
int x = getCenterX();
|
||||
int z = getCenterZ();
|
||||
String pillarID = String.format("%d_%d", x, z);
|
||||
CompoundTag pillar = WorldDataUtil.getCompoundTag("pillars");
|
||||
CompoundTag pillar = WorldDataAPI.getCompoundTag(BetterEnd.MOD_ID, "pillars");
|
||||
int minY = pillar.contains(pillarID) ? pillar.getInt(pillarID) : 65;
|
||||
int maxY = minY + height - 54;
|
||||
info.setReturnValue(maxY);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -13,11 +11,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg;
|
|||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
@ -37,14 +31,10 @@ import ru.bclib.api.BiomeAPI;
|
|||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.registry.EndBiomes;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.util.DataFixerUtil;
|
||||
import ru.betterend.util.WorldDataUtil;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
||||
@Mixin(ServerLevel.class)
|
||||
public abstract class ServerLevelMixin extends Level {
|
||||
private static final int BE_DEV_VERSION = be_getVersionInt("63.63.63");
|
||||
private static final int BE_FIX_VERSION = BE_DEV_VERSION;
|
||||
private static String be_lastWorld = null;
|
||||
|
||||
protected ServerLevelMixin(WritableLevelData writableLevelData, ResourceKey<Level> resourceKey, DimensionType dimensionType, Supplier<ProfilerFiller> supplier, boolean bl, boolean bl2, long l) {
|
||||
|
@ -58,30 +48,8 @@ public abstract class ServerLevelMixin extends Level {
|
|||
}
|
||||
|
||||
be_lastWorld = session.getLevelId();
|
||||
|
||||
ServerLevel world = ServerLevel.class.cast(this);
|
||||
EndBiomes.onWorldLoad(world.getSeed());
|
||||
File dir = session.getDimensionPath(world.dimension());
|
||||
if (!new File(dir, "level.dat").exists()) {
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
File data = new File(dir, "data/betterend_data.nbt");
|
||||
|
||||
ModMetadata meta = FabricLoader.getInstance().getModContainer(BetterEnd.MOD_ID).get().getMetadata();
|
||||
int version = BetterEnd.isDevEnvironment() ? BE_DEV_VERSION : be_getVersionInt(meta.getVersion().toString());
|
||||
|
||||
WorldDataUtil.load(data);
|
||||
CompoundTag root = WorldDataUtil.getRootTag();
|
||||
int dataVersion = be_getVersionInt(root.getString("version"));
|
||||
GeneratorOptions.setPortalPos(NbtUtils.readBlockPos(root.getCompound("portal")));
|
||||
|
||||
if (dataVersion < version) {
|
||||
if (version < BE_FIX_VERSION) {
|
||||
DataFixerUtil.fixData(data.getParentFile());
|
||||
}
|
||||
root.putString("version", be_getVersionString(version));
|
||||
WorldDataUtil.saveFile();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "getSharedSpawnPos", at = @At("HEAD"), cancellable = true)
|
||||
|
@ -110,24 +78,4 @@ public abstract class ServerLevelMixin extends Level {
|
|||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private static int be_getVersionInt(String version) {
|
||||
if (version.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
String[] values = version.split("\\.");
|
||||
return Integer.parseInt(values[0]) << 12 | Integer.parseInt(values[1]) << 6 | Integer.parseInt(values[1]);
|
||||
}
|
||||
catch (Exception e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static String be_getVersionString(int version) {
|
||||
int a = (version >> 12) & 63;
|
||||
int b = (version >> 6) & 63;
|
||||
int c = version & 63;
|
||||
return String.format(Locale.ROOT, "%d.%d.%d", a, b, c);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,10 +25,10 @@ import net.minecraft.world.level.levelgen.feature.SpikeFeature;
|
|||
import net.minecraft.world.level.levelgen.feature.configurations.SpikeConfiguration;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
|
||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
||||
import ru.bclib.api.WorldDataAPI;
|
||||
import ru.bclib.util.BlocksHelper;
|
||||
import ru.bclib.util.StructureHelper;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.util.WorldDataUtil;
|
||||
import ru.betterend.world.generator.GeneratorOptions;
|
||||
|
||||
@Mixin(SpikeFeature.class)
|
||||
|
@ -51,12 +51,12 @@ public class SpikeFeatureMixin {
|
|||
long lz = (long) z;
|
||||
if (lx * lx + lz * lz < 10000) {
|
||||
String pillarID = String.format("%d_%d", x, z);
|
||||
CompoundTag pillar = WorldDataUtil.getCompoundTag("pillars");
|
||||
CompoundTag pillar = WorldDataAPI.getCompoundTag(BetterEnd.MOD_ID, "pillars");
|
||||
boolean haveValue = pillar.contains(pillarID);
|
||||
minY = haveValue ? pillar.getInt(pillarID) : world.getChunk(x >> 4, z >> 4).getHeight(Types.WORLD_SURFACE, x & 15, z);
|
||||
if (!haveValue) {
|
||||
pillar.putInt(pillarID, minY);
|
||||
WorldDataUtil.saveFile();
|
||||
WorldDataAPI.saveFile(BetterEnd.MOD_ID);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
package ru.betterend.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
public class WorldDataUtil {
|
||||
private static CompoundTag root;
|
||||
/*private static CompoundTag root;
|
||||
private static File saveFile;
|
||||
|
||||
public static void load(File file) {
|
||||
|
@ -53,5 +46,5 @@ public class WorldDataUtil {
|
|||
catch (IOException e) {
|
||||
BetterEnd.LOGGER.error("World data saving failed", e);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue