From 5c114e388081dd5666c3b8fed71ae6ed34469d0a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 4 Jul 2016 20:23:53 +0200 Subject: [PATCH] Made fuel less hideous codewise --- .../mod/recipe/FuelHandler.java | 48 +++++++++---------- .../mod/tile/TileEntityBase.java | 1 - 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/FuelHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/FuelHandler.java index 7475a3451..e96a11372 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/FuelHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/FuelHandler.java @@ -20,56 +20,54 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.common.IFuelHandler; import net.minecraftforge.fml.common.registry.GameRegistry; -import org.apache.commons.lang3.tuple.Pair; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.List; -//TODO Make this less hideous public class FuelHandler implements IFuelHandler{ - private static final HashMap, Integer> FUEL_LIST = new HashMap, Integer>(); + private static final List FUEL_LIST = new ArrayList(); public static void init(){ ModUtil.LOGGER.info("Initializing Fuelstuffs..."); GameRegistry.registerFuelHandler(new FuelHandler()); - setFuelValues(); - } - public static void setFuelValues(){ addFuel(InitItems.itemMisc, TheMiscItems.TINY_CHAR.ordinal(), 200); addFuel(InitItems.itemMisc, TheMiscItems.TINY_COAL.ordinal(), 200); addFuel(InitBlocks.blockMisc, TheMiscBlocks.CHARCOAL_BLOCK.ordinal(), 16000); addFuel(InitItems.itemMisc, TheMiscItems.BIOCOAL.ordinal(), 180); } - private static void addFuel(Item item, int metadata, int value){ - FUEL_LIST.put(Pair.of(item, metadata), value); + private static void addFuel(Item item, int meta, int value){ + FUEL_LIST.add(new Fuel(new ItemStack(item, meta), value)); } - private static void addFuel(Block block, int metadata, int value){ - addFuel(Item.getItemFromBlock(block), metadata, value); + private static void addFuel(Block block, int meta, int value){ + addFuel(Item.getItemFromBlock(block), meta, value); } - private static int getFuelValue(ItemStack stack){ - if(stack != null && stack.getItem() != null){ - Pair pair = Pair.of(stack.getItem(), stack.getItemDamage()); - - if(FUEL_LIST.containsKey(pair)){ - return FUEL_LIST.get(pair); - } - else{ - pair = Pair.of(stack.getItem(), 0); - if(FUEL_LIST.containsKey(pair)){ - return FUEL_LIST.get(pair); + @Override + public int getBurnTime(ItemStack stack){ + if(stack != null){ + for(Fuel fuel : FUEL_LIST){ + if(stack.isItemEqual(fuel.fuel)){ + return fuel.burnTime; } } } return 0; } - @Override - public int getBurnTime(ItemStack fuel){ - return getFuelValue(fuel); + private static class Fuel{ + + public ItemStack fuel; + public int burnTime; + + public Fuel(ItemStack fuel, int burnTime){ + this.fuel = fuel; + this.burnTime = burnTime; + } + } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java index 6250ad729..fe28f4844 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java @@ -50,7 +50,6 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{ this.name = name; } - //TODO Change for next major update to use the name variable automatically public static void init(){ ModUtil.LOGGER.info("Registering TileEntities...");