Jump to content

[1.9] Custom Shapeless Recipe based on Item amount


AntariaN

Recommended Posts

I'm trying to create a Custom Shapless Recipe that implements IRecipe. It should allow registering recipes, that just requires some amount of one Item. Everything works fine, except two things. I've tried to solve it by myself for about 4 hours, but didn't figured out.

 

The problems I have:

1. getRemaningItems method works incorrectly (eg., when It's 5 sticks in input, after crafting there is a stick with 0 amount).

2. If you putting Items into workbanch one by one (RightClick) all in the same Slot the recipe doesn't work.

 

Custom Recipe Class:

package com.antarian.testmod.recipe;

import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;

public class ShapelessMultipleItemRecipe implements IRecipe {

private final ItemStack recipeOutput;
private final Item recipeItem;
private final int recipeAmount;

public ShapelessMultipleItemRecipe(ItemStack recipeOutput, Item recipeItem, int recipeAmount) {
	this.recipeOutput = recipeOutput;
	this.recipeItem = recipeItem;
	this.recipeAmount = recipeAmount;
}

public ItemStack getRecipeOutput() {
	return recipeOutput;
}

public ItemStack[] getRemainingItems(InventoryCrafting inv) {
	ItemStack[] itemStackArray = new ItemStack[inv.getSizeInventory()];
	int itemsToGet = recipeAmount;

	for(int i = 0; i < itemStackArray.length; i++) {
		ItemStack itemStack = inv.getStackInSlot(i);

		if(itemStack != null && itemsToGet > 0) {
			int getItems = itemStack.stackSize >= itemsToGet ? itemsToGet : itemStack.stackSize;
			itemStack.stackSize -= getItems;
			itemStackArray[i] = itemStack.stackSize > 0 ? itemStack : null;
			//itemStack.stackSize -= getItems - 1;
			//itemStackArray[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(itemStack);
			itemsToGet -= getItems;
		}
	}

	return itemStackArray;
}

public boolean matches(InventoryCrafting inv, World worldIn) {
	Item item = this.recipeItem;
	int itemCount = 0;

	for(int i = 0; i < inv.getHeight(); i++) {
		for(int j = 0; j < inv.getWidth(); j++) {
			ItemStack currItemStack = inv.getStackInRowAndColumn(j, i);

			if(currItemStack != null) {
				if(currItemStack.getItem() == item) {
					itemCount += currItemStack.stackSize;
				}
			}
		}
	}

	if(itemCount >= recipeAmount) {
		return true;
	}

	return false;
}

public ItemStack getCraftingResult(InventoryCrafting inv) {
	return recipeOutput.copy();
}

public int getRecipeSize() {
	return 1;
}
}

 

Some parts of ModRecipes Class:

RecipeSorter.register("testmod:shapelessmultipleitem", ShapelessMultipleItemRecipe.class, SHAPELESS, "after:minecraft:shapless");

GameRegistry.addRecipe(new ShapelessMultipleItemRecipe(new ItemStack(ModBlocks.blockBonfire), Items.stick, 4));

Link to comment
Share on other sites

If you're using a custom crafting bench, absolutely.

 

I've got a "Sifter" machine that takes inputs of size 8 and produces an output of size 1 (turns Tiny Dust into Dust).  Ditto for a "compactor" (turns Snowballs into Snow, etc)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

If you're using a custom crafting bench, absolutely.

 

I've got a "Sifter" machine that takes inputs of size 8 and produces an output of size 1 (turns Tiny Dust into Dust).  Ditto for a "compactor" (turns Snowballs into Snow, etc)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.