mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-27 19:09:08 +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(
|
||||
|
||||
Reference in New Issue
Block a user