Jump to content

Creating a crafting handler the exports multiple items


gmod622

Recommended Posts

So something like this?

 

    @Nullable
    public ItemStack getMultiResult(ItemStack stack)
    {
        for (Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet())
        {
            if (this.compareItemStacks(stack, entry.getKey()))
            {
            	multismeltList.get(stack);
                return stack;
            }
        }

        return null;
    }

 

or this?

 

    @Nullable
    public List<OutputWrapper> getMultiResult(ItemStack stack)
    {
        for (Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet())
        {
            if (this.compareItemStacks(stack, entry.getKey()))
            {
                List<OutputWrapper> list = new ArrayList<OutputWrapper>();
                return list;
            }
        }

        return null;
    }

 

or neither?

Not new to java >> New to modding.

Link to comment
Share on other sites

public List<OutputWrapper> getMultiResult(ItemStack stack) {

    return multismeltList.get(stack);

}

 

You don't need to iterate over the entry set.

 

The whole point of creating the wrapper was so you could do this:

 

smeltmulti.get(stack);

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

Okay,

 

So now the Tile is wanting a list, which I gave, however I'm getting a bunch of errors because its a list, instead of an itemstack.

 

Edit:

 

Here is the function that needs some tweaking:

 

private boolean smeltItem(boolean performSmelt)
{
	Integer firstSuitableInputSlot = null;
	Integer firstSuitableOutputSlot = null;
	List<OutputWrapper> result = null;
	for (int inputSlot = FIRST_INPUT_SLOT; inputSlot < FIRST_INPUT_SLOT + INPUT_SLOTS_COUNT; inputSlot++)	{
		if (itemStacks[inputSlot] != null) {
			result = getSmeltingResultForItem(itemStacks[inputSlot]);
  			if (result != null) {
				// find the first suitable output slot- either empty, or with identical item that has enough space
				for (int outputSlot = FIRST_OUTPUT_SLOT; outputSlot < FIRST_OUTPUT_SLOT + OUTPUT_SLOTS_COUNT; outputSlot++) {
					ItemStack outputStack = itemStacks[outputSlot];
					if (outputStack == null) {
						firstSuitableInputSlot = inputSlot;
						firstSuitableOutputSlot = outputSlot;
						break;
					}

					if (outputStack.getItem() == result.getItem() && (!outputStack.getHasSubtypes() || outputStack.getMetadata() == outputStack.getMetadata())
									&& ItemStack.areItemStackTagsEqual(outputStack, result)) {
						int combinedSize = itemStacks[outputSlot].stackSize + result.stackSize;
						if (combinedSize <= getInventoryStackLimit() && combinedSize <= itemStacks[outputSlot].getMaxStackSize()) {
							firstSuitableInputSlot = inputSlot;
							firstSuitableOutputSlot = outputSlot;
							break;
						}
					}
				}
				if (firstSuitableInputSlot != null) break;
			}
		}
	}

	if (firstSuitableInputSlot == null) return false;
	if (!performSmelt) return true;

	// alter input and output
	itemStacks[firstSuitableInputSlot].stackSize--;
	if (itemStacks[firstSuitableInputSlot].stackSize <=0) itemStacks[firstSuitableInputSlot] = null;
	if (itemStacks[firstSuitableOutputSlot] == null) {
		itemStacks[firstSuitableOutputSlot] = result.copy(); // Use deep .copy() to avoid altering the recipe
	} else {
		itemStacks[firstSuitableOutputSlot].stackSize += result.stackSize;
	}
	markDirty();
	return true;
}

Not new to java >> New to modding.

Link to comment
Share on other sites

Sorry, that's too dense for me to figure out what your intentions are.

I assumed you had a 1-input, multi-output furnace.  It looks like you actually have multi-(1-input:1-output) furnace.

 

The idea I had in my head was that you had one input, you would get its list of outputs, and iterate over that list, checking to see if the probabilistic result item was outputted or not.

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

Then what is this loop for?

for (int inputSlot = FIRST_INPUT_SLOT; inputSlot < FIRST_INPUT_SLOT + INPUT_SLOTS_COUNT; inputSlot++) {...}

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

Okay, So I'm having a problem with applying the multiple output slots, the item smelts, but doesn't give an output nor get used.

I KNOW there is something with it, but I cant figure it out:

 

private boolean canSmelt() {return smeltItem(false);}

/**
 * Smelt an input item into an output slot, if possible
 */
private void smeltItem() {smeltItem(true);}

/**
 * checks that there is an item to be smelted in one of the input slots and that there is room for the result in the output slots
 * If desired, performs the smelt
 * @param performSmelt if true, perform the smelt.  if false, check whether smelting is possible, but don't change the inventory
 * @return false if no items can be smelted, true otherwise
 */
private boolean smeltItem(boolean performSmelt)
{
	Integer firstSuitableInputSlot = null;
	Integer firstSuitableOutputSlot = null;
	ItemStack result = null;

		if (itemStacks[0] != null) {
			result = getSmeltingResultForItem(itemStacks[0]);
  			if (result != null) {
				for (int outputSlot = FIRST_OUTPUT_SLOT; outputSlot < FIRST_OUTPUT_SLOT + OUTPUT_SLOTS_COUNT; outputSlot++) {
					ItemStack outputStack = itemStacks[outputSlot];
					if (outputStack == null) {
						firstSuitableOutputSlot = outputSlot;
						break;
					}
					if (outputStack.getItem() == result.getItem() && (!outputStack.getHasSubtypes() || outputStack.getMetadata() == outputStack.getMetadata()) && ItemStack.areItemStackTagsEqual(outputStack, result)) {
						int combinedSize = itemStacks[outputSlot].stackSize + result.stackSize;
						if (combinedSize <= getInventoryStackLimit() && combinedSize <= itemStacks[outputSlot].getMaxStackSize()) {
							firstSuitableOutputSlot = outputSlot;
							break;
						}
					}
				}
			}
		}

	return true;
}

// returns the smelting result for the given stack. Returns null if the given stack can not be smelted
public static ItemStack getSmeltingResultForItem(ItemStack stack) { return FurnaceRecipes.instance().getSmeltingResult(stack); }

// re

 

EDIT:

 

Just trying to get the regular furnace recipes working

 

Not new to java >> New to modding.

Link to comment
Share on other sites

You need to refactor things so that your "firstvalidoutputslot" variable isn't based on checking "is it this one? is it this one? is it this one?" You need to write a function to do that, rather than encapsulating it inside the smelt method.

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.

Announcements



×
×
  • Create New...

Important Information

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