You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

1.20版本自定义方块实体配方失效,无法合成问题求助

Minecraft科技模组矿石加工机器配方失效问题

我正在开发一款科技机械类Minecraft模组,做了个类似熔炉的矿石加工机器,但配方完全不工作——把矿石放进插槽后毫无反应。

我已经把inventory加入监视列表,能检测到插槽里的方块,但就是触发不了合成。目前发现getCurrentRecipe()返回Optional.empty,明明inventory里有对应物品。试过修改属性排查作用域问题,没用。而且程序既不崩溃也不报错,就是完全没响应。

相关代码片段

1. 配方JSON文件

{
  "type": "darkcollective:ore_refining",
  "ingredients": [
    {
      "item": "darkcollective:aernium_ore"
    }
  ],
  "output": {
    "count": 2,
    "item": "darkcollective:aernium_ingot"
  }
}

2. OreRefineryEntityClass中配方检测与合成启动代码

private boolean hasRecipe() {
        Optional<OreRefineryRecipe> recipe = getCurrentRecipe();

        System.out.println(recipe);

        if(recipe.isEmpty()) {
            return false;
        }
        ItemStack result = recipe.get().getResultItem(getLevel().registryAccess());

        return canInsertAmountIntoOutputSlot(result.getCount()) && canInsertItemIntoOutputSlot(result.getItem());
    }

    private Optional<OreRefineryRecipe> getCurrentRecipe() {
        SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots());
        for(int i = 0; i < itemHandler.getSlots(); i++) {
            inventory.setItem(i, this.itemHandler.getStackInSlot(i));
        }

        return this.level.getRecipeManager().getRecipeFor(OreRefineryRecipe.Type.INSTANCE, inventory, level);
    }

3. RecipeSerializer代码

public static class Serializer implements RecipeSerializer<OreRefineryRecipe>{

        public static final Serializer INSTANCE = new Serializer();
        public static final ResourceLocation ID = new ResourceLocation(DarkCollective.ModID, "ore_refining");

        @Override
        public OreRefineryRecipe fromJson(ResourceLocation recipeId, JsonObject serializedRecipe) {
            ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(serializedRecipe, "result"));

            JsonArray ingredients = GsonHelper.getAsJsonArray(serializedRecipe, "ingredients");
            NonNullList<Ingredient> inputs = NonNullList.withSize(1, Ingredient.EMPTY);

            for(int i = 0; i < inputs.size(); i++) {
                inputs.set(i, Ingredient.fromJson(ingredients.get(i)));
            }

            return new OreRefineryRecipe(inputs, output, recipeId);
        }

        @Override
        public @Nullable OreRefineryRecipe fromNetwork(ResourceLocation recipeID, FriendlyByteBuf buffer) {
            NonNullList<Ingredient> inputs = NonNullList.withSize(buffer.readInt(), Ingredient.EMPTY);

            for(int i = 0; i < inputs.size(); i++) {
                inputs.set(i, Ingredient.fromNetwork(buffer));
            }

            ItemStack output = buffer.readItem();
            return new OreRefineryRecipe(inputs, output, recipeID);
        }

        @Override
        public void toNetwork(FriendlyByteBuf buffer, OreRefineryRecipe recipe) {
            buffer.writeInt(recipe.inputItems.size());

            for (Ingredient ingredient : recipe.getIngredients()) {
                ingredient.toNetwork(buffer);
            }

            buffer.writeItemStack(recipe.getResultItem(null), false);

        }
    }

我是模组开发新手,代码跟着教程写的,对规范不太熟。如果有遗漏信息,我可以补充。


内容的提问来源于stack exchange,提问作者BlueFFlame

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 09:43:18