mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-25 09:59:20 +00:00
修复锻造台概率生效
This commit is contained in:
@@ -129,7 +129,7 @@ public class BukkitFontManager extends AbstractFontManager implements Listener {
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onAnvilRename(PrepareAnvilEvent event) {
|
||||
if (!Config.allowEmojiAnvil() || super.emojiKeywordTrie == null) {
|
||||
return;
|
||||
|
||||
@@ -339,32 +339,6 @@ public class ComponentItemFactory extends BukkitItemFactory {
|
||||
return Optional.ofNullable((Integer) ComponentType.encodeJava(ComponentKeys.REPAIR_COST, item.getComponent(ComponentKeys.REPAIR_COST)).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemWrapper<ItemStack> mergeCopy(ItemWrapper<ItemStack> item1, ItemWrapper<ItemStack> item2) {
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
try {
|
||||
Object itemStack3 = Reflections.method$ItemStack$transmuteCopy.invoke(itemStack1, Reflections.method$ItemStack$getItem.invoke(itemStack2), 1);
|
||||
Reflections.method$ItemStack$applyComponents.invoke(itemStack3, Reflections.method$ItemStack$getComponentsPatch.invoke(itemStack2));
|
||||
return new RTagItemWrapper(new RtagItem(ItemObject.asCraftMirror(itemStack3)), item2.count());
|
||||
} catch (Exception e) {
|
||||
this.plugin.logger().warn("Failed to merge item", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(ItemWrapper<ItemStack> item1, ItemWrapper<ItemStack> item2) {
|
||||
// load previous changes on nms items
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
try {
|
||||
Reflections.method$ItemStack$applyComponents.invoke(itemStack1, Reflections.method$ItemStack$getComponentsPatch.invoke(itemStack2));
|
||||
} catch (Exception e) {
|
||||
plugin.logger().warn("Failed to merge item", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void trim(ItemWrapper<ItemStack> item, Trim trim) {
|
||||
if (trim == null) {
|
||||
@@ -388,4 +362,30 @@ public class ComponentItemFactory extends BukkitItemFactory {
|
||||
Map<String, String> trimMap = (Map<String, String>) trim.get();
|
||||
return Optional.of(new Trim(trimMap.get("pattern"), trimMap.get("material")));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemWrapper<ItemStack> mergeCopy(ItemWrapper<ItemStack> item1, ItemWrapper<ItemStack> item2) {
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
try {
|
||||
Object itemStack3 = FastNMS.INSTANCE.method$ItemStack$transmuteCopy(itemStack1, itemStack2);
|
||||
FastNMS.INSTANCE.method$ItemStack$applyComponents(itemStack3, FastNMS.INSTANCE.method$ItemStack$getComponentsPatch(itemStack2));
|
||||
return new RTagItemWrapper(new RtagItem(ItemObject.asCraftMirror(itemStack3)), item2.count());
|
||||
} catch (Exception e) {
|
||||
this.plugin.logger().warn("Failed to merge item", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void merge(ItemWrapper<ItemStack> item1, ItemWrapper<ItemStack> item2) {
|
||||
// load previous changes on nms items
|
||||
Object itemStack1 = item1.getLiteralObject();
|
||||
Object itemStack2 = item2.getLiteralObject();
|
||||
try {
|
||||
FastNMS.INSTANCE.method$ItemStack$applyComponents(itemStack1, FastNMS.INSTANCE.method$ItemStack$getComponentsPatch(itemStack2));
|
||||
} catch (Exception e) {
|
||||
plugin.logger().warn("Failed to merge item", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -447,7 +447,7 @@ public class RecipeEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onAnvilCombineItems(PrepareAnvilEvent event) {
|
||||
AnvilInventory inventory = event.getInventory();
|
||||
ItemStack first = inventory.getFirstItem();
|
||||
@@ -490,7 +490,7 @@ public class RecipeEventListener implements Listener {
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
|
||||
public void onAnvilRepairItems(PrepareAnvilEvent event) {
|
||||
AnvilInventory inventory = event.getInventory();
|
||||
ItemStack first = inventory.getFirstItem();
|
||||
@@ -644,7 +644,7 @@ public class RecipeEventListener implements Listener {
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
public void onAnvilRenameItem(PrepareAnvilEvent event) {
|
||||
AnvilInventory inventory = event.getInventory();
|
||||
ItemStack first = inventory.getFirstItem();
|
||||
|
||||
@@ -320,7 +320,7 @@ public class BukkitServerPlayer extends Player {
|
||||
if (VersionHelper.isFolia()) {
|
||||
try {
|
||||
Object serverPlayer = serverPlayer();
|
||||
Object gameMode = Reflections.field$ServerPlayer$gameMode.get(serverPlayer);
|
||||
Object gameMode = FastNMS.INSTANCE.field$ServerPlayer$gameMode(serverPlayer);
|
||||
this.gameTicks = (int) Reflections.field$ServerPlayerGameMode$gameTicks.get(gameMode);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
CraftEngine.instance().logger().warn("Failed to get game tick for " + name(), e);
|
||||
|
||||
@@ -5297,25 +5297,25 @@ public class Reflections {
|
||||
)
|
||||
);
|
||||
|
||||
// 1.20.5+
|
||||
public static final Method method$ItemStack$transmuteCopy = ReflectionUtils.getMethod(
|
||||
clazz$ItemStack, clazz$ItemStack, clazz$ItemLike, int.class
|
||||
);
|
||||
// // 1.20.5+
|
||||
// public static final Method method$ItemStack$transmuteCopy = ReflectionUtils.getMethod(
|
||||
// clazz$ItemStack, clazz$ItemStack, clazz$ItemLike, int.class
|
||||
// );
|
||||
|
||||
// 1.20.5+
|
||||
public static final Class<?> clazz$DataComponentPatch = ReflectionUtils.getClazz(
|
||||
BukkitReflectionUtils.assembleMCClass("core.component.DataComponentPatch")
|
||||
);
|
||||
|
||||
// 1.20.5+
|
||||
public static final Method method$ItemStack$getComponentsPatch = Optional.ofNullable(clazz$DataComponentPatch)
|
||||
.map(it -> ReflectionUtils.getMethod(clazz$ItemStack, it))
|
||||
.orElse(null);
|
||||
|
||||
// 1.20.5+
|
||||
public static final Method method$ItemStack$applyComponents = Optional.ofNullable(clazz$DataComponentPatch)
|
||||
.map(it -> ReflectionUtils.getMethod(clazz$ItemStack, void.class, it))
|
||||
.orElse(null);
|
||||
// // 1.20.5+
|
||||
// public static final Method method$ItemStack$getComponentsPatch = Optional.ofNullable(clazz$DataComponentPatch)
|
||||
// .map(it -> ReflectionUtils.getMethod(clazz$ItemStack, it))
|
||||
// .orElse(null);
|
||||
//
|
||||
// // 1.20.5+ WRONG!!!
|
||||
// public static final Method method$ItemStack$applyComponents = Optional.ofNullable(clazz$DataComponentPatch)
|
||||
// .map(it -> ReflectionUtils.getMethod(clazz$ItemStack, void.class, it))
|
||||
// .orElse(null);
|
||||
|
||||
public static final Method method$ItemStack$getItem = requireNonNull(
|
||||
ReflectionUtils.getMethod(
|
||||
|
||||
@@ -29,6 +29,9 @@ public class ExactPathMatcher implements PathMatcher {
|
||||
@Override
|
||||
public PathMatcher create(Map<String, Object> arguments) {
|
||||
String path = (String) arguments.get("path");
|
||||
if (path == null) {
|
||||
throw new IllegalArgumentException("The 'path' argument must not be null");
|
||||
}
|
||||
return new ExactPathMatcher(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class FilenameMatcher implements PathMatcher {
|
||||
public PathMatcher create(Map<String, Object> arguments) {
|
||||
String name = (String) arguments.get("name");
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("The name argument must not be null");
|
||||
throw new IllegalArgumentException("The 'name' argument must not be null");
|
||||
}
|
||||
return new FilenameMatcher(name);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
import java.io.EOFException;
|
||||
|
||||
public abstract class AbstractTokenStringReader implements TokenStringReader {
|
||||
protected final char[] chars;
|
||||
protected int index;
|
||||
|
||||
public AbstractTokenStringReader(char[] chars) {
|
||||
this.chars = chars;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.index < this.chars.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int index() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextToken() {
|
||||
if (!hasNext()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
int start = this.index;
|
||||
int end = this.chars.length - 1;
|
||||
while (this.index < this.chars.length && !Character.isWhitespace(this.chars[this.index])) {
|
||||
end++;
|
||||
}
|
||||
String token = new String(this.chars, start, end - start);
|
||||
this.index = end;
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char peek() {
|
||||
return this.chars[this.index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public char peek(int n) {
|
||||
return this.chars[this.index + n];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skip(int n) {
|
||||
if (n < 0) {
|
||||
throw new IllegalArgumentException("n < 0");
|
||||
}
|
||||
if (index() + n >= this.chars.length) {
|
||||
throw new IndexOutOfBoundsException("index(" + index() + ") + (" + n + ") > chars.length(" + this.chars.length + ")");
|
||||
}
|
||||
this.index += n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void skipWhitespace() {
|
||||
while (this.index < this.chars.length && !Character.isWhitespace(this.chars[this.index])) {
|
||||
this.index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
public interface Action<T> {
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public interface Block {
|
||||
|
||||
int size();
|
||||
|
||||
Action<?>[] actions();
|
||||
|
||||
Key id();
|
||||
|
||||
Action<?> byIndex(int index);
|
||||
|
||||
int indexOf(Action<?> action);
|
||||
|
||||
boolean contains(Action<?> action);
|
||||
|
||||
static Block create(Key id, Action<?>... actions) {
|
||||
return new BlockImpl(id, actions);
|
||||
}
|
||||
|
||||
class BlockImpl implements Block {
|
||||
private final Key id;
|
||||
private final Action<?>[] actions;
|
||||
|
||||
public BlockImpl(Key id, Action<?>[] actions) {
|
||||
this.actions = actions;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return actions.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action<?>[] actions() {
|
||||
return this.actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key id() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Action<?> action) {
|
||||
for (Action<?> value : this.actions) {
|
||||
if (value.equals(action)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action<?> byIndex(int index) {
|
||||
return this.actions[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(final Action<?> action) {
|
||||
for (int i = 0; i < this.actions.length; i++) {
|
||||
if (this.actions[i].equals(action)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Task {
|
||||
|
||||
Map<Key, Block> blocks();
|
||||
|
||||
Key id();
|
||||
|
||||
@Nullable
|
||||
Block byId(Key id);
|
||||
|
||||
@Nullable
|
||||
Block byAction(Action<?> action);
|
||||
|
||||
static Task create(Key key, Map<Key, Block> blocks) {
|
||||
return new TaskImpl(key, blocks);
|
||||
}
|
||||
|
||||
class TaskImpl implements Task {
|
||||
private final Key id;
|
||||
private final Map<Key, Block> blocks = new LinkedHashMap<>();
|
||||
|
||||
public TaskImpl(Key id, Map<Key, Block> blocks) {
|
||||
this.blocks.putAll(blocks);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Block byId(Key id) {
|
||||
return this.blocks.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Key, Block> blocks() {
|
||||
return Collections.unmodifiableMap(this.blocks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key id() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Block byAction(Action<?> action) {
|
||||
for (Block block : blocks.values()) {
|
||||
if (block.contains(action)) {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
public interface TaskActionParser {
|
||||
|
||||
<T> Action<T> parse(TokenStringReader reader);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
public class TaskActionParsers {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
public interface TaskContext {
|
||||
|
||||
Task task();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.momirealms.craftengine.core.plugin.script;
|
||||
|
||||
public interface TokenStringReader {
|
||||
|
||||
char peek();
|
||||
|
||||
char peek(int n);
|
||||
|
||||
void skip(int n);
|
||||
|
||||
int index();
|
||||
|
||||
boolean hasNext();
|
||||
|
||||
String nextToken();
|
||||
|
||||
void skipWhitespace();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.craftengine.core.plugin.script.argument;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.script.TokenStringReader;
|
||||
|
||||
public interface ArgumentParser<T> {
|
||||
|
||||
T parse(TokenStringReader reader);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.momirealms.craftengine.core.plugin.script.argument;
|
||||
|
||||
public class ArgumentParsers {
|
||||
public static final ArgumentParser<Integer> INT_PARSER = new IntArgumentParser();
|
||||
public static final ArgumentParser<Long> LONG_PARSER = new LongArgumentParser();
|
||||
public static final ArgumentParser<Double> DOUBLE_PARSER = new DoubleArgumentParser();
|
||||
|
||||
public static ArgumentParser<Integer> intParser() {
|
||||
return INT_PARSER;
|
||||
}
|
||||
|
||||
public static ArgumentParser<Long> longParser() {
|
||||
return LONG_PARSER;
|
||||
}
|
||||
|
||||
public static ArgumentParser<Double> doubleParser() {
|
||||
return DOUBLE_PARSER;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.craftengine.core.plugin.script.argument;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.script.TokenStringReader;
|
||||
|
||||
public class DoubleArgumentParser implements ArgumentParser<Double> {
|
||||
|
||||
@Override
|
||||
public Double parse(TokenStringReader reader) {
|
||||
String token = reader.nextToken();
|
||||
return Double.parseDouble(token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.craftengine.core.plugin.script.argument;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.script.TokenStringReader;
|
||||
|
||||
public class IntArgumentParser implements ArgumentParser<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer parse(TokenStringReader reader) {
|
||||
String token = reader.nextToken();
|
||||
return Integer.parseInt(token);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.craftengine.core.plugin.script.argument;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.script.TokenStringReader;
|
||||
|
||||
public class LongArgumentParser implements ArgumentParser<Long> {
|
||||
|
||||
@Override
|
||||
public Long parse(TokenStringReader reader) {
|
||||
String token = reader.nextToken();
|
||||
return Long.parseLong(token);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.craftengine.core.pack.model.select.SelectPropertyFactory;
|
||||
import net.momirealms.craftengine.core.pack.model.special.SpecialModelFactory;
|
||||
import net.momirealms.craftengine.core.pack.model.tint.TintFactory;
|
||||
import net.momirealms.craftengine.core.plugin.config.template.TemplateArgumentFactory;
|
||||
import net.momirealms.craftengine.core.plugin.script.TaskActionParser;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
@@ -49,6 +50,7 @@ public class BuiltInRegistries {
|
||||
public static final Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Factory> SMITHING_RESULT_PROCESSOR_FACTORY = createRegistry(Registries.SMITHING_RESULT_PROCESSOR_FACTORY);
|
||||
public static final Registry<HitBoxFactory> HITBOX_FACTORY = createRegistry(Registries.HITBOX_FACTORY);
|
||||
public static final Registry<ResourcePackHostFactory> RESOURCE_PACK_HOST_FACTORY = createRegistry(Registries.RESOURCE_PACK_HOST_FACTORY);
|
||||
public static final Registry<TaskActionParser> TASK_ACTION_PARSER = createRegistry(Registries.TASK_ACTION_PARSER);
|
||||
|
||||
private static <T> Registry<T> createRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
return new MappedRegistry<>(key);
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.momirealms.craftengine.core.pack.model.select.SelectPropertyFactory;
|
||||
import net.momirealms.craftengine.core.pack.model.special.SpecialModelFactory;
|
||||
import net.momirealms.craftengine.core.pack.model.tint.TintFactory;
|
||||
import net.momirealms.craftengine.core.plugin.config.template.TemplateArgumentFactory;
|
||||
import net.momirealms.craftengine.core.plugin.script.TaskActionParser;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
@@ -50,4 +51,5 @@ public class Registries {
|
||||
public static final ResourceKey<Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Factory>> SMITHING_RESULT_PROCESSOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_factory"));
|
||||
public static final ResourceKey<Registry<HitBoxFactory>> HITBOX_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("hitbox_factory"));
|
||||
public static final ResourceKey<Registry<ResourcePackHostFactory>> RESOURCE_PACK_HOST_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("resource_pack_host_factory"));
|
||||
public static final ResourceKey<Registry<TaskActionParser>> TASK_ACTION_PARSER = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("task_action_parser"));
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.15
|
||||
nms_helper_version=0.61
|
||||
nms_helper_version=0.61.1
|
||||
reactive_streams_version=1.0.4
|
||||
amazon_awssdk_version=2.31.23
|
||||
amazon_awssdk_eventstream_version=1.0.1
|
||||
|
||||
Reference in New Issue
Block a user