Very Nice Fuel Handling, By: CBG

CarbonBasedGhost

New Member
Jul 29, 2019
910
-1
0
Hiya,

Today I bring you a very nice fuel handling system I made that is extremely light weight(compared to what people normally do).

And going on a stretch I say this should be implemented to forge just to make everything so much simpler. @GregoriousT (screw the spelling) helped me out a bit to make it more efficient but other than that it is all mine.

So In order for this to work you need the handler (feel free to suggest things to make it more efficient or to ask questions)
Code:
public class VinillaFurnaceFuelHandler implements IFuelHandler{
   
    public static HashMap<Item, Integer> FurnaceFuel = new HashMap<Item, Integer>();

   
    public static void RegisterFurnaceFuel(Item fuel, Integer burnTime){
       
        FurnaceFuel.put(fuel, burnTime);
    }
    @Override
    public int getBurnTime(ItemStack fuel) {
       
        Item ItemInFuelSlot = fuel.getItem();
        Integer BurnTime = FurnaceFuel.get(ItemInFuelSlot);
       
        if (BurnTime == null) return 0; else return BurnTime;   
    }
}

Now you can directly input items to be made fuels into this but I for blocks I had to make a method, and to make the code look clean I made a method for items too.

Code:
public static void addItemFurnaceFuel(Item fuel, Integer burnTime){
       
        VinillaFurnaceFuelHandler.RegisterFurnaceFuel(fuel, burnTime);
       
    }

    public static void addBlockFurnaceFuel (Block fuel, Integer burnTime){
       
        VinillaFurnaceFuelHandler.RegisterFurnaceFuel(Item.getItemFromBlock(fuel), burnTime);
       
    }

and all you have to do now is register the fuel handler in preInit

Code:
@EventHandler
    public void preInit(FMLPreInitializationEvent event) {
       
        GameRegistry.registerFuelHandler(new VinillaFurnaceFuelHandler());
       
    }
 

CarbonBasedGhost

New Member
Jul 29, 2019
910
-1
0
If that's extremely lightweight, I want to know what the heck everyone else does.
If I want to add 30 fuels I just register them in there. If someone uses the traditional way there will be thirty if statements all lined up next to each other.
 

CarbonBasedGhost

New Member
Jul 29, 2019
910
-1
0
You forgot to add a check for registered fuel. Also, don't forget about naming convention.
Sorry about the late reply. This is just an outline however that is something that should be implemented. If I were to make a check I would make it so I look at the conflicting fuel then, delete my registration (unless said otherwise, probably by a priority 1 byte variable). The reason I would not re-register the fuel through my own methods is because that would make it even more laggy with the most efficient method of withholding a recipe from being registered.

Hopefully that makes some sense
-CBG
 
  • Like
Reactions: 1SDAN and null123