Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have this custom recipe handler for my custom machine and i cant figure out how to convert it to have two outputs.

 

Here is the file:

 

 

package com.professorvennie.api.recipes;

import net.minecraft.item.ItemStack;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;

/**
* Created by ProfessorVennie on 8/16/2014 at 2:55 PM.
*/
public class ExtractorRecipes {

    private static final ExtractorRecipes SMELTING_BASE = new ExtractorRecipes();
    private Map extractorList = new HashMap();
    private Map expList = new HashMap();
    private Random random = new Random();

    public static ExtractorRecipes extractoring(){
        return SMELTING_BASE;
    }

    public ExtractorRecipes(){

    }

    public void addRecipe(ItemStack itemStack1, ItemStack itemstack2 , float exp){
        this.addLists(itemStack1, itemstack2, exp);
    }

    public void addLists(ItemStack itemStack1, ItemStack itemstack2, float exp){
        this.putLists(itemStack1, itemstack2, exp);
    }

    public void putLists(ItemStack itemstack, ItemStack itemstack2, float exp){
        this.extractorList.put(itemstack, itemstack2);
        this.expList.put(itemstack2, Float.valueOf(exp));
    }

    public ItemStack getExtractoringResult(ItemStack itemstack){
        Iterator iterator = this.extractorList.entrySet().iterator();

        Map.Entry entry;

        do{
            if(!iterator.hasNext()){;
                return null;
            }
            entry = (Map.Entry) iterator.next();
        }
        while(!canBeExtracted(itemstack, (ItemStack)entry.getKey()));
        return (ItemStack) entry.getValue();
    }

    private boolean canBeExtracted(ItemStack itemstack, ItemStack itemstack2) {
        return itemstack2.getItem() == itemstack.getItem() && (itemstack2.getItemDamage() == 32767 ||itemstack2.getItemDamage() == itemstack.getItemDamage());
    }

    public float giveExp(ItemStack itemstack){
        Iterator iterator = this.expList.entrySet().iterator();
        Map.Entry entry;

        do{
            if(!iterator.hasNext()){
                return 0;
            }
            entry = (Map.Entry) iterator.next();
        }
        while(!canBeExtracted(itemstack, (ItemStack)entry.getKey()));

        if(itemstack.getItem().getSmeltingExperience(itemstack) != -1){
            return itemstack.getItem().getSmeltingExperience(itemstack);
        }

        return ((Float) entry.getValue()).floatValue();
    }
}

 

 

ok firstly, when you define hashmaps, put you classes in don't leave them a s just Map or HashMap (you will only see Map in decompiled code) this prevent adding incorrect stuff to it by accident

 

For what you are doing would probably be better off not to use hashmaps and simply add the recipes to a list

then search the list for a match and you can then get the 2 output from the recipe

 

Two output?

Of What, with what and what else?

Always two output or is one output possible, too?

What is the input?

Does it work like two furnaces or one furnace with a random second output?

 

All of these choices drive how to program both your recipes and your logic.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.