#[1.21] Creating a custom Recipe Type

14 messages · Page 1 of 1 (latest)

raven kayak
#

I'm tryna make a custom recipe type but I can't even get past the first step.

So I've got a file layed out like this:

public class CustomRecipe implements Recipe<SimpleInventory>{
    //(inherited methods and stuff)
}

but I'm getting the error Bound mismatch: The type SimpleInventory is not a valid substitute for the bounded parameter <T extends RecipeInput> of the type Recipe<T> on line 11 (over Recipe<SimpleInventory>).

I see that SimpleInventory won't go in Recipe<T> and I see that it is supposed to be a RecipeInput but how would I get that to link to an Inventory.

To be honest, a link to an updated tutorial would be the best but the most recent I can find is for 1.20.2, right before they changed a lot with recipes.

#

I've tried different inventories, even a custom ImplementedInventory from a file like this:

public interface ImplementedInventory extends Inventory {

    DefaultedList<ItemStack> getItems();
    
    static ImplementedInventory of(DefaultedList<ItemStack> items) {
        return () -> items;
    }

    static ImplementedInventory ofSize(int size) {
        return of(DefaultedList.ofSize(size, ItemStack.EMPTY));
    }

    @Override
    default int size() {
        return getItems().size();
    }

    @Override
    default boolean isEmpty() {
        for (int i = 0; i < size(); i++) {
            ItemStack stack = getStack(i);
            if (!stack.isEmpty()) {
                return false;
            }
        }
        return true;
    }

    @Override
    default ItemStack getStack(int slot) {
        return getItems().get(slot);
    }

    @Override
    default ItemStack removeStack(int slot, int count) {
        ItemStack result = Inventories.splitStack(getItems(), slot, count);
        if (!result.isEmpty()) {
            markDirty();
        }
        return result;
    }

    @Override
    default ItemStack removeStack(int slot) {
        return Inventories.removeStack(getItems(), slot);
    }

    @Override
    default void setStack(int slot, ItemStack stack) {
        getItems().set(slot, stack);
        if (stack.getCount() > stack.getMaxCount()) {
            stack.setCount(stack.getMaxCount());
        }
    }

    @Override
    default void clear() {
        getItems().clear();
    }

    @Override
    default void markDirty() {
        // Override if you want behavior.
    }

    @Override
    default boolean canPlayerUse(PlayerEntity player) {
        return true;
    }
}

But it still doesn't work because (I'm assuming) it's not a RecipeInput

crimson dawn
#

RecipeInput is an interface, implement it for your inventory

raven kayak
#

Is this what you mean:

public interface ImplementedInventory extends Inventory, RecipeInput{
  //...
}

Because I'm now getting an error on line 6 saying The target type of this expression must be a functional interface and I don't know how to fix as when I search it up all the results are just some old Eclipse bug

crimson dawn
#

send full file, with error spot

raven kayak
# crimson dawn send full file, with error spot

here's my github
It's a bit messy atm but ImplementedInventory.java is (obviously) the one above and SlicerRecipe.java is my recipe file. I haven't rewritten all the SlicerRecipe method's yet because I want to focus on one thing at a time and I'm pretty sure doing it won't change the error in ImplementedInventory

I've put a comment on the error on line 27 of ImplementedInventory

grim moat
#

was any fix found for this?

crimson dawn
#

look at how vanilla does it. I don't know if @raven kayak found a fix, but most of the information i sourced was from the crafting table block

crimson dawn
raven kayak
# grim moat was any fix found for this?

For the most recent error I said about, just return items instead of return () -> items.
But I also haven't fully understood codecs yet so I basically just copied from SmithingTrimRecipe.class
But I still haven't managed to create a custom recipe type yet 💀

fierce quiver
#

Has anybody found the solution?, I was about to make a thread but I found this one instead

crimson dawn
fierce quiver
#

I don't really know how to do that, but at least I have a way

#

thanks!