9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 18:09:27 +00:00

就这样吧

This commit is contained in:
XiaoMoMi
2025-05-02 18:24:32 +08:00
parent ec627ffc79
commit 6bdd3dccde
27 changed files with 105 additions and 98 deletions

View File

@@ -148,10 +148,10 @@ public class CropBlockBehavior extends BushBlockBehavior {
int z = FastNMS.INSTANCE.field$Vec3i$z(pos);
net.momirealms.craftengine.core.world.World wrappedWorld = new BukkitWorld(world);
int i = this.getAge(immutableBlockState) + this.boneMealBonus.getInt(new LootContext(wrappedWorld, ContextHolder.builder()
int i = this.getAge(immutableBlockState) + this.boneMealBonus.getInt(new LootContext(wrappedWorld, 1, ThreadLocalRandom.current(), ContextHolder.builder()
.withParameter(LootParameters.WORLD, wrappedWorld)
.withParameter(LootParameters.LOCATION, Vec3d.atCenterOf(new Vec3i(x, y, z)))
.build(), ThreadLocalRandom.current(), 1));
.build()));
int maxAge = this.ageProperty.max;
if (i > maxAge) {
i = maxAge;

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.loot;
import net.momirealms.craftengine.core.util.context.CommonContext;
import net.momirealms.craftengine.core.util.context.ContextHolder;
import net.momirealms.craftengine.core.util.context.ContextKey;
import net.momirealms.craftengine.core.world.World;
@@ -7,43 +8,30 @@ import net.momirealms.craftengine.core.world.World;
import java.util.Optional;
import java.util.Random;
public class LootContext {
public class LootContext extends CommonContext {
private final World world;
private final ContextHolder contexts;
private final Random randomSource;
private final float luck;
public LootContext(World world, ContextHolder contexts, Random randomSource, float luck) {
public LootContext(World world, float luck, Random randomSource, ContextHolder contexts) {
super(contexts);
this.randomSource = randomSource;
this.contexts = contexts;
this.world = world;
this.luck = luck;
}
public Random randomSource() {
return randomSource;
return this.randomSource;
}
public <T> Optional<T> getOptionalParameter(ContextKey<T> parameter) {
return this.contexts.getOptional(parameter);
}
public boolean hasParameter(ContextKey<?> parameter) {
return this.contexts.has(parameter);
}
public <T> T getParameterOrThrow(ContextKey<T> parameter) {
return this.contexts.getOrThrow(parameter);
return super.contexts.getOptional(parameter);
}
public float luck() {
return luck;
}
public ContextHolder contexts() {
return contexts;
}
public World world() {
return world;
}

View File

@@ -80,7 +80,7 @@ public class LootTable<T> {
}
public ArrayList<Item<T>> getRandomItems(ContextHolder parameters, World world) {
return this.getRandomItems(new LootContext(world, parameters, ThreadLocalRandom.current(), 1));
return this.getRandomItems(new LootContext(world, 1, ThreadLocalRandom.current(), parameters));
}
private ArrayList<Item<T>> getRandomItems(LootContext context) {

View File

@@ -30,6 +30,7 @@ public class AllOfCondition implements LootCondition {
}
public static class Factory implements LootConditionFactory {
@SuppressWarnings("unchecked")
@Override
public LootCondition create(Map<String, Object> arguments) {

View File

@@ -7,7 +7,7 @@ import net.momirealms.craftengine.core.font.BitmapImage;
import net.momirealms.craftengine.core.font.Font;
import net.momirealms.craftengine.core.item.EquipmentData;
import net.momirealms.craftengine.core.pack.conflict.PathContext;
import net.momirealms.craftengine.core.pack.conflict.resolution.ConditionalResolution;
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionConditional;
import net.momirealms.craftengine.core.pack.host.ResourcePackHost;
import net.momirealms.craftengine.core.pack.host.ResourcePackHosts;
import net.momirealms.craftengine.core.pack.host.impl.NoneHost;
@@ -1159,7 +1159,7 @@ public abstract class AbstractPackManager implements PackManager {
PathContext relativeCTX = PathContext.of(relative);
PathContext targetCTX = PathContext.of(targetPath);
PathContext fileCTX = PathContext.of(file);
for (ConditionalResolution resolution : Config.resolutions()) {
for (ResolutionConditional resolution : Config.resolutions()) {
if (resolution.matcher().test(relativeCTX)) {
resolution.resolution().run(targetCTX, fileCTX);
return FileVisitResult.CONTINUE;

View File

@@ -10,18 +10,13 @@ import net.momirealms.craftengine.core.util.context.Condition;
import java.util.List;
import java.util.Map;
public class AllOfPathMatcher extends AllOfCondition<PathContext> implements PathMatcher {
public class PathMatcherAllOf extends AllOfCondition<PathContext> implements PathMatcher {
public static final Factory FACTORY = new Factory();
public AllOfPathMatcher(List<? extends Condition<PathContext>> conditions) {
public PathMatcherAllOf(List<? extends Condition<PathContext>> conditions) {
super(conditions);
}
@Override
public Key type() {
return PathMatchers.ALL_OF;
}
public static class Factory implements PathMatcherFactory {
@SuppressWarnings("unchecked")
@@ -30,10 +25,10 @@ public class AllOfPathMatcher extends AllOfCondition<PathContext> implements Pat
Object termsObj = arguments.get("terms");
if (termsObj instanceof List<?> list) {
List<Map<String, Object>> terms = (List<Map<String, Object>>) list;
return new AllOfPathMatcher(PathMatchers.fromMapList(terms));
return new PathMatcherAllOf(PathMatchers.fromMapList(terms));
} else if (termsObj instanceof Map<?, ?>) {
Map<String, Object> terms = MiscUtils.castToMap(termsObj, false);
return new AllOfPathMatcher(PathMatchers.fromMapList(List.of(terms)));
return new PathMatcherAllOf(PathMatchers.fromMapList(List.of(terms)));
} else {
throw new LocalizedException("warning.config.conflict_matcher.all_of.missing_terms");
}

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.pack.conflict.matcher;
import net.momirealms.craftengine.core.pack.conflict.PathContext;
import net.momirealms.craftengine.core.plugin.locale.LocalizedException;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.MiscUtils;
import net.momirealms.craftengine.core.util.condition.AnyOfCondition;
import net.momirealms.craftengine.core.util.context.Condition;
@@ -10,18 +9,13 @@ import net.momirealms.craftengine.core.util.context.Condition;
import java.util.List;
import java.util.Map;
public class AnyOfPathMatcher extends AnyOfCondition<PathContext> implements PathMatcher {
public class PathMatcherAnyOf extends AnyOfCondition<PathContext> implements PathMatcher {
public static final Factory FACTORY = new Factory();
public AnyOfPathMatcher(List<? extends Condition<PathContext>> conditions) {
public PathMatcherAnyOf(List<? extends Condition<PathContext>> conditions) {
super(conditions);
}
@Override
public Key type() {
return PathMatchers.ANY_OF;
}
public static class Factory implements PathMatcherFactory {
@SuppressWarnings("unchecked")
@@ -30,10 +24,10 @@ public class AnyOfPathMatcher extends AnyOfCondition<PathContext> implements Pat
Object termsObj = arguments.get("terms");
if (termsObj instanceof List<?> list) {
List<Map<String, Object>> terms = (List<Map<String, Object>>) list;
return new AnyOfPathMatcher(PathMatchers.fromMapList(terms));
return new PathMatcherAnyOf(PathMatchers.fromMapList(terms));
} else if (termsObj instanceof Map<?, ?>) {
Map<String, Object> terms = MiscUtils.castToMap(termsObj, false);
return new AnyOfPathMatcher(PathMatchers.fromMapList(List.of(terms)));
return new PathMatcherAnyOf(PathMatchers.fromMapList(List.of(terms)));
} else {
throw new LocalizedException("warning.config.conflict_matcher.any_of.missing_terms");
}

View File

@@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class PathContainsMatcher implements PathMatcher {
public class PathMatcherContains implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String path;
public PathContainsMatcher(String path) {
public PathMatcherContains(String path) {
this.path = path;
}
@@ -31,7 +31,7 @@ public class PathContainsMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.contains.missing_path"));
return new PathContainsMatcher(path);
return new PathMatcherContains(path);
}
}
}

View File

@@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class ExactPathMatcher implements PathMatcher {
public class PathMatcherExact implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String path;
public ExactPathMatcher(String path) {
public PathMatcherExact(String path) {
this.path = path;
}
@@ -31,7 +31,7 @@ public class ExactPathMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String path = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("path"), () -> new LocalizedException("warning.config.conflict_matcher.exact.missing_path"));
return new ExactPathMatcher(path);
return new PathMatcherExact(path);
}
}
}

View File

@@ -7,11 +7,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.util.Map;
public class FilenameMatcher implements PathMatcher {
public class PathMatcherFilename implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String name;
public FilenameMatcher(String name) {
public PathMatcherFilename(String name) {
this.name = name;
}
@@ -31,7 +31,7 @@ public class FilenameMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String name = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("name"), () -> new LocalizedException("warning.config.conflict_matcher.filename.missing_name"));
return new FilenameMatcher(name);
return new PathMatcherFilename(name);
}
}
}

View File

@@ -9,25 +9,20 @@ import net.momirealms.craftengine.core.util.condition.InvertedCondition;
import java.util.Map;
public class InvertedPathMatcher extends InvertedCondition<PathContext> implements PathMatcher {
public class PathMatcherInverted extends InvertedCondition<PathContext> implements PathMatcher {
public static final Factory FACTORY = new Factory();
public InvertedPathMatcher(PathMatcher condition) {
public PathMatcherInverted(PathMatcher condition) {
super(condition);
}
@Override
public Key type() {
return PathMatchers.INVERTED;
}
public static class Factory implements PathMatcherFactory {
@Override
public PathMatcher create(Map<String, Object> arguments) {
Object inverted = ResourceConfigUtils.requireNonNullOrThrow(arguments.get("term"), () -> new LocalizedException("warning.config.conflict_matcher.inverted.missing_term"));
Map<String, Object> term = MiscUtils.castToMap(inverted, false);
return new InvertedPathMatcher(PathMatchers.fromMap(term));
return new PathMatcherInverted(PathMatchers.fromMap(term));
}
}
}

View File

@@ -8,11 +8,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
public class ParentPathPrefixMatcher implements PathMatcher {
public class PathMatcherParentPrefix implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String prefix;
public ParentPathPrefixMatcher(String prefix) {
public PathMatcherParentPrefix(String prefix) {
this.prefix = prefix;
}
@@ -34,7 +34,7 @@ public class ParentPathPrefixMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String prefix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("prefix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_prefix.missing_prefix"));
return new ParentPathPrefixMatcher(prefix);
return new PathMatcherParentPrefix(prefix);
}
}
}

View File

@@ -8,11 +8,11 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import java.nio.file.Path;
import java.util.Map;
public class ParentPathSuffixMatcher implements PathMatcher {
public class PathMatcherParentSuffix implements PathMatcher {
public static final Factory FACTORY = new Factory();
private final String suffix;
public ParentPathSuffixMatcher(String suffix) {
public PathMatcherParentSuffix(String suffix) {
this.suffix = suffix;
}
@@ -34,7 +34,7 @@ public class ParentPathSuffixMatcher implements PathMatcher {
@Override
public PathMatcher create(Map<String, Object> arguments) {
String suffix = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("suffix"), () -> new LocalizedException("warning.config.conflict_matcher.parent_suffix.missing_suffix"));
return new ParentPathSuffixMatcher(suffix);
return new PathMatcherParentSuffix(suffix);
}
}
}

View File

@@ -8,6 +8,7 @@ import net.momirealms.craftengine.core.registry.WritableRegistry;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
import net.momirealms.craftengine.core.util.ResourceKey;
import net.momirealms.craftengine.core.util.condition.AllOfCondition;
import java.util.ArrayList;
import java.util.List;
@@ -25,15 +26,15 @@ public class PathMatchers {
public static final Key INVERTED = Key.of("craftengine:inverted");
static {
register(PARENT_PATH_SUFFIX, ParentPathSuffixMatcher.FACTORY);
register(PARENT_PATH_PREFIX, ParentPathPrefixMatcher.FACTORY);
register(PARENT_PATH_SUFFIX, PathMatcherParentSuffix.FACTORY);
register(PARENT_PATH_PREFIX, PathMatcherParentPrefix.FACTORY);
register(PATTERN, PathPatternMatcher.FACTORY);
register(EXACT, ExactPathMatcher.FACTORY);
register(FILENAME, FilenameMatcher.FACTORY);
register(ANY_OF, AnyOfPathMatcher.FACTORY);
register(ALL_OF, AllOfPathMatcher.FACTORY);
register(INVERTED, InvertedPathMatcher.FACTORY);
register(CONTAINS, PathContainsMatcher.FACTORY);
register(EXACT, PathMatcherExact.FACTORY);
register(FILENAME, PathMatcherFilename.FACTORY);
register(ANY_OF, PathMatcherAnyOf.FACTORY);
register(ALL_OF, PathMatcherAllOf.FACTORY);
register(INVERTED, PathMatcherInverted.FACTORY);
register(CONTAINS, PathMatcherContains.FACTORY);
}
public static void register(Key key, PathMatcherFactory factory) {

View File

@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.util.MiscUtils;
import java.util.Map;
public record ConditionalResolution(PathMatcher matcher, Resolution resolution) implements Resolution {
public record ResolutionConditional(PathMatcher matcher, Resolution resolution) implements Resolution {
public static final Factory FACTORY = new Factory();
@Override
@@ -26,10 +26,10 @@ public record ConditionalResolution(PathMatcher matcher, Resolution resolution)
public static class Factory implements ResolutionFactory {
@Override
public ConditionalResolution create(Map<String, Object> arguments) {
public ResolutionConditional create(Map<String, Object> arguments) {
Map<String, Object> term = MiscUtils.castToMap(arguments.get("term"), false);
Map<String, Object> resolution = MiscUtils.castToMap(arguments.get("resolution"), false);
return new ConditionalResolution(PathMatchers.fromMap(term), Resolutions.fromMap(resolution));
return new ResolutionConditional(PathMatchers.fromMap(term), Resolutions.fromMap(resolution));
}
}
}

View File

@@ -12,9 +12,9 @@ import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
public class MergeAltasResolution implements Resolution {
public class ResolutionMergeAltas implements Resolution {
public static final Factory FACTORY = new Factory();
public static final MergeAltasResolution INSTANCE = new MergeAltasResolution();
public static final ResolutionMergeAltas INSTANCE = new ResolutionMergeAltas();
@Override
public void run(PathContext existing, PathContext conflict) {

View File

@@ -9,11 +9,11 @@ import net.momirealms.craftengine.core.util.Key;
import java.io.IOException;
import java.util.Map;
public class MergeJsonResolution implements Resolution {
public class ResolutionMergeJson implements Resolution {
public static final Factory FACTORY = new Factory();
private final boolean deeply;
public MergeJsonResolution(boolean deeply) {
public ResolutionMergeJson(boolean deeply) {
this.deeply = deeply;
}
@@ -44,7 +44,7 @@ public class MergeJsonResolution implements Resolution {
@Override
public Resolution create(Map<String, Object> arguments) {
boolean deeply = (boolean) arguments.getOrDefault("deeply", false);
return new MergeJsonResolution(deeply);
return new ResolutionMergeJson(deeply);
}
}
}

View File

@@ -11,11 +11,11 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
public class MergePackMcMetaResolution implements Resolution {
public class ResolutionMergePackMcMeta implements Resolution {
public static final Factory FACTORY = new Factory();
private final String description;
public MergePackMcMetaResolution(String description) {
public ResolutionMergePackMcMeta(String description) {
this.description = description;
}
@@ -209,7 +209,7 @@ public class MergePackMcMetaResolution implements Resolution {
@Override
public Resolution create(Map<String, Object> arguments) {
String description = arguments.getOrDefault("description", "<gray>CraftEngine ResourcePack</gray>").toString();
return new MergePackMcMetaResolution(description);
return new ResolutionMergePackMcMeta(description);
}
}
}

View File

@@ -20,10 +20,10 @@ public class Resolutions {
static {
register(RETAIN_MATCHING, RetainMatchingResolution.FACTORY);
register(MERGE_JSON, MergeJsonResolution.FACTORY);
register(CONDITIONAL, ConditionalResolution.FACTORY);
register(MERGE_PACK_MCMETA, MergePackMcMetaResolution.FACTORY);
register(MERGE_ATLAS, MergeAltasResolution.FACTORY);
register(MERGE_JSON, ResolutionMergeJson.FACTORY);
register(CONDITIONAL, ResolutionConditional.FACTORY);
register(MERGE_PACK_MCMETA, ResolutionMergePackMcMeta.FACTORY);
register(MERGE_ATLAS, ResolutionMergeAltas.FACTORY);
}
public static void register(Key key, ResolutionFactory factory) {

View File

@@ -13,7 +13,7 @@ import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import dev.dejvokep.boostedyaml.utils.format.NodeRole;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.core.entity.furniture.ColliderType;
import net.momirealms.craftengine.core.pack.conflict.resolution.ConditionalResolution;
import net.momirealms.craftengine.core.pack.conflict.resolution.ResolutionConditional;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.PluginProperties;
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
@@ -54,7 +54,7 @@ public class Config {
protected boolean resource_pack$remove_tinted_leaves_particle;
protected boolean resource_pack$generate_mod_assets;
protected boolean resource_pack$override_uniform_font;
protected List<ConditionalResolution> resource_pack$duplicated_files_handler;
protected List<ResolutionConditional> resource_pack$duplicated_files_handler;
protected List<String> resource_pack$merge_external_folders;
protected boolean resource_pack$protection$crash_tools$method_1;
@@ -245,7 +245,7 @@ public class Config {
try {
resource_pack$duplicated_files_handler = config.getMapList("resource-pack.duplicated-files-handler").stream().map(it -> {
Map<String, Object> args = MiscUtils.castToMap(it, false);
return ConditionalResolution.FACTORY.create(args);
return ResolutionConditional.FACTORY.create(args);
}).toList();
} catch (LocalizedResourceConfigException e) {
TranslationManager.instance().log(e.node(), e.arguments());
@@ -479,7 +479,7 @@ public class Config {
return instance.resource_pack$delivery$file_to_upload;
}
public static List<ConditionalResolution> resolutions() {
public static List<ResolutionConditional> resolutions() {
return instance.resource_pack$duplicated_files_handler;
}

View File

@@ -2,7 +2,6 @@ package net.momirealms.craftengine.core.plugin.text.minimessage;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.momirealms.craftengine.core.util.context.Context;
import net.momirealms.craftengine.core.util.context.ContextHolder;
public interface MiniMessageTextContext extends Context {

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.util.condition;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.context.Condition;
import java.util.List;
@@ -20,4 +21,9 @@ public abstract class AllOfCondition<CTX> implements Condition<CTX> {
}
return true;
}
@Override
public Key type() {
return CommonConditions.ALL_OF;
}
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.util.condition;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.context.Condition;
import java.util.List;
@@ -20,4 +21,9 @@ public abstract class AnyOfCondition<CTX> implements Condition<CTX> {
}
return false;
}
@Override
public Key type() {
return CommonConditions.ANY_OF;
}
}

View File

@@ -0,0 +1,11 @@
package net.momirealms.craftengine.core.util.condition;
import net.momirealms.craftengine.core.util.Key;
public final class CommonConditions {
private CommonConditions() {}
public static final Key ALL_OF = Key.of("craftengine:all_of");
public static final Key ANY_OF = Key.of("craftengine:any_of");
public static final Key INVERTED = Key.of("craftengine:inverted");
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.util.condition;
import net.momirealms.craftengine.core.util.Key;
import net.momirealms.craftengine.core.util.context.Condition;
public abstract class InvertedCondition<CTX> implements Condition<CTX> {
@@ -13,4 +14,9 @@ public abstract class InvertedCondition<CTX> implements Condition<CTX> {
public boolean test(CTX ctx) {
return !this.condition.test(ctx);
}
@Override
public Key type() {
return CommonConditions.INVERTED;
}
}

View File

@@ -1,14 +1,14 @@
package net.momirealms.craftengine.core.util.context;
public abstract class CommonContext implements Context {
protected final ContextHolder holder;
protected final ContextHolder contexts;
public CommonContext(ContextHolder holder) {
this.holder = holder;
public CommonContext(ContextHolder contexts) {
this.contexts = contexts;
}
@Override
public ContextHolder contexts() {
return holder;
return contexts;
}
}

View File

@@ -1,4 +1,9 @@
package net.momirealms.craftengine.core.util.context;
public class CommonParameters {
public final class CommonParameters {
private CommonParameters() {}
public static ContextKey<Double> RANDOM = ContextKey.of("random");
public static ContextKey<Double> LAST_RANDOM = ContextKey.of("last_random");
}