Posted September 2, 20196 yr I've been using an IItemHandler (which, according to the Forge docs, we're supposed to use instead of IInventory) to handle the inventory of one of the processing blocks in my mod. However, I'm not sure how to get recipes with it. The Minecraft RecipeManager requires an IInventory as the second parameter of #getRecipe(), and I couldn't find a Forge RecipeManager nor a different method that would take an IItemHandler and return a recipe. Does anyone know how I can get recipes using my IItemHandler? Just for reference, here's what I'm trying to do: public class GrinderTileEntity extends TileEntity implements ITickableTileEntity, INamedContainerProvider { private LazyOptional<IItemHandler> itemHandler = LazyOptional.of(this::createItemHandler); private LazyOptional<IEnergyStorage> energyHandler = LazyOptional.of(this::createEnergyHandler); private int counter = 0; public GrinderTileEntity() { super(TileEntityTypes.grinder); } @Override public void tick() { if (world.isRemote) return; //Nothing to do if we have no energy AtomicBoolean hasEnergy = new AtomicBoolean(); energyHandler.ifPresent( e -> hasEnergy.set(e.getEnergyStored() > 0) ); if (!hasEnergy.get()) return; //Nothing to do if there isn't an item. AtomicReference<ItemStack> stack = new AtomicReference<>(); itemHandler.ifPresent( h -> stack.set(h.getStackInSlot(0).copy()) ); if(stack.get().isEmpty()) return; AtomicReference<IItemHandler> inventory = new AtomicReference<>(); itemHandler.ifPresent(inventory::set); //#getRecipe() is where it breaks, specifically inventory.get() IRecipe<?> recipe = world.getRecipeManager() .getRecipe(RecipeTypes.GRINDING, inventory.get(), world) .orElse(null); //processing... } /* ************************************************ * Used to create the IItemHandler for itemHandler ***************************************************/ private IItemHandler createItemHandler() { return new ItemStackHandler(2) { @Override public boolean isItemValid(int slot, @Nonnull ItemStack stack) { return ItemTags.getCollection() .get(ResourceLocation.tryCreate("forge:ores")) .contains(stack.getItem()) && slot == 0; } @Nonnull @Override public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { if (slot != 0 || !ItemTags.getCollection() .get(ResourceLocation.tryCreate("forge:ores")) .contains(stack.getItem()) ) { return stack; } return super.insertItem(slot, stack, simulate); } @Override protected void onContentsChanged(int slot) { markDirty(); } }; } //other functions... } Thanks!
September 2, 20196 yr 9 minutes ago, TheMikeste1 said: Does anyone know how I can get recipes using my IItemHandler? Create a RecipeWrapper it takes in a IItemHandlerModifiable and it's an IInventory. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
September 2, 20196 yr Author Just now, Animefan8888 said: Create a RecipeWrapper it takes in a IItemHandlerModifiable and it's an IInventory. Oh, awesome. I didn't notice that class. Thanks!
September 2, 20196 yr @TheMikeste1 ]https://github.com/MinecraftForge/MinecraftForge/blob/1.14.x/src/main/java/net/minecraftforge/items/wrapper/RecipeWrapper.java
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.