More work on fuel gas system and hydrogen generator
This commit is contained in:
parent
269dec46e7
commit
50fa61e489
6 changed files with 82 additions and 23 deletions
|
@ -4,18 +4,25 @@ import java.util.HashMap;
|
|||
|
||||
import mekanism.common.Mekanism;
|
||||
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
|
||||
import buildcraft.api.fuels.IronEngineFuel;
|
||||
import buildcraft.api.fuels.IronEngineFuel.Fuel;
|
||||
|
||||
public class FuelHandler
|
||||
{
|
||||
public static HashMap<Gas, FuelGas> fuels = new HashMap<Gas, FuelGas>();
|
||||
public static HashMap<String, FuelGas> fuels = new HashMap<String, FuelGas>();
|
||||
|
||||
public static void addGas(Gas gas, int burnTicks, double energyPerMilliBucket)
|
||||
{
|
||||
fuels.put(gas.getName(), new FuelGas(burnTicks, energyPerMilliBucket));
|
||||
}
|
||||
|
||||
public static FuelGas getFuel(Gas gas)
|
||||
{
|
||||
if(fuels.containsKey(gas))
|
||||
if(fuels.containsKey(gas.getName()))
|
||||
{
|
||||
return fuels.get(gas);
|
||||
return fuels.get(gas.getName());
|
||||
}
|
||||
|
||||
if(gas.hasFluid())
|
||||
|
@ -24,7 +31,7 @@ public class FuelHandler
|
|||
if(bcFuel != null)
|
||||
{
|
||||
FuelGas fuel = new FuelGas(bcFuel);
|
||||
fuels.put(gas, fuel);
|
||||
fuels.put(gas.getName(), fuel);
|
||||
return fuel;
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +52,7 @@ public class FuelHandler
|
|||
|
||||
public FuelGas(Fuel bcFuel)
|
||||
{
|
||||
burnTicks = bcFuel.totalBurningTime;
|
||||
burnTicks = bcFuel.totalBurningTime / FluidContainerRegistry.BUCKET_VOLUME;
|
||||
energyPerTick = bcFuel.powerPerCycle * Mekanism.FROM_BC;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,16 @@ public class Gas
|
|||
unlocalizedName = name = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Gas object that corresponds to the given Fluid
|
||||
*/
|
||||
public Gas(Fluid f)
|
||||
{
|
||||
unlocalizedName = name = f.getName();
|
||||
icon = f.getStillIcon();
|
||||
fluid = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name (key) of this Gas. This is NOT a translated or localized display name.
|
||||
* @return this Gas's name or key
|
||||
|
|
|
@ -19,6 +19,7 @@ import mekanism.api.MekanismAPI;
|
|||
import mekanism.api.MekanismAPI.BoxBlacklistEvent;
|
||||
import mekanism.api.PressurizedProducts;
|
||||
import mekanism.api.PressurizedReactants;
|
||||
import mekanism.api.gas.FuelHandler;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasNetwork.GasTransferEvent;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
|
@ -825,6 +826,10 @@ public class Mekanism
|
|||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
//Fuel Gases
|
||||
FuelHandler.addGas(GasRegistry.getGas("hydrogen"), 1, FROM_H2);
|
||||
FuelHandler.addGas(GasRegistry.getGas("ethene"), 40, 25000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1210,6 +1215,7 @@ public class Mekanism
|
|||
InfuseRegistry.registerInfuseType(new InfuseType("DIAMOND", MekanismUtils.getResource(ResourceType.INFUSE, "Infusions.png"), 8, 0).setUnlocalizedName("infuse.diamond"));
|
||||
InfuseRegistry.registerInfuseType(new InfuseType("REDSTONE", MekanismUtils.getResource(ResourceType.INFUSE, "Infusions.png"), 16, 0).setUnlocalizedName("infuse.redstone"));
|
||||
InfuseRegistry.registerInfuseType(new InfuseType("FUNGI", MekanismUtils.getResource(ResourceType.INFUSE, "Infusions.png"), 20, 0).setUnlocalizedName("infuse.fungi"));
|
||||
InfuseRegistry.registerInfuseType(new InfuseType("BIO", MekanismUtils.getResource(ResourceType.INFUSE, "Infusions.png"), 12, 0).setUnlocalizedName("infuse.bio"));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package mekanism.common.inventory.slot;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.IGasItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -8,13 +11,20 @@ import net.minecraft.item.ItemStack;
|
|||
|
||||
public class SlotStorageTank extends Slot
|
||||
{
|
||||
public Gas type;
|
||||
public Collection<Gas> types;
|
||||
public boolean acceptsAllGasses;
|
||||
|
||||
public SlotStorageTank(IInventory inventory, Gas gas, boolean all, int index, int x, int y)
|
||||
{
|
||||
super(inventory, index, x, y);
|
||||
type = gas;
|
||||
types = Collections.singletonList(gas);
|
||||
acceptsAllGasses = all;
|
||||
}
|
||||
|
||||
public SlotStorageTank(IInventory inventory, Collection<Gas> gases, boolean all, int index, int x, int y)
|
||||
{
|
||||
super(inventory, index, x, y);
|
||||
types = gases;
|
||||
acceptsAllGasses = all;
|
||||
}
|
||||
|
||||
|
@ -28,7 +38,7 @@ public class SlotStorageTank extends Slot
|
|||
|
||||
if(itemstack.getItem() instanceof IGasItem)
|
||||
{
|
||||
return ((IGasItem)itemstack.getItem()).getGas(itemstack) == null || ((IGasItem)itemstack.getItem()).getGas(itemstack).getGas() == type;
|
||||
return ((IGasItem)itemstack.getItem()).getGas(itemstack) == null || types.contains(((IGasItem)itemstack.getItem()).getGas(itemstack).getGas());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -3,25 +3,24 @@ package mekanism.generators.common;
|
|||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mekanism.api.infuse.InfuseObject;
|
||||
import mekanism.api.infuse.InfuseRegistry;
|
||||
import mekanism.api.infuse.InfuseType;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
import mekanism.common.IModule;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.Version;
|
||||
import mekanism.common.item.ItemMekanism;
|
||||
import mekanism.common.recipe.MekanismRecipe;
|
||||
import mekanism.common.recipe.RecipeHandler;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.generators.common.block.BlockGenerator;
|
||||
import mekanism.generators.common.item.ItemBlockGenerator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
|
||||
import buildcraft.api.fuels.IronEngineFuel;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
|
@ -30,7 +29,6 @@ import cpw.mods.fml.common.Mod.Instance;
|
|||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
@ -65,10 +63,18 @@ public class MekanismGenerators implements IModule
|
|||
public static double windGeneration;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
//Register infuses
|
||||
InfuseRegistry.registerInfuseType(new InfuseType("BIO", MekanismUtils.getResource(ResourceType.INFUSE, "Infusions.png"), 12, 0).setUnlocalizedName("infuse.bio"));
|
||||
for(String s : IronEngineFuel.fuels.keySet())
|
||||
{
|
||||
Fluid f = FluidRegistry.getFluid(s);
|
||||
if(!(f == null || GasRegistry.containsGas(s)))
|
||||
{
|
||||
GasRegistry.register(new Gas(f));
|
||||
}
|
||||
}
|
||||
|
||||
IronEngineFuel.addFuel("ethene", (int)(240 * Mekanism.TO_BC), 40* FluidContainerRegistry.BUCKET_VOLUME);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -2,6 +2,8 @@ package mekanism.generators.common.tile;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.gas.FuelHandler;
|
||||
import mekanism.api.gas.FuelHandler.FuelGas;
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
import mekanism.api.gas.GasStack;
|
||||
|
@ -30,6 +32,9 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
|
|||
/** The tank this block is storing fuel in. */
|
||||
public GasTank fuelTank;
|
||||
|
||||
public int burnTicks = 0;
|
||||
public double generationRate = 0;
|
||||
|
||||
public TileEntityHydrogenGenerator()
|
||||
{
|
||||
super("HydrogenGenerator", Mekanism.FROM_H2*100, Mekanism.FROM_H2*2);
|
||||
|
@ -68,8 +73,23 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
|
|||
{
|
||||
setActive(true);
|
||||
|
||||
fuelTank.draw(1, true);
|
||||
setEnergy(electricityStored + Mekanism.FROM_H2);
|
||||
if(burnTicks > 0)
|
||||
{
|
||||
burnTicks--;
|
||||
setEnergy(electricityStored + generationRate);
|
||||
}
|
||||
else if(fuelTank.getStored() > 0)
|
||||
{
|
||||
FuelGas fuel = FuelHandler.getFuel(fuelTank.getGas().getGas());
|
||||
burnTicks = fuel.burnTicks;
|
||||
generationRate = fuel.energyPerTick;
|
||||
fuelTank.draw(1, true);
|
||||
setEnergy(electricityStored + generationRate);
|
||||
}
|
||||
else {
|
||||
burnTicks = 0;
|
||||
generationRate = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
setActive(false);
|
||||
|
@ -179,7 +199,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
|
|||
@Override
|
||||
public int receiveGas(ForgeDirection side, GasStack stack)
|
||||
{
|
||||
if(fuelTank.getGas() == null || fuelTank.getGas().getGas() == stack.getGas())
|
||||
if(fuelTank.getGas() == null || fuelTank.getGas().isGasEqual(stack))
|
||||
{
|
||||
return fuelTank.receive(stack, true);
|
||||
}
|
||||
|
@ -213,7 +233,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
|
|||
@Override
|
||||
public boolean canReceiveGas(ForgeDirection side, Gas type)
|
||||
{
|
||||
return (type == GasRegistry.getGas("hydrogen") || type == GasRegistry.getGas("ethene")) && side != ForgeDirection.getOrientation(facing);
|
||||
return FuelHandler.getFuel(type) != null && side != ForgeDirection.getOrientation(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue