Made fuel less hideous codewise

This commit is contained in:
Ellpeck 2016-07-04 20:23:53 +02:00
parent 0eb64b2659
commit 5c114e3880
2 changed files with 23 additions and 26 deletions

View file

@ -20,56 +20,54 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.IFuelHandler; import net.minecraftforge.fml.common.IFuelHandler;
import net.minecraftforge.fml.common.registry.GameRegistry; 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{ public class FuelHandler implements IFuelHandler{
private static final HashMap<Pair<Item, Integer>, Integer> FUEL_LIST = new HashMap<Pair<Item, Integer>, Integer>(); private static final List<Fuel> FUEL_LIST = new ArrayList<Fuel>();
public static void init(){ public static void init(){
ModUtil.LOGGER.info("Initializing Fuelstuffs..."); ModUtil.LOGGER.info("Initializing Fuelstuffs...");
GameRegistry.registerFuelHandler(new FuelHandler()); GameRegistry.registerFuelHandler(new FuelHandler());
setFuelValues();
}
public static void setFuelValues(){
addFuel(InitItems.itemMisc, TheMiscItems.TINY_CHAR.ordinal(), 200); addFuel(InitItems.itemMisc, TheMiscItems.TINY_CHAR.ordinal(), 200);
addFuel(InitItems.itemMisc, TheMiscItems.TINY_COAL.ordinal(), 200); addFuel(InitItems.itemMisc, TheMiscItems.TINY_COAL.ordinal(), 200);
addFuel(InitBlocks.blockMisc, TheMiscBlocks.CHARCOAL_BLOCK.ordinal(), 16000); addFuel(InitBlocks.blockMisc, TheMiscBlocks.CHARCOAL_BLOCK.ordinal(), 16000);
addFuel(InitItems.itemMisc, TheMiscItems.BIOCOAL.ordinal(), 180); addFuel(InitItems.itemMisc, TheMiscItems.BIOCOAL.ordinal(), 180);
} }
private static void addFuel(Item item, int metadata, int value){ private static void addFuel(Item item, int meta, int value){
FUEL_LIST.put(Pair.of(item, metadata), value); FUEL_LIST.add(new Fuel(new ItemStack(item, meta), value));
} }
private static void addFuel(Block block, int metadata, int value){ private static void addFuel(Block block, int meta, int value){
addFuel(Item.getItemFromBlock(block), metadata, value); addFuel(Item.getItemFromBlock(block), meta, value);
} }
private static int getFuelValue(ItemStack stack){ @Override
if(stack != null && stack.getItem() != null){ public int getBurnTime(ItemStack stack){
Pair<Item, Integer> pair = Pair.of(stack.getItem(), stack.getItemDamage()); if(stack != null){
for(Fuel fuel : FUEL_LIST){
if(FUEL_LIST.containsKey(pair)){ if(stack.isItemEqual(fuel.fuel)){
return FUEL_LIST.get(pair); return fuel.burnTime;
}
else{
pair = Pair.of(stack.getItem(), 0);
if(FUEL_LIST.containsKey(pair)){
return FUEL_LIST.get(pair);
} }
} }
} }
return 0; return 0;
} }
@Override private static class Fuel{
public int getBurnTime(ItemStack fuel){
return getFuelValue(fuel); public ItemStack fuel;
public int burnTime;
public Fuel(ItemStack fuel, int burnTime){
this.fuel = fuel;
this.burnTime = burnTime;
}
} }
} }

View file

@ -50,7 +50,6 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
this.name = name; this.name = name;
} }
//TODO Change for next major update to use the name variable automatically
public static void init(){ public static void init(){
ModUtil.LOGGER.info("Registering TileEntities..."); ModUtil.LOGGER.info("Registering TileEntities...");