9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 04:19:27 +00:00

修复bug

This commit is contained in:
XiaoMoMi
2025-07-11 04:19:55 +08:00
parent 18c67d34e0
commit f4906abe0d
6 changed files with 28 additions and 17 deletions

View File

@@ -298,7 +298,11 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
@Override
public ItemStack buildItemStack(Key id, @Nullable Player player) {
return Optional.ofNullable(buildCustomItemStack(id, player)).orElseGet(() -> createVanillaItemStack(id));
ItemStack customItem = buildCustomItemStack(id, player);
if (customItem != null) {
return customItem;
}
return createVanillaItemStack(id);
}
@Override
@@ -306,26 +310,31 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
return Optional.ofNullable(customItems.get(id)).map(it -> it.buildItem(player)).orElse(null);
}
@Override
public Item<ItemStack> createWrappedItem(Key id, @Nullable Player player) {
CustomItem<ItemStack> customItem = this.customItems.get(id);
if (customItem != null) {
return customItem.buildItem(player);
}
ItemStack itemStack = this.createVanillaItemStack(id);
if (itemStack != null) {
return wrap(itemStack);
}
return null;
}
private ItemStack createVanillaItemStack(Key id) {
NamespacedKey key = NamespacedKey.fromString(id.toString());
if (key == null) {
return this.emptyStack;
return null;
}
Object item = FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.ITEM, KeyUtils.toResourceLocation(id));
if (item == null) {
return this.emptyStack;
return null;
}
return FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(FastNMS.INSTANCE.constructor$ItemStack(item, 1));
}
@Override
public Item<ItemStack> createWrappedItem(Key id, @Nullable Player player) {
return Optional.ofNullable(this.customItems.get(id)).map(it -> it.buildItem(player)).orElseGet(() -> {
ItemStack itemStack = createVanillaItemStack(id);
return wrap(itemStack);
});
}
@Override
public @NotNull Item<ItemStack> wrap(ItemStack itemStack) {
if (itemStack == null) return this.empty;

View File

@@ -10,7 +10,6 @@ import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.reflection.bukkit.CraftBukkitReflections;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MItems;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistries;
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
import net.momirealms.craftengine.bukkit.util.KeyUtils;