mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Made fuel less hideous codewise
This commit is contained in:
parent
0eb64b2659
commit
5c114e3880
2 changed files with 23 additions and 26 deletions
|
@ -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<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(){
|
||||
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<Item, Integer> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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...");
|
||||
|
||||
|
|
Loading…
Reference in a new issue