修改兼容初始化方式,手动初始化
This commit is contained in:
parent
70ce25d158
commit
903585d281
|
|
@ -33,7 +33,7 @@ mod_name=3944Realms 's Lib Mod
|
||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=MIT
|
mod_license=MIT
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=0.3.1
|
mod_version=0.3.3
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|
|
||||||
|
|
@ -34,15 +34,8 @@ public abstract class CompatManager {
|
||||||
// 存储事件监听器配置
|
// 存储事件监听器配置
|
||||||
protected final List<ListenerConfig> listenerConfigs = new ArrayList<>();
|
protected final List<ListenerConfig> listenerConfigs = new ArrayList<>();
|
||||||
|
|
||||||
protected void initialize() {
|
public void initialize() {
|
||||||
modEventBus.addListener(this::onConstructMod);
|
initializeAllCompat();
|
||||||
}
|
|
||||||
|
|
||||||
private void onConstructMod(FMLConstructModEvent event) {
|
|
||||||
event.enqueueWork(() -> {
|
|
||||||
initializeAllCompat();
|
|
||||||
Lib39.LOGGER.info("[{}]: CompatManager initialized with {} modules", this.getId(), getLoadedCompats().size());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompatManager(ResourceLocation id, IEventBus modEventBus, IEventBus gameEventBus) {
|
public CompatManager(ResourceLocation id, IEventBus modEventBus, IEventBus gameEventBus) {
|
||||||
|
|
@ -50,7 +43,6 @@ public abstract class CompatManager {
|
||||||
this.modEventBus = modEventBus;
|
this.modEventBus = modEventBus;
|
||||||
this.gameEventBus = gameEventBus;
|
this.gameEventBus = gameEventBus;
|
||||||
this.logger = LoggerFactory.getLogger(id.toString());
|
this.logger = LoggerFactory.getLogger(id.toString());
|
||||||
initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -149,7 +141,7 @@ public abstract class CompatManager {
|
||||||
/**
|
/**
|
||||||
* 初始化所有兼容模块并应用事件监听器
|
* 初始化所有兼容模块并应用事件监听器
|
||||||
*/
|
*/
|
||||||
public void initializeAllCompat() {
|
protected synchronized void initializeAllCompat() {
|
||||||
logger.info("Initializing {} compatibility modules", compats.size());
|
logger.info("Initializing {} compatibility modules", compats.size());
|
||||||
|
|
||||||
// 先处理所有缓存的注册
|
// 先处理所有缓存的注册
|
||||||
|
|
@ -158,11 +150,14 @@ public abstract class CompatManager {
|
||||||
|
|
||||||
// 初始化所有兼容模块
|
// 初始化所有兼容模块
|
||||||
for (Map.Entry<ResourceLocation, ICompat> entry : compats.entrySet()) {
|
for (Map.Entry<ResourceLocation, ICompat> entry : compats.entrySet()) {
|
||||||
try {
|
if (!entry.getValue().isInitialized()) {
|
||||||
entry.getValue().initialize();
|
try {
|
||||||
logger.info("Initialized compat: {}", entry.getKey());
|
entry.getValue().initialize();
|
||||||
} catch (Exception e) {
|
entry.getValue().setInitialize(true);
|
||||||
logger.error("Failed to initialize compat: {}", entry.getKey(), e);
|
logger.info("Initialized compat: {}", entry.getKey());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Failed to initialize compat: {}", entry.getKey(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
@ -192,8 +187,10 @@ public abstract class CompatManager {
|
||||||
*/
|
*/
|
||||||
private void applyListenerToAllCompats(ListenerConfig config) {
|
private void applyListenerToAllCompats(ListenerConfig config) {
|
||||||
for (ICompat compat : compats.values()) {
|
for (ICompat compat : compats.values()) {
|
||||||
if (config.shouldApply(compat)) {
|
if(!compat.isInitialized()) {
|
||||||
applyListenerToCompat(compat, config);
|
if (config.shouldApply(compat)) {
|
||||||
|
applyListenerToCompat(compat, config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ import java.util.concurrent.Callable;
|
||||||
* The interface Compat.
|
* The interface Compat.
|
||||||
*/
|
*/
|
||||||
public interface ICompat {
|
public interface ICompat {
|
||||||
|
void setInitialize(boolean initialize);
|
||||||
|
boolean isInitialized();
|
||||||
/**
|
/**
|
||||||
* Id resource location.
|
* Id resource location.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import top.r3944realms.lib39.core.compat.ICompat;
|
||||||
* The type Lib 39 compat.
|
* The type Lib 39 compat.
|
||||||
*/
|
*/
|
||||||
public class Lib39Compat implements ICompat {
|
public class Lib39Compat implements ICompat {
|
||||||
|
boolean initialized = false;
|
||||||
/**
|
/**
|
||||||
* The constant INSTANCE.
|
* The constant INSTANCE.
|
||||||
*/
|
*/
|
||||||
|
|
@ -20,6 +21,17 @@ public class Lib39Compat implements ICompat {
|
||||||
* The constant ID.
|
* The constant ID.
|
||||||
*/
|
*/
|
||||||
public static ResourceLocation ID = Lib39.rl("lib39");
|
public static ResourceLocation ID = Lib39.rl("lib39");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInitialize(boolean initialize) {
|
||||||
|
this.initialized = initialize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isInitialized() {
|
||||||
|
return initialized;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation id() {
|
public ResourceLocation id() {
|
||||||
return ID;
|
return ID;
|
||||||
|
|
|
||||||
|
|
@ -101,19 +101,12 @@ public class ExCommonEventHandler {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onConstructMod(FMLConstructModEvent event) {
|
public static void onConstructMod(FMLConstructModEvent event) {
|
||||||
event.enqueueWork(() -> {
|
event.enqueueWork(() -> {
|
||||||
getOrCreateCompatManager();
|
CompatManager orCreateCompatManager = Mod.getOrCreateCompatManager();
|
||||||
|
orCreateCompatManager
|
||||||
|
.registerCompat(Lib39Compat.ID, Lib39Compat.INSTANCE);
|
||||||
|
orCreateCompatManager.initialize();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* On fml common setup.
|
|
||||||
*
|
|
||||||
* @param event the event
|
|
||||||
*/
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onFMLCommonSetup(FMLCommonSetupEvent event) {
|
|
||||||
event.enqueueWork(() -> ExCommonEventHandler.Mod.getOrCreateCompatManager()
|
|
||||||
.registerCompat(Lib39Compat.ID, Lib39Compat.INSTANCE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register capability.
|
* Register capability.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user