9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 09:59:20 +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;

View File

@@ -43,8 +43,10 @@ public interface ItemManager<T> extends Manageable, ModelGenerator {
@Nullable
T buildItemStack(Key id, @Nullable Player player);
@Nullable
Item<T> createCustomWrappedItem(Key id, @Nullable Player player);
@Nullable
Item<T> createWrappedItem(Key id, @Nullable Player player);
@NotNull

View File

@@ -173,6 +173,8 @@ public abstract class AbstractRecipeManager<T> implements RecipeManager<T> {
markAsCustomRecipe(id);
registerInternalRecipe(id, recipe);
registerPlatformRecipe(id, recipe);
} catch (LocalizedResourceConfigException e) {
throw e;
} catch (Exception e) {
CraftEngine.instance().logger().warn("Failed to register custom recipe " + id, e);
}

View File

@@ -157,7 +157,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
List<ItemWithAction> iconList = this.categoryOnMainPage.stream().map(it -> {
Item<?> item = this.plugin.itemManager().createWrappedItem(it.icon(), player);
if (item == null) {
if (ItemUtils.isEmpty(item)) {
this.plugin.logger().warn("Can't not find item " + it.icon() + " for category icon");
return null;
}
@@ -242,7 +242,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
Category subCategory = this.byId.get(Key.of(subCategoryId));
if (subCategory == null) return null;
Item<?> item = this.plugin.itemManager().createWrappedItem(subCategory.icon(), player);
if (item == null) {
if (ItemUtils.isEmpty(item)) {
if (!subCategory.icon().equals(ItemKeys.AIR)) {
item = this.plugin.itemManager().createWrappedItem(ItemKeys.BARRIER, player);
item.customNameJson(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(subCategory.displayName(), ItemBuildContext.EMPTY.tagResolvers())));
@@ -261,7 +261,7 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
Key itemId = Key.of(it);
Item<?> item = this.plugin.itemManager().createWrappedItem(itemId, player);
boolean canGoFurther;
if (item == null) {
if (ItemUtils.isEmpty(item)) {
if (!itemId.equals(ItemKeys.AIR)) {
item = this.plugin.itemManager().createWrappedItem(ItemKeys.BARRIER, player);
item.customNameJson(AdventureHelper.componentToJson(Component.text(it).decoration(TextDecoration.ITALIC, TextDecoration.State.FALSE).color(NamedTextColor.RED)));
@@ -499,7 +499,6 @@ public class ItemBrowserManagerImpl implements ItemBrowserManager {
}
}));
List<Item<?>> templates = new ArrayList<>();
Optional.ofNullable(recipe.template()).ifPresent(it -> {
for (UniqueKey in : it.items()) {

View File

@@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.59.7
config_version=41
lang_version=21
lang_version=22
project_group=net.momirealms
latest_supported_version=1.21.7