mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48: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.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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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...");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue