some more stuff

This commit is contained in:
FalsePattern committed 2023-03-30 17:37:50 +02:00
1 parent b857c49966
commit 3890efe317
4 files changed
+25 -27

No files matched your search

+2 -2
View File
@@ -58,8 +58,8 @@ Instead of being called once per chunk, it is called once per chunk section (16x
### ChunkDataRegistry
This is where you actually register your manager. You need to do all registrations inside the `init` phase.
You can also disable specific manager IDs by calling `disableDataManager`, but this is not recommended,
and should only be used if you know what you are doing.
You can also disable specific manager IDs by calling `disableDataManager`, but this is not recommended, and should
only be used if you know what you are doing. You need to do all the disabling inside the `postInit` phase.
Alternatives
------------
@@ -14,6 +14,8 @@ package com.falsepattern.chunk.api;
import com.falsepattern.chunk.internal.ChunkDataRegistryImpl;
import java.util.Set;
/**
* This class is used to register ChunkDataManagers.
* @see ChunkDataManager
@@ -37,4 +39,12 @@ public class ChunkDataRegistry {
public static void disableDataManager(String domain, String id) throws IllegalStateException {
ChunkDataRegistryImpl.disableDataManager(domain, id);
}
/**
* Returns an unmodifiable set of all registered ChunkDataManagers.
* The id of a manager is its domain and id separated by a colon. (domain:id)
*/
public static Set<String> getRegisteredManagers() {
return ChunkDataRegistryImpl.getRegisteredManagers();
}
}
@@ -18,12 +18,9 @@ import com.falsepattern.chunk.internal.vanilla.BlockIDManager;
import com.falsepattern.chunk.internal.vanilla.BlocklightManager;
import com.falsepattern.chunk.internal.vanilla.MetadataManager;
import com.falsepattern.chunk.internal.vanilla.SkylightManager;
import lombok.Getter;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = Tags.MODID,
version = Tags.VERSION,
@@ -31,30 +28,13 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
acceptedMinecraftVersions = "[1.7.10]",
dependencies = "required-after:falsepatternlib@[0.10.15,);")
public class ChunkAPI {
@Getter
private static boolean registrationStage = false;
@Getter
private static boolean disableStage = false;
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
registrationStage = true;
disableStage = true;
public void init(FMLInitializationEvent event) {
ChunkDataRegistry.registerDataManager(new BlockIDManager());
ChunkDataRegistry.registerDataManager(new MetadataManager());
ChunkDataRegistry.registerDataManager(new BlocklightManager());
ChunkDataRegistry.registerDataManager(new SkylightManager());
ChunkDataRegistry.registerDataManager(new BiomeManager());
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
registrationStage = false;
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
disableStage = false;
}
}
@@ -20,9 +20,13 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderState;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -36,9 +40,9 @@ public class ChunkDataRegistryImpl {
private static final Set<String> disabledManagers = new HashSet<>();
private static int maxPacketSize = 4;
public static void registerDataManager(ChunkDataManager manager) throws IllegalStateException, IllegalArgumentException {
if (!ChunkAPI.isRegistrationStage()) {
if (Loader.instance().getLoaderState() != LoaderState.INITIALIZATION) {
throw new IllegalStateException("ChunkDataManager registration is not allowed at this time! " +
"Please register your ChunkDataManager in the preInit phase of your mod.");
"Please register your ChunkDataManager in the init phase.");
}
var id = manager.domain() + ":" + manager.id();
if (managers.contains(id)) {
@@ -66,9 +70,9 @@ public class ChunkDataRegistryImpl {
}
public static void disableDataManager(String domain, String id) {
if (!ChunkAPI.isDisableStage()) {
if (Loader.instance().getLoaderState() != LoaderState.POSTINITIALIZATION) {
throw new IllegalStateException("ChunkDataManager disabling is not allowed at this time! " +
"Please disable any ChunkDataManagers in the preInit/init phases.");
"Please disable any ChunkDataManagers in the postInit phase.");
}
Common.LOG.warn("Disabling ChunkDataManager " + id + " in domain " + domain + ". See the stacktrace for the source of this event.", new Throwable());
val manager = domain + ":" + id;
@@ -209,4 +213,8 @@ public class ChunkDataRegistryImpl {
manager.readChunkFromNBT(chunk, getManagerNBT(manager.chunkPrivilegedAccess(), chunkNBT, manager));
}
}
public static Set<String> getRegisteredManagers() {
return Collections.unmodifiableSet(managers);
}
}