mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
Merge remote-tracking branch 'upstream/dev' into dev
# Conflicts: # gradle.properties
This commit is contained in:
@@ -258,6 +258,16 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
|
||||
public class ItemParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[] {"items", "item"};
|
||||
private static final float VERSION_1_21_2 = 21.2f;
|
||||
private static final float VERSION_1_21_4 = 21.4f;
|
||||
|
||||
private boolean isModernFormatRequired() {
|
||||
return Config.packMaxVersion() >= VERSION_1_21_4;
|
||||
}
|
||||
|
||||
private boolean needsLegacyCompatibility() {
|
||||
return Config.packMinVersion() < VERSION_1_21_4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] sectionId() {
|
||||
@@ -281,7 +291,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
|
||||
|
||||
boolean isVanillaItem = isVanillaItem(id);
|
||||
Key material = Key.from(isVanillaItem ? id.value() : ResourceConfigUtils.requireNonEmptyStringOrThrow(section.get("material"), "warning.config.item.missing_material"));
|
||||
Key material = Key.from(isVanillaItem ? id.value() : ResourceConfigUtils.requireNonEmptyStringOrThrow(section.get("material"), "warning.config.item.missing_material").toLowerCase(Locale.ENGLISH));
|
||||
int customModelData = ResourceConfigUtils.getAsInt(section.getOrDefault("custom-model-data", 0), "custom-model-data");
|
||||
if (customModelData < 0) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.invalid_custom_model_data", String.valueOf(customModelData));
|
||||
@@ -338,7 +348,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
|
||||
// add it to category
|
||||
if (section.containsKey("category")) {
|
||||
plugin.itemBrowserManager().addExternalCategoryMember(id, MiscUtils.getAsStringList(section.get("category")).stream().map(Key::of).toList());
|
||||
AbstractItemManager.this.plugin.itemBrowserManager().addExternalCategoryMember(id, MiscUtils.getAsStringList(section.get("category")).stream().map(Key::of).toList());
|
||||
}
|
||||
|
||||
// model part, can be null
|
||||
@@ -353,7 +363,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
throw new LocalizedResourceConfigException("warning.config.item.missing_model_id");
|
||||
}
|
||||
// 1.21.4+必须要配置model区域
|
||||
if (Config.packMaxVersion() >= 21.4f && modelSection == null) {
|
||||
if (isModernFormatRequired() && modelSection == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.missing_model");
|
||||
}
|
||||
|
||||
@@ -362,47 +372,22 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
// 旧版格式
|
||||
TreeSet<LegacyOverridesModel> legacyOverridesModels = null;
|
||||
|
||||
if (Config.packMaxVersion() >= 21.4f) {
|
||||
if (isModernFormatRequired() || (needsLegacyCompatibility() && legacyModelSection == null)) {
|
||||
modernModel = ItemModels.fromMap(modelSection);
|
||||
for (ModelGeneration generation : modernModel.modelsToGenerate()) {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
// 如果最低支持版本低于1.21.4,则需要准备旧版overrides模型
|
||||
if (Config.packMinVersion() < 21.4f) {
|
||||
// 如果有旧版格式,就用旧版
|
||||
if (legacyModelSection != null) {
|
||||
LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection);
|
||||
for (ModelGeneration generation : legacyItemModel.modelsToGenerate()) {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
legacyOverridesModels = new TreeSet<>(legacyItemModel.overrides());
|
||||
} else {
|
||||
// 否则把新版格式并转换为旧版
|
||||
legacyOverridesModels = new TreeSet<>();
|
||||
processModelRecursively(modernModel, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData);
|
||||
if (legacyOverridesModels.isEmpty()) {
|
||||
TranslationManager.instance().log("warning.config.item.legacy_model.cannot_convert", path.toString(), id.asString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 最高支持版本不超过1.21.4,所以新版model格式为非必需
|
||||
else {
|
||||
// 如果有旧版格式,就用旧版
|
||||
if (needsLegacyCompatibility()) {
|
||||
if (legacyModelSection != null) {
|
||||
LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection);
|
||||
LegacyItemModel legacyItemModel = LegacyItemModel.fromMap(legacyModelSection, customModelData);
|
||||
for (ModelGeneration generation : legacyItemModel.modelsToGenerate()) {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
legacyOverridesModels = new TreeSet<>(legacyItemModel.overrides());
|
||||
} else {
|
||||
// 否则读新版格式并转换为旧版
|
||||
ItemModel model = ItemModels.fromMap(modelSection);
|
||||
for (ModelGeneration generation : model.modelsToGenerate()) {
|
||||
prepareModelGeneration(generation);
|
||||
}
|
||||
legacyOverridesModels = new TreeSet<>();
|
||||
processModelRecursively(model, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData);
|
||||
processModelRecursively(modernModel, new LinkedHashMap<>(), legacyOverridesModels, material, customModelData);
|
||||
if (legacyOverridesModels.isEmpty()) {
|
||||
TranslationManager.instance().log("warning.config.item.legacy_model.cannot_convert", path.toString(), id.asString());
|
||||
}
|
||||
@@ -413,29 +398,30 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
if (customModelData != 0) {
|
||||
// use custom model data
|
||||
// check conflict
|
||||
Map<Integer, Key> conflict = cmdConflictChecker.computeIfAbsent(material, k -> new HashMap<>());
|
||||
Map<Integer, Key> conflict = AbstractItemManager.this.cmdConflictChecker.computeIfAbsent(material, k -> new HashMap<>());
|
||||
if (conflict.containsKey(customModelData)) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.custom_model_data_conflict", String.valueOf(customModelData), conflict.get(customModelData).toString());
|
||||
}
|
||||
conflict.put(customModelData, id);
|
||||
// Parse models
|
||||
if (Config.packMaxVersion() >= 21.4f && modernModel != null) {
|
||||
TreeMap<Integer, ItemModel> map = modernOverrides.computeIfAbsent(material, k -> new TreeMap<>());
|
||||
if (isModernFormatRequired() && modernModel != null) {
|
||||
TreeMap<Integer, ItemModel> map = AbstractItemManager.this.modernOverrides.computeIfAbsent(material, k -> new TreeMap<>());
|
||||
map.put(customModelData, modernModel);
|
||||
}
|
||||
if (Config.packMinVersion() < 21.4f && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
TreeSet<LegacyOverridesModel> lom = legacyOverrides.computeIfAbsent(material, k -> new TreeSet<>());
|
||||
if (needsLegacyCompatibility() && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
TreeSet<LegacyOverridesModel> lom = AbstractItemManager.this.legacyOverrides.computeIfAbsent(material, k -> new TreeSet<>());
|
||||
lom.addAll(legacyOverridesModels);
|
||||
}
|
||||
}
|
||||
|
||||
// use item model
|
||||
if (itemModelKey != null) {
|
||||
if (Config.packMaxVersion() >= 21.4f && modernModel != null) {
|
||||
modernItemModels1_21_4.put(itemModelKey, modernModel);
|
||||
if (isModernFormatRequired() && modernModel != null) {
|
||||
AbstractItemManager.this.modernItemModels1_21_4.put(itemModelKey, modernModel);
|
||||
}
|
||||
if (Config.packMaxVersion() >= 21.2f && Config.packMinVersion() < 21.4f && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
modernItemModels1_21_2.put(itemModelKey, legacyOverridesModels);
|
||||
if (Config.packMaxVersion() >= VERSION_1_21_2 && needsLegacyCompatibility() && legacyOverridesModels != null && !legacyOverridesModels.isEmpty()) {
|
||||
TreeSet<LegacyOverridesModel> lom = AbstractItemManager.this.modernItemModels1_21_2.computeIfAbsent(itemModelKey, k -> new TreeSet<>());
|
||||
lom.addAll(legacyOverridesModels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,5 @@ public class ComponentKeys {
|
||||
public static final Key CUSTOM_DATA = Key.of("minecraft", "custom_data");
|
||||
public static final Key PROFILE = Key.of("minecraft", "profile");
|
||||
public static final Key DYED_COLOR = Key.of("minecraft", "dyed_color");
|
||||
public static final Key DEATH_PROTECTION = Key.of("minecraft", "death_protection");
|
||||
}
|
||||
|
||||
@@ -428,8 +428,10 @@ public abstract class AbstractPackManager implements PackManager {
|
||||
Yaml yaml = new Yaml(new StringKeyConstructor(new LoaderOptions()));
|
||||
for (Pack pack : loadedPacks()) {
|
||||
if (!pack.enabled()) continue;
|
||||
Path configurationFolderPath = pack.configurationFolder();
|
||||
if (!Files.isDirectory(configurationFolderPath)) continue;
|
||||
try {
|
||||
Files.walkFileTree(pack.configurationFolder(), new SimpleFileVisitor<>() {
|
||||
Files.walkFileTree(configurationFolderPath, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public @NotNull FileVisitResult visitFile(@NotNull Path path, @NotNull BasicFileAttributes attrs) {
|
||||
if (Files.isRegularFile(path) && path.getFileName().toString().endsWith(".yml")) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.momirealms.craftengine.core.pack.model;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.model.generation.ModelGeneration;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import software.amazon.awssdk.services.s3.endpoints.internal.Value;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class LegacyItemModel {
|
||||
private final List<ModelGeneration> modelsToGenerate;
|
||||
@@ -31,13 +32,38 @@ public class LegacyItemModel {
|
||||
return path;
|
||||
}
|
||||
|
||||
public static LegacyItemModel fromMap(Map<String, Object> legacyModel) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static LegacyItemModel fromMap(Map<String, Object> legacyModel, int customModelData) {
|
||||
String legacyModelPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(legacyModel.get("path"), "warning.config.item.legacy_model.missing_path");
|
||||
Map<String, Object> generation = MiscUtils.castToMap(legacyModel.get("generation"), true);
|
||||
ModelGeneration modelGeneration = null;
|
||||
ModelGeneration baseModelGeneration = null;
|
||||
if (generation != null) {
|
||||
modelGeneration = ModelGeneration.of(Key.of(legacyModelPath), generation);
|
||||
baseModelGeneration = ModelGeneration.of(Key.of(legacyModelPath), generation);
|
||||
}
|
||||
List<Map<String, Object>> overrides = (List<Map<String, Object>>) legacyModel.get("overrides");
|
||||
if (overrides != null) {
|
||||
List<ModelGeneration> modelGenerations = new ArrayList<>();
|
||||
List<LegacyOverridesModel> legacyOverridesModels = new ArrayList<>();
|
||||
if (baseModelGeneration != null) modelGenerations.add(baseModelGeneration);
|
||||
legacyOverridesModels.add(new LegacyOverridesModel(new HashMap<>(), legacyModelPath, customModelData));
|
||||
for (Map<String, Object> override : overrides) {
|
||||
String overrideModelPath = ResourceConfigUtils.requireNonEmptyStringOrThrow(override.get("path"), () -> new LocalizedResourceConfigException("warning.config.item.legacy_model.overrides.missing_path"));
|
||||
Map<String, Object> predicate = MiscUtils.castToMap(ResourceConfigUtils.requireNonNullOrThrow(override.get("predicate"), "warning.config.item.legacy_model.overrides.missing_predicate"), false);
|
||||
if (predicate.isEmpty()) {
|
||||
throw new LocalizedResourceConfigException("warning.config.item.legacy_model.overrides.missing_predicate");
|
||||
}
|
||||
Map<String, Object> overrideGeneration = MiscUtils.castToMap(override.get("generation"), true);
|
||||
if (overrideGeneration != null) {
|
||||
modelGenerations.add(ModelGeneration.of(Key.of(overrideModelPath), overrideGeneration));
|
||||
}
|
||||
legacyOverridesModels.add(new LegacyOverridesModel(predicate, overrideModelPath, customModelData));
|
||||
}
|
||||
return new LegacyItemModel(legacyModelPath, legacyOverridesModels, modelGenerations);
|
||||
} else {
|
||||
return new LegacyItemModel(legacyModelPath,
|
||||
List.of(new LegacyOverridesModel(new HashMap<>(), legacyModelPath, customModelData)),
|
||||
baseModelGeneration == null ? List.of() : List.of(baseModelGeneration)
|
||||
);
|
||||
}
|
||||
LegacyOverridesModel legacyOverridesModel = new LegacyOverridesModel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ package net.momirealms.craftengine.core.pack.model;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -11,8 +13,8 @@ public class LegacyOverridesModel implements Comparable<LegacyOverridesModel> {
|
||||
private final String model;
|
||||
private final int customModelData;
|
||||
|
||||
public LegacyOverridesModel(Map<String, Object> predicate, String model, int customModelData) {
|
||||
this.predicate = predicate;
|
||||
public LegacyOverridesModel(@Nullable Map<String, Object> predicate, @NotNull String model, int customModelData) {
|
||||
this.predicate = predicate == null ? new HashMap<>() : predicate;
|
||||
this.model = model;
|
||||
this.customModelData = customModelData;
|
||||
if (customModelData > 0) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class EqualsCondition<CTX extends Context> implements Condition<CTX> {
|
||||
@Override
|
||||
public Condition<CTX> create(Map<String, Object> arguments) {
|
||||
String value1 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value1"), "warning.config.condition.equals.missing_value1");
|
||||
String value2 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value1"), "warning.config.condition.equals.missing_value2");
|
||||
String value2 = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("value2"), "warning.config.condition.equals.missing_value2");
|
||||
return new EqualsCondition<>(TextProviders.fromString(value1), TextProviders.fromString(value2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class AbstractConditionalFunction<CTX extends Context> implement
|
||||
} else if (predicates instanceof Map<?,?> map) {
|
||||
return List.of(factory.apply(MiscUtils.castToMap(map, false)));
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported condition type: " + predicates.getClass().getSimpleName());
|
||||
throw new UnsupportedOperationException("Unsupported conditions argument class type: " + predicates.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
public final class CommonFunctions {
|
||||
private CommonFunctions() {}
|
||||
|
||||
public static final Key RUN_ALL = Key.of("craftengine:run_all");
|
||||
public static final Key RUN = Key.of("craftengine:run");
|
||||
public static final Key COMMAND = Key.of("craftengine:command");
|
||||
public static final Key MESSAGE = Key.of("craftengine:message");
|
||||
public static final Key ACTIONBAR = Key.of("craftengine:actionbar");
|
||||
public static final Key TITLE = Key.of("craftengine:title");
|
||||
public static final Key OPEN_WINDOW = Key.of("craftengine:open_window");
|
||||
public static final Key PARTICLE = Key.of("craftengine:particle");
|
||||
public static final Key SOUND = Key.of("craftengine:sound");
|
||||
public static final Key POTION_EFFECT = Key.of("craftengine:potion_effect");
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.function;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.context.*;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
|
||||
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
|
||||
import net.momirealms.craftengine.core.plugin.context.text.TextProvider;
|
||||
import net.momirealms.craftengine.core.plugin.context.text.TextProviders;
|
||||
import net.momirealms.craftengine.core.plugin.gui.GuiType;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class OpenWindowFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
|
||||
private final PlayerSelector<CTX> selector;
|
||||
private final GuiType guiType;
|
||||
private final TextProvider optionalTitle;
|
||||
|
||||
public OpenWindowFunction(List<Condition<CTX>> predicates, @Nullable PlayerSelector<CTX> selector, GuiType guiType, TextProvider optionalTitle) {
|
||||
super(predicates);
|
||||
this.selector = selector;
|
||||
this.guiType = guiType;
|
||||
this.optionalTitle = optionalTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInternal(CTX ctx) {
|
||||
Optional<Player> owner = ctx.getOptionalParameter(DirectContextParameters.PLAYER);
|
||||
if (this.selector == null) {
|
||||
owner.ifPresent(it -> {
|
||||
CraftEngine.instance().guiManager().openInventory(it, this.guiType);
|
||||
if (this.optionalTitle != null) {
|
||||
CraftEngine.instance().guiManager().updateInventoryTitle(it, AdventureHelper.miniMessage().deserialize(this.optionalTitle.get(ctx), ctx.tagResolvers()));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for (Player viewer : this.selector.get(ctx)) {
|
||||
CraftEngine.instance().guiManager().openInventory(viewer, this.guiType);
|
||||
if (this.optionalTitle != null) {
|
||||
RelationalContext relationalContext = ViewerContext.of(ctx, PlayerOptionalContext.of(viewer, ContextHolder.EMPTY));
|
||||
CraftEngine.instance().guiManager().updateInventoryTitle(viewer, AdventureHelper.miniMessage().deserialize(this.optionalTitle.get(relationalContext), relationalContext.tagResolvers()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return CommonFunctions.OPEN_WINDOW;
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
|
||||
|
||||
public FactoryImpl(java.util.function.Function<Map<String, Object>, Condition<CTX>> factory) {
|
||||
super(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function<CTX> create(Map<String, Object> arguments) {
|
||||
TextProvider title = Optional.ofNullable(arguments.get("title")).map(String::valueOf).map(TextProviders::fromString).orElse(null);
|
||||
String rawType = ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("gui-type"), "warning.config.function.open_window.missing_gui_type");
|
||||
try {
|
||||
GuiType type = GuiType.valueOf(rawType.toUpperCase(Locale.ENGLISH));
|
||||
return new OpenWindowFunction<>(getPredicates(arguments), PlayerSelectors.fromObject(arguments.get("target"), conditionFactory()), type, title);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new LocalizedResourceConfigException("warning.config.function.open_window.invalid_gui_type", e, rawType, EnumUtils.toString(GuiType.values()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package net.momirealms.craftengine.core.plugin.context.function;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
|
||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.event.EventFunctions;
|
||||
import net.momirealms.craftengine.core.util.*;
|
||||
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class RunFunction<CTX extends Context> extends AbstractConditionalFunction<CTX> {
|
||||
private final List<Function<CTX>> functions;
|
||||
private final NumberProvider delay;
|
||||
|
||||
public RunFunction(List<Function<CTX>> functions, NumberProvider delay, List<Condition<CTX>> predicates) {
|
||||
super(predicates);
|
||||
this.functions = functions;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runInternal(CTX ctx) {
|
||||
int delay = this.delay.getInt(ctx);
|
||||
if (delay <= 0) {
|
||||
for (Function<CTX> function : functions) {
|
||||
function.run(ctx);
|
||||
}
|
||||
} else {
|
||||
Optional<WorldPosition> position = ctx.getOptionalParameter(DirectContextParameters.POSITION);
|
||||
if (!VersionHelper.isFolia() || position.isEmpty()) {
|
||||
CraftEngine.instance().scheduler().sync().runLater(() -> {
|
||||
for (Function<CTX> function : functions) {
|
||||
function.run(ctx);
|
||||
}
|
||||
}, delay);
|
||||
} else {
|
||||
WorldPosition pos = position.get();
|
||||
CraftEngine.instance().scheduler().sync().runLater(() -> {
|
||||
for (Function<CTX> function : functions) {
|
||||
function.run(ctx);
|
||||
}
|
||||
}, delay, pos.world().platformWorld(), MCUtils.fastFloor(pos.x()) >> 4, MCUtils.fastFloor(pos.z()) >> 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return CommonFunctions.RUN;
|
||||
}
|
||||
|
||||
public static class FactoryImpl<CTX extends Context> extends AbstractFactory<CTX> {
|
||||
private final java.util.function.Function<Map<String, Object>, Function<CTX>> functionFactory;
|
||||
|
||||
public FactoryImpl(java.util.function.Function<Map<String, Object>, Function<CTX>> functionFactory, java.util.function.Function<Map<String, Object>, Condition<CTX>> conditionFactory) {
|
||||
super(conditionFactory);
|
||||
this.functionFactory = functionFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function<CTX> create(Map<String, Object> arguments) {
|
||||
NumberProvider delay = NumberProviders.fromObject(arguments.getOrDefault("delay", 0));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> functions = (List<Map<String, Object>>) ResourceConfigUtils.requireNonNullOrThrow(arguments.get("functions"), "warning.config.function.run.missing_functions");
|
||||
List<Function<CTX>> fun = new ArrayList<>();
|
||||
for (Map<String, Object> function : functions) {
|
||||
fun.add(this.functionFactory.apply(function));
|
||||
}
|
||||
return new RunFunction<>(fun, delay, getPredicates(arguments));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,9 @@ public class EventFunctions {
|
||||
register(CommonFunctions.MESSAGE, new MessageFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.ACTIONBAR, new ActionBarFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.TITLE, new TitleFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.OPEN_WINDOW, new OpenWindowFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.CANCEL_EVENT, new CancelEventFunction.FactoryImpl<>(EventConditions::fromMap));
|
||||
register(CommonFunctions.RUN, new RunFunction.FactoryImpl<>(EventFunctions::fromMap, EventConditions::fromMap));
|
||||
}
|
||||
|
||||
public static void register(Key key, FunctionFactory<PlayerOptionalContext> factory) {
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package net.momirealms.craftengine.core.plugin.gui;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
|
||||
public interface GuiManager extends Manageable {
|
||||
|
||||
void openInventory(Player player, GuiType guiType);
|
||||
|
||||
void updateInventoryTitle(Player player, Component component);
|
||||
|
||||
Inventory createInventory(Gui gui, int size);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.momirealms.craftengine.core.plugin.gui;
|
||||
|
||||
public enum GuiType {
|
||||
ANVIL,
|
||||
CARTOGRAPHY,
|
||||
ENCHANTMENT,
|
||||
GRINDSTONE,
|
||||
LOOM,
|
||||
SMITHING,
|
||||
CRAFTING
|
||||
}
|
||||
@@ -20,6 +20,10 @@ public interface RegionExecutor<W> extends Executor {
|
||||
|
||||
SchedulerTask runAsyncLater(Runnable runnable, long delay);
|
||||
|
||||
default SchedulerTask runLater(Runnable runnable, long delay) {
|
||||
return runLater(runnable, delay, null, 0 ,0);
|
||||
}
|
||||
|
||||
SchedulerTask runLater(Runnable runnable, long delay, W world, int x, int z);
|
||||
|
||||
SchedulerTask runRepeating(Runnable runnable, long delay, long period, W world, int x, int z);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.core.util;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -13,7 +14,7 @@ public class IntIdentityList implements IndexedIterable<Integer> {
|
||||
|
||||
public IntIdentityList(int size) {
|
||||
this.size = size;
|
||||
list = new ArrayList<>(size);
|
||||
list = new IntArrayList(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user