mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-25 22:44:51 +00:00
Open the custom data mapping gate once the world's info has loaded
This commit is contained in:
6 files changed
+74
-7
No files matched your search
@@ -23,13 +23,13 @@ public abstract class CustomDataReplacementManager {
|
||||
|
||||
/// Transforms `root` in place through every registered transformer whose stamp differs from its current
|
||||
/// version, then writes the updated stamps onto `root`. Throws [IllegalStateException] when called before the
|
||||
/// world's saved id mappings were applied.
|
||||
/// world's info, and with it any saved id map, has loaded.
|
||||
public static void transform(String storageId, NBTTagCompound root) {
|
||||
if (!serverRunning()) return;
|
||||
if (!IDRegistry.isMappingApplied()) {
|
||||
throw new IllegalStateException(
|
||||
"Custom data " + storageId
|
||||
+ " was offered for transformation before the world's id mappings were applied");
|
||||
+ " was offered for transformation before the world's info and id mappings loaded");
|
||||
}
|
||||
transform(storageId, root, VersionedReplacementManager.transformers());
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public final class PosteaLoadingPlugin implements IEarlyMixinLoader, IFMLLoading
|
||||
mixins.add("MixinEntityPlayer");
|
||||
mixins.add("MixinAnvilChunkLoader");
|
||||
mixins.add("MixinNBTTagList");
|
||||
mixins.add("MixinSaveHandler");
|
||||
return mixins;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.gtnewhorizons.postea.mixins.early;
|
||||
|
||||
import net.minecraft.world.storage.SaveHandler;
|
||||
import net.minecraft.world.storage.WorldInfo;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import com.gtnewhorizons.postea.utility.IDRegistry;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
@Mixin(SaveHandler.class)
|
||||
public abstract class MixinSaveHandler {
|
||||
|
||||
/// Returns come after FML's `handleWorldDataLoad` applies any saved id map, or when the world has no readable
|
||||
/// `level.dat`. FML applies the map only on the server thread.
|
||||
@Inject(method = "loadWorldInfo", at = @At("RETURN"), require = 1)
|
||||
private void postea$markWorldInfoLoaded(CallbackInfoReturnable<WorldInfo> cir) {
|
||||
if (FMLCommonHandler.instance()
|
||||
.getEffectiveSide()
|
||||
.isServer()) IDRegistry.onWorldInfoLoaded();
|
||||
}
|
||||
}
|
||||
@@ -41,12 +41,11 @@ public abstract class IDRegistry {
|
||||
private static volatile boolean mappingApplied;
|
||||
|
||||
/// Loads the retired id table of the world about to load. [#registerWorldSpecificIDs] records into it until
|
||||
/// [#endWorld()].
|
||||
/// [#endWorld()]. [#isMappingApplied] stays false until [#onWorldInfoLoaded].
|
||||
public static void beginWorld(File worldDirectory) {
|
||||
tableFile = new File(new File(worldDirectory, Postea.MODID), WorldIdTable.FILE_NAME);
|
||||
table = WorldIdTable.load(tableFile);
|
||||
// No level.dat means no saved id map, and FML fires no remap event.
|
||||
mappingApplied = !new File(worldDirectory, "level.dat").exists();
|
||||
mappingApplied = false;
|
||||
}
|
||||
|
||||
public static void endWorld() {
|
||||
@@ -58,11 +57,17 @@ public abstract class IDRegistry {
|
||||
ITEM_NAME_TO_ID.clear();
|
||||
}
|
||||
|
||||
/// Whether FML has applied the loading world's saved id map.
|
||||
/// Whether the loading world's info has loaded on the server thread. FML applies the world's saved id map, if
|
||||
/// it has one, during that load.
|
||||
public static boolean isMappingApplied() {
|
||||
return mappingApplied;
|
||||
}
|
||||
|
||||
/// Marks the loading world's info as loaded. Ignored outside a world begun by [#beginWorld].
|
||||
public static void onWorldInfoLoaded() {
|
||||
if (tableFile != null) mappingApplied = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers all the callbacks registered by other mods that wish to identify a block that may no longer exist.
|
||||
* These callbacks effectively remove the need for dummies, and should help improve performance at runtime.
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
"MixinEntity",
|
||||
"MixinEntityPlayer",
|
||||
"MixinItemStack",
|
||||
"MixinNBTTagList"
|
||||
"MixinNBTTagList",
|
||||
"MixinSaveHandler"
|
||||
],
|
||||
"client": [],
|
||||
"server": []
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.gtnewhorizons.postea.utility;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class IDRegistryTest {
|
||||
|
||||
@TempDir
|
||||
File world;
|
||||
|
||||
@AfterEach
|
||||
void endWorld() {
|
||||
IDRegistry.endWorld();
|
||||
}
|
||||
|
||||
@Test
|
||||
void theMappingGateOpensOnlyWhenTheBegunWorldsInfoLoads() {
|
||||
IDRegistry.beginWorld(world);
|
||||
assertFalse(IDRegistry.isMappingApplied());
|
||||
|
||||
IDRegistry.onWorldInfoLoaded();
|
||||
assertTrue(IDRegistry.isMappingApplied());
|
||||
|
||||
IDRegistry.endWorld();
|
||||
IDRegistry.onWorldInfoLoaded();
|
||||
assertFalse(IDRegistry.isMappingApplied());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user