Беды с рецептом(Или у меня с головой)

Версия Minecraft
1.16.5
API
Forge
84
5
6
Всем привет

Недавно сделал интеграцию JEI
И свой функциональный блок

рецепт один
и он не работает....
2022-09-14_20.14.23.png

Однако в JEI он есть

2022-09-14_20.14.30.png

С такой проблемой никогда не сталкивался

помогите чем сможете)


Древорез...мда..мне тоже как то такое название не нравится, но моей фантазии только на это и хватает(не стесняйтесь предлагать свои варианты)
 
1,369
112
241
Всем привет

Недавно сделал интеграцию JEI
И свой функциональный блок

рецепт один
и он не работает....
Посмотреть вложение 15171

Однако в JEI он есть

Посмотреть вложение 15172

С такой проблемой никогда не сталкивался

помогите чем сможете)


Древорез...мда..мне тоже как то такое название не нравится, но моей фантазии только на это и хватает(не стесняйтесь предлагать свои варианты)
Ты неправильно парсишь свой рецепт. Покажи код крафтилки.
 
84
5
6
{ "type": "ue:woodcutting", "ingredient": { "item": "minecraft:oak_log" }, "result": "ue:oak_log_slab", "count": 2 }



Java:
    @Override
    public boolean matches(IInventory inventory, World world)
    {
        return this.ingredient.test(inventory.getStackInSlot(0));
    }

    @Override
    public ItemStack getIcon()
    {
        return new ItemStack(UEBlocks.LUMBERJACK_TABLE.get());
    }

    public static class Serializer<T extends WoodcuttingRecipe> extends net.minecraftforge.registries.ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<T>
    {
        private final WoodcuttingRecipe.Serializer.IRecipeFactory<T> factory;

        public Serializer(WoodcuttingRecipe.Serializer.IRecipeFactory<T> factory)
        {
            this.factory = factory;
        }

        @Override
        public T read(ResourceLocation recipeId, JsonObject json)
        {
            String group = JSONUtils.getString(json, "group", "");
            Ingredient ingredient;
            if(JSONUtils.isJsonArray(json, "ingredient"))
            {
                ingredient = Ingredient.deserialize(JSONUtils.getJsonArray(json, "ingredient"));
            }
            else
            {
                ingredient = Ingredient.deserialize(JSONUtils.getJsonObject(json, "ingredient"));
            }
            String result = JSONUtils.getString(json, "result");
            int count = JSONUtils.getInt(json, "count");
            ItemStack stack = new ItemStack(Registry.ITEM.getOrDefault(new ResourceLocation(result)), count);
            return this.factory.create(recipeId, group, ingredient, stack);
        }

        @Override
        public T read(ResourceLocation recipeId, PacketBuffer buffer)
        {
            String group = buffer.readString(32767);
            Ingredient ingredient = Ingredient.read(buffer);
            ItemStack stack = buffer.readItemStack();
            return this.factory.create(recipeId, group, ingredient, stack);
        }

        @Override
        public void write(PacketBuffer buffer, T recipe)
        {
            buffer.writeString(recipe.group);
            recipe.ingredient.write(buffer);
            buffer.writeItemStack(recipe.result);
        }

        public interface IRecipeFactory<T extends WoodcuttingRecipe>
        {
            T create(ResourceLocation id, String group, Ingredient ingredient, ItemStack stack);
        }
    }
}
 
1,369
112
241
Я просил саму крафтилку, а не рецепт :\ Мне нужен код того, как ты в гуишке/тайле/где ещё преобразуешь эти рецепты в input и output.

Кстати, касательно рецепта:
1) Неясно, зачем нужен group, он, кстати, в json не указан;
2) Предмет result лучше делать через ItemStack, а не через String и ForgeRegistry (мб в этом проблема, но я в этом сомневаюсь, по первому времени также делал, всё работало);
3) У тебя Ingredient априори один, не надо считывать его как array.
 
84
5
6
1), 2), 3) код с камнереза(я его потом подредактирую)


Container(тоже все с камнереза)

Java:
 private final IWorldPosCallable worldPosCallable;
    private final IntReferenceHolder selectedRecipe = IntReferenceHolder.single();
    private final World world;
    private List<WoodcuttingRecipe> recipes = Lists.newArrayList();
    private ItemStack itemStackInput = ItemStack.EMPTY;

    private long lastOnTake;
    final Slot inputInventorySlot;
    final Slot outputInventorySlot;
    private Runnable inventoryUpdateListener = () -> {
    };
    public final IInventory inputInventory = new Inventory(1) {
        @Override
        public void markDirty() {
            super.markDirty();
            WoodcutterContainer.this.onCraftMatrixChanged(this);
            WoodcutterContainer.this.inventoryUpdateListener.run();
        }
    };
    private final CraftResultInventory inventory = new CraftResultInventory();

    public WoodcutterContainer(int windowIdIn, PlayerInventory playerInventoryIn) {
        this(windowIdIn, playerInventoryIn, IWorldPosCallable.DUMMY);
    }

    public WoodcutterContainer(int windowIdIn, PlayerInventory playerInventoryIn, final IWorldPosCallable worldPosCallableIn) {
        super(UEContainers.WOODCUTTER.get(), windowIdIn);
        this.worldPosCallable = worldPosCallableIn;
        this.world = playerInventoryIn.player.world;
        this.inputInventorySlot = this.addSlot(new Slot(this.inputInventory, 0, 20, 33));
        this.outputInventorySlot = this.addSlot(new Slot(this.inventory, 1, 143, 33) {

            @Override
            public boolean isItemValid(ItemStack stack) {
                return false;
            }
            @Override
            public ItemStack onTake(PlayerEntity thePlayer, ItemStack stack) {
                stack.onCrafting(thePlayer.world, thePlayer, stack.getCount());
                WoodcutterContainer.this.inventory.onCrafting(thePlayer);
                ItemStack itemstack = WoodcutterContainer.this.inputInventorySlot.decrStackSize(1);
                if (!itemstack.isEmpty()) {
                    WoodcutterContainer.this.updateRecipeResultSlot();
                }

                worldPosCallableIn.consume((p_216954_1_, p_216954_2_) -> {
                    long l = p_216954_1_.getGameTime();
                    if (WoodcutterContainer.this.lastOnTake != l) {
                        p_216954_1_.playSound((PlayerEntity)null, p_216954_2_, SoundEvents.UI_STONECUTTER_TAKE_RESULT, SoundCategory.BLOCKS, 1.0F, 1.0F);
                        WoodcutterContainer.this.lastOnTake = l;
                    }

                });
                return super.onTake(thePlayer, stack);
            }
        });

        for(int i = 0; i < 3; ++i) {
            for(int j = 0; j < 9; ++j) {
                this.addSlot(new Slot(playerInventoryIn, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
            }
        }

        for(int k = 0; k < 9; ++k) {
            this.addSlot(new Slot(playerInventoryIn, k, 8 + k * 18, 142));
        }

        this.trackInt(this.selectedRecipe);
    }

    @OnlyIn(Dist.CLIENT)
    public int getSelectedRecipe() {
        return this.selectedRecipe.get();
    }

    @OnlyIn(Dist.CLIENT)
    public List<WoodcuttingRecipe> getRecipeList() {
        return this.recipes;
    }

    @OnlyIn(Dist.CLIENT)
    public int getRecipeListSize() {
        return this.recipes.size();
    }

    @OnlyIn(Dist.CLIENT)
    public boolean hasItemsinInputSlot() {
        return this.inputInventorySlot.getHasStack() && !this.recipes.isEmpty();
    }

    @Override
    public boolean canInteractWith(PlayerEntity playerIn) {
        return isWithinUsableDistance(this.worldPosCallable, playerIn, UEBlocks.LUMBERJACK_TABLE.get());
    }

    @Override
    public boolean enchantItem(PlayerEntity playerIn, int id) {
        if (this.func_241818_d_(id)) {
            this.selectedRecipe.set(id);
            this.updateRecipeResultSlot();
        }

        return true;
    }

    private boolean func_241818_d_(int p_241818_1_) {
        return p_241818_1_ >= 0 && p_241818_1_ < this.recipes.size();
    }


    public void onCraftMatrixChanged(IInventory inventoryIn) {
        ItemStack itemstack = this.inputInventorySlot.getStack();
        if (itemstack.getItem() != this.itemStackInput.getItem()) {
            this.itemStackInput = itemstack.copy();
            this.updateAvailableRecipes(inventoryIn, itemstack);
        }

    }
    private void updateAvailableRecipes(IInventory inventoryIn, ItemStack stack) {
        this.recipes.clear();
        this.selectedRecipe.set(-1);
        this.outputInventorySlot.putStack(ItemStack.EMPTY);
        if (!stack.isEmpty()) {
            this.recipes = this.world.getRecipeManager().getRecipes(UERecipeType.WOODCUTTING, inventoryIn, this.world);
        }

    }
    private void updateRecipeResultSlot() {
        if (!this.recipes.isEmpty() && this.func_241818_d_(this.selectedRecipe.get())) {
            WoodcuttingRecipe woodcuttingRecipe = this.recipes.get(this.selectedRecipe.get());
            this.inventory.setRecipeUsed(woodcuttingRecipe);
            this.outputInventorySlot.putStack(woodcuttingRecipe.getCraftingResult(this.inputInventory));
        } else {
            this.outputInventorySlot.putStack(ItemStack.EMPTY);
        }

        this.detectAndSendChanges();
    }
    @Override
    public ContainerType<?> getType() {
        return UEContainers.WOODCUTTER.get();
    }

    @OnlyIn(Dist.CLIENT)
    public void setInventoryUpdateListener(Runnable listenerIn) {
        this.inventoryUpdateListener = listenerIn;
    }


    public boolean canMergeSlot(ItemStack stack, Slot slotIn) {
        return slotIn.inventory != this.inventory && super.canMergeSlot(stack, slotIn);
    }
    @Override
    public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
        ItemStack itemstack = ItemStack.EMPTY;
        Slot slot = this.inventorySlots.get(index);
        if (slot != null && slot.getHasStack()) {
            ItemStack itemstack1 = slot.getStack();
            Item item = itemstack1.getItem();
            itemstack = itemstack1.copy();
            if (index == 1) {
                item.onCreated(itemstack1, playerIn.world, playerIn);
                if (!this.mergeItemStack(itemstack1, 2, 38, true)) {
                    return ItemStack.EMPTY;
                }

                slot.onSlotChange(itemstack1, itemstack);
            } else if (index == 0) {
                if (!this.mergeItemStack(itemstack1, 2, 38, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (this.world.getRecipeManager().getRecipe(UERecipeType.WOODCUTTING, new Inventory(itemstack1), this.world).isPresent()) {
                if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (index < 29) {
                if (!this.mergeItemStack(itemstack1, 29, 38, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (index < 38 && !this.mergeItemStack(itemstack1, 2, 29, false)) {
                return ItemStack.EMPTY;
            }

            if (itemstack1.isEmpty()) {
                slot.putStack(ItemStack.EMPTY);
            }

            slot.onSlotChanged();
            if (itemstack1.getCount() == itemstack.getCount()) {
                return ItemStack.EMPTY;
            }

            slot.onTake(playerIn, itemstack1);
            this.detectAndSendChanges();
        }

        return itemstack;
    }

    @Override
    public void onContainerClosed(PlayerEntity playerIn) {
        super.onContainerClosed(playerIn);
        this.inventory.removeStackFromSlot(1);
        this.worldPosCallable.consume((p_217079_2_, p_217079_3_) -> this.clearContainer(playerIn, playerIn.world, this.inputInventory));
    }



}
 
84
5
6
Я просил саму крафтилку, а не рецепт :\ Мне нужен код того, как ты в гуишке/тайле/где ещё преобразуешь эти рецепты в input и output.

Кстати, касательно рецепта:
1) Неясно, зачем нужен group, он, кстати, в json не указан;
2) Предмет result лучше делать через ItemStack, а не через String и ForgeRegistry (мб в этом проблема, но я в этом сомневаюсь, по первому времени также делал, всё работало);
3) У тебя Ingredient априори один, не надо считывать его как array.
не помогло, но все равно спасибо
 
Сверху