New option: extra logic worlds
Mods like "create" make use of level wrappers to implement functions which breaks Arclight. By default, Arclight prevents these levels(side from ServerLevel and WorldGenRegion) firing Bukkit events. If any mods extends these two classes and use them not as a wrapper, users need add class names to this option.
This commit is contained in:
parent
16af4bd81c
commit
54f32cf7d7
|
@ -1,14 +1,22 @@
|
|||
package io.izzel.arclight.common.mod.util;
|
||||
|
||||
import io.izzel.arclight.common.mod.ArclightMod;
|
||||
import io.izzel.arclight.i18n.ArclightConfig;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.WorldGenRegion;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class DistValidate {
|
||||
|
||||
private static final Marker MARKER = MarkerManager.getMarker("EXT_LOGIC");
|
||||
|
||||
public static boolean isValid(UseOnContext context) {
|
||||
return context != null && isValid(context.getLevel());
|
||||
}
|
||||
|
@ -26,6 +34,17 @@ public class DistValidate {
|
|||
private static boolean isLogicWorld(LevelAccessor level) {
|
||||
var cl = level.getClass();
|
||||
return cl == ServerLevel.class || cl == WorldGenRegion.class
|
||||
|| ArclightConfig.spec().getCompat().getExtraLogicWorlds().contains(cl.getName());
|
||||
|| isLogicWorld(cl);
|
||||
}
|
||||
|
||||
private static final Map<Class<?>, Boolean> SEEN_CLASSES = new ConcurrentHashMap<>();
|
||||
|
||||
private static boolean isLogicWorld(Class<?> cl) {
|
||||
return SEEN_CLASSES.computeIfAbsent(cl, c -> {
|
||||
var name = c.getName();
|
||||
var result = ArclightConfig.spec().getCompat().getExtraLogicWorlds().contains(cl.getName());
|
||||
ArclightMod.LOGGER.warn(MARKER, "Level class {} treated as logic world: {}", name, result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package io.izzel.arclight.i18n.conf;
|
|||
import ninja.leaping.configurate.objectmapping.Setting;
|
||||
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@ConfigSerializable
|
||||
public class CompatSpec {
|
||||
|
@ -16,12 +16,11 @@ public class CompatSpec {
|
|||
@Setting("entity-property-overrides")
|
||||
private Map<String, EntityPropertySpec> entities;
|
||||
|
||||
// todo Enable this by default in 1.17
|
||||
@Setting("symlink-world")
|
||||
private boolean symlinkWorld;
|
||||
|
||||
@Setting("extra-logic-worlds")
|
||||
private Set<String> extraLogicWorlds;
|
||||
private List<String> extraLogicWorlds;
|
||||
|
||||
public Map<String, MaterialPropertySpec> getMaterials() {
|
||||
return materials;
|
||||
|
@ -43,7 +42,7 @@ public class CompatSpec {
|
|||
return symlinkWorld;
|
||||
}
|
||||
|
||||
public Set<String> getExtraLogicWorlds() {
|
||||
public List<String> getExtraLogicWorlds() {
|
||||
return extraLogicWorlds;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ compatibility {
|
|||
entity-property-overrides {
|
||||
}
|
||||
symlink-world = false
|
||||
extra-logic-worlds = []
|
||||
extra-logic-worlds = [
|
||||
"com.example.mod.ExtraLogicWorld"
|
||||
]
|
||||
}
|
||||
async-catcher {
|
||||
dump = true
|
||||
|
|
|
@ -111,5 +111,9 @@ comments {
|
|||
" and cause data loss on plugins relying world names"
|
||||
"See https://github.com/IzzelAliz/Arclight/wiki/World-Symlink for more detail"
|
||||
]
|
||||
extra-logic-worlds.comment = [
|
||||
"Extra worlds running logic"
|
||||
"If any mods do not function well, try search class names in logs related to [EXT_LOGIC] and add them here"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,5 +111,9 @@ comments {
|
|||
"变更此设置会导致模组世界名称变化,可能造成依赖世界名称的插件数据丢失"
|
||||
"参见 https://github.com/IzzelAliz/Arclight/wiki/World-Symlink"
|
||||
]
|
||||
extra-logic-worlds.comment = [
|
||||
"额外运行逻辑的维度类名"
|
||||
"如果有模组世界/功能运行不正常,尝试在日志中搜索和 [EXT_LOGIC] 有关的对应类名并添加"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user