Minecraftforge: [Request] Hook for fuels for brewing stand

Created on 27 Nov 2016  路  15Comments  路  Source: MinecraftForge/MinecraftForge

Originally proposed in pull #2731, there should be a way for adding fuels for brewing stands.

Possible ways:

  1. Use some sort of fuel handler;
  2. Use item map.

More, thanks @mezz for organizing forge.

Feature Stale help wanted

All 15 comments

This isn't something that will get used heavily so it should be kept basic.

BrewingRecipeRegistry.java 

List<ItemStack> fuels;
List<Integer> burnTimes;

public void addFuel(ItemStack fuel, int burnTime) {
    fuels.add(fuel);
    burnTimes.add(burnTime);
}

public int getBurnTime(ItemStack stack) {
    //Iterate over the list and compare the ItemStacks to get the index, and if it's found return the value from the burn time list, else return 0.
}

public List<ItemStack> getFuels() { 
    return Collections.unmodifiableList(fuels);
}

@mezz How about oredict

If you have an oredict tag, you can grab all the items from the oreDict for that tag and then add them. As long as there are not 1000 fuels this should be OK.

@mezz It should probably use a Map instead of two separate lists.

@Silly511 ItemStack can't be used as a map key, the comparisons are complicated.

@mezz Your right, I forgot that ItemStack doesn't override equals(Object).

Excuse me for jumping in.
With this you don't have to iterate.

Example Code

Equivalence<ItemStack> itemEquivalence = new Equivalence<ItemStack>(){
    protected boolean doEquivalent(ItemStack a, ItemStack b){
        //...
    }

    protected int doHash(ItemStack t){
        //...
    }
};

Map<Equivalence.Wrapper<ItemStack>, Integer> fuelMap;

public void addFuel(@Nonnull ItemStack fuel, int burnTime){
    fuelMap.put(itemEquivalence.wrap(fuel), burnTime);
}

public int getBurnTime(@Nullable ItemStack stack){
    return Objects.firstNonNull(fuelMap.get(itemEquivalence.wrap(stack)), 0);
}

public Collection<ItemStack> getFuels(){
    return Collections.unmodifiableCollection(Collections2.transform(fuelMap.keySet(), new Function<Equivalence.Wrapper<ItemStack>, ItemStack>(){
        @Nullable
        @Override
        public ItemStack apply(@Nullable Equivalence.Wrapper<ItemStack> input){
            assert input != null;
            return input.get();
        }
    }));
}

@CrafterKina I would use hashing like oredict does.

@liach Then you can implement doHash as oredict.

final static Equivalence<ItemStack> itemEquivalence = new Equivalence<ItemStack>(){
    protected boolean doEquivalent(@Nonnull ItemStack a, @Nonnull ItemStack b){
        return OreDictionary.itemMatches(a, b, false);
    }

    protected int doHash(@Nonnull ItemStack stack){
        ResourceLocation registryName = stack.getItem().delegate.name();
        int hash;
        if (registryName == null)
        {
            FMLLog.bigWarning("BIG WARN!!");
            hash = -1;
        }
        else
        {
            hash = GameData.getItemRegistry().getId(registryName);
        }
        if (stack.getItemDamage() != OreDictionary.WILDCARD_VALUE)
        {
            hash |= ((stack.getItemDamage() + 1) << 16); // +1 so 0 is significant
        }
        return hash;
    }
};

I don't see the need to optimize this, it will be used by only a few mods. Keep it simple please.

This issue has been automatically marked as stale because it has not had activity in a long time, and will be closed if no further activity occurs. If this issue was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

This has an open PR now, so it is not stale.

This issue has been automatically marked as stale because it has not had activity in a long time. If this issue is still relevant and should remain open, please reply with a short explanation (e.g. "I have checked the code and this issue is still relevant because ___." or "Here's a screenshot of this issue on the latest version"). Thank you for your contributions!

This issue has been automatically closed because it has not had activity in a long time. Please feel free to reopen it or create a new issue.

oh.

Was this page helpful?
0 / 5 - 0 ratings