Add the unified FluidGenerator recipe system + Restructure FluidGenerators tiles
They should all be pretty now
This commit is contained in:
parent
3bf346f39a
commit
97192ee3f4
12 changed files with 442 additions and 607 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
package techreborn.api.generator;
|
||||||
|
|
||||||
|
public enum EFluidGenerator {
|
||||||
|
THERMAL, GAS, DIESEL, SEMIFLUID
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
package techreborn.api.generator;
|
||||||
|
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
|
||||||
|
public class FluidGeneratorRecipe {
|
||||||
|
private Fluid fluid;
|
||||||
|
private int energyPerMb;
|
||||||
|
|
||||||
|
public FluidGeneratorRecipe(Fluid fluid, int energyPerMb)
|
||||||
|
{
|
||||||
|
this.fluid = fluid;
|
||||||
|
this.energyPerMb = energyPerMb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Fluid getFluid() {
|
||||||
|
return fluid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFluid(Fluid fluid) {
|
||||||
|
this.fluid = fluid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEnergyPerMb() {
|
||||||
|
return energyPerMb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnergyPerMb(int energyPerMb) {
|
||||||
|
this.energyPerMb = energyPerMb;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "FluidGeneratorRecipe [fluid=" + fluid + ", energyPerMb=" + energyPerMb + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + energyPerMb;
|
||||||
|
result = prime * result + ((fluid == null) ? 0 : fluid.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
FluidGeneratorRecipe other = (FluidGeneratorRecipe) obj;
|
||||||
|
if (energyPerMb != other.energyPerMb)
|
||||||
|
return false;
|
||||||
|
if (fluid == null) {
|
||||||
|
if (other.fluid != null)
|
||||||
|
return false;
|
||||||
|
} else if (!fluid.equals(other.fluid))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
package techreborn.api.generator;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
|
||||||
|
public class FluidGeneratorRecipeList {
|
||||||
|
private HashSet<FluidGeneratorRecipe> recipes;
|
||||||
|
|
||||||
|
public FluidGeneratorRecipeList(FluidGeneratorRecipe... recipes)
|
||||||
|
{
|
||||||
|
this.recipes = Sets.newHashSet(recipes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean addRecipe(FluidGeneratorRecipe fluidGeneratorRecipe) {
|
||||||
|
if(!this.getRecipeForFluid(fluidGeneratorRecipe.getFluid()).isPresent())
|
||||||
|
return this.getRecipes().add(fluidGeneratorRecipe);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeRecipe(FluidGeneratorRecipe fluidGeneratorRecipe)
|
||||||
|
{
|
||||||
|
return this.getRecipes().remove(fluidGeneratorRecipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<FluidGeneratorRecipe> getRecipeForFluid(Fluid fluid)
|
||||||
|
{
|
||||||
|
return this.recipes.stream().filter(recipe -> recipe.getFluid().equals(fluid)).findAny();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<FluidGeneratorRecipe> getRecipes() {
|
||||||
|
return recipes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecipes(HashSet<FluidGeneratorRecipe> recipes) {
|
||||||
|
this.recipes = recipes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "FluidGeneratorRecipeList [recipes=" + recipes + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((recipes == null) ? 0 : recipes.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
FluidGeneratorRecipeList other = (FluidGeneratorRecipeList) obj;
|
||||||
|
if (recipes == null) {
|
||||||
|
if (other.recipes != null)
|
||||||
|
return false;
|
||||||
|
} else if (!recipes.equals(other.recipes))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package techreborn.api.generator;
|
||||||
|
|
||||||
|
import java.util.EnumMap;
|
||||||
|
|
||||||
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
|
||||||
|
public class GeneratorRecipeHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This EnumMap store all the energy recipes for the fluid generators. Each
|
||||||
|
* value of the EFluidGenerator enum is linked to an object holding a set of
|
||||||
|
* FluidGeneratorRecipe.
|
||||||
|
*/
|
||||||
|
public static EnumMap<EFluidGenerator, FluidGeneratorRecipeList> fluidRecipes = new EnumMap<>(
|
||||||
|
EFluidGenerator.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a Fluid energy recipe.
|
||||||
|
*
|
||||||
|
* @param generatorType
|
||||||
|
* A value of the EFluidGenerator type in which the fluid is
|
||||||
|
* allowed to be consumed.
|
||||||
|
* @param fluidType
|
||||||
|
* @param energyPerMb
|
||||||
|
* Represent the energy / MILLI_BUCKET the fluid will produce.
|
||||||
|
* Some generators use this value to alter their fluid decay
|
||||||
|
* speed to match their maximum energy output.
|
||||||
|
*/
|
||||||
|
public static void registerFluidRecipe(EFluidGenerator generatorType, Fluid fluidType, int energyPerMb) {
|
||||||
|
fluidRecipes.putIfAbsent(generatorType, new FluidGeneratorRecipeList());
|
||||||
|
fluidRecipes.get(generatorType).addRecipe(new FluidGeneratorRecipe(fluidType, energyPerMb));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param generatorType
|
||||||
|
* A value of the EFluidGenerator type in which the fluid is
|
||||||
|
* allowed to be consumed.
|
||||||
|
* @return An object holding a set of availables recipes for this type of
|
||||||
|
* FluidGenerator.
|
||||||
|
*/
|
||||||
|
public static FluidGeneratorRecipeList getFluidRecipesForGenerator(EFluidGenerator generatorType) {
|
||||||
|
return fluidRecipes.get(generatorType);
|
||||||
|
}
|
||||||
|
}
|
4
src/main/java/techreborn/api/generator/package-info.java
Normal file
4
src/main/java/techreborn/api/generator/package-info.java
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
@API(apiVersion = "@MODVERSION@", owner = "techreborn", provides = "techrebornAPI")
|
||||||
|
package techreborn.api.generator;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
|
@ -166,7 +166,7 @@ public class ModFluids {
|
||||||
BlockFluidLithium = new BlockFluidTechReborn(fluidLithium, Material.WATER, "techreborn.lithium");
|
BlockFluidLithium = new BlockFluidTechReborn(fluidLithium, Material.WATER, "techreborn.lithium");
|
||||||
registerBlock(BlockFluidLithium,
|
registerBlock(BlockFluidLithium,
|
||||||
ModInfo.MOD_ID + "_" + BlockFluidLithium.getUnlocalizedName().substring(5));
|
ModInfo.MOD_ID + "_" + BlockFluidLithium.getUnlocalizedName().substring(5));
|
||||||
FluidPowerManager.fluidPowerValues.put(fluidNitrofuel, 24.0);
|
FluidPowerManager.fluidPowerValues.put(fluidLithium, 24.0);
|
||||||
|
|
||||||
FluidRegistry.registerFluid(fluidMercury);
|
FluidRegistry.registerFluid(fluidMercury);
|
||||||
BlockFluidMercury = new BlockFluidTechReborn(fluidMercury, Material.WATER, "techreborn.mercury");
|
BlockFluidMercury = new BlockFluidTechReborn(fluidMercury, Material.WATER, "techreborn.mercury");
|
||||||
|
@ -268,13 +268,13 @@ public class ModFluids {
|
||||||
BlockFluidNitroDiesel = new BlockFluidTechReborn(fluidNitroDiesel, Material.WATER, "techreborn.nitrodiesel");
|
BlockFluidNitroDiesel = new BlockFluidTechReborn(fluidNitroDiesel, Material.WATER, "techreborn.nitrodiesel");
|
||||||
registerBlock(BlockFluidNitroDiesel,
|
registerBlock(BlockFluidNitroDiesel,
|
||||||
ModInfo.MOD_ID + "_" + BlockFluidNitroDiesel.getUnlocalizedName().substring(5));
|
ModInfo.MOD_ID + "_" + BlockFluidNitroDiesel.getUnlocalizedName().substring(5));
|
||||||
FluidPowerManager.fluidPowerValues.put(fluidNitrofuel, 36.0);
|
FluidPowerManager.fluidPowerValues.put(fluidNitroDiesel, 36.0);
|
||||||
|
|
||||||
FluidRegistry.registerFluid(fluidOil);
|
FluidRegistry.registerFluid(fluidOil);
|
||||||
BlockFluidOil = new BlockFluidTechReborn(fluidOil, Material.WATER, "techreborn.oil");
|
BlockFluidOil = new BlockFluidTechReborn(fluidOil, Material.WATER, "techreborn.oil");
|
||||||
registerBlock(BlockFluidOil,
|
registerBlock(BlockFluidOil,
|
||||||
ModInfo.MOD_ID + "_" + BlockFluidOil.getUnlocalizedName().substring(5));
|
ModInfo.MOD_ID + "_" + BlockFluidOil.getUnlocalizedName().substring(5));
|
||||||
FluidPowerManager.fluidPowerValues.put(fluidNitrofuel, 16.0);
|
FluidPowerManager.fluidPowerValues.put(fluidOil, 16.0);
|
||||||
|
|
||||||
FluidRegistry.registerFluid(fluidSulfuricAcid);
|
FluidRegistry.registerFluid(fluidSulfuricAcid);
|
||||||
BlockFluidSulfuricAcid = new BlockFluidTechReborn(fluidSulfuricAcid, Material.WATER, "techreborn.sulfuricacid");
|
BlockFluidSulfuricAcid = new BlockFluidTechReborn(fluidSulfuricAcid, Material.WATER, "techreborn.sulfuricacid");
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.minecraftforge.common.ForgeModContainer;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.fluids.FluidUtil;
|
||||||
import net.minecraftforge.fluids.UniversalBucket;
|
import net.minecraftforge.fluids.UniversalBucket;
|
||||||
import net.minecraftforge.fml.common.Loader;
|
import net.minecraftforge.fml.common.Loader;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
@ -22,6 +23,8 @@ import reborncore.common.util.StringUtils;
|
||||||
import techreborn.Core;
|
import techreborn.Core;
|
||||||
import techreborn.api.ScrapboxList;
|
import techreborn.api.ScrapboxList;
|
||||||
import techreborn.api.TechRebornAPI;
|
import techreborn.api.TechRebornAPI;
|
||||||
|
import techreborn.api.generator.EFluidGenerator;
|
||||||
|
import techreborn.api.generator.GeneratorRecipeHelper;
|
||||||
import techreborn.api.reactor.FusionReactorRecipe;
|
import techreborn.api.reactor.FusionReactorRecipe;
|
||||||
import techreborn.api.reactor.FusionReactorRecipeHelper;
|
import techreborn.api.reactor.FusionReactorRecipeHelper;
|
||||||
import techreborn.api.recipe.RecyclerRecipe;
|
import techreborn.api.recipe.RecyclerRecipe;
|
||||||
|
@ -99,6 +102,7 @@ public class ModRecipes {
|
||||||
addCompressorRecipes();
|
addCompressorRecipes();
|
||||||
addWireRecipes();
|
addWireRecipes();
|
||||||
addScrapBoxloot();
|
addScrapBoxloot();
|
||||||
|
addFluidGeneratorRecipes();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addScrapBoxloot() {
|
static void addScrapBoxloot() {
|
||||||
|
@ -3220,6 +3224,23 @@ public class ModRecipes {
|
||||||
CraftingHelper.addShapedOreRecipe(gemboots, "G G", "G G", 'G', gem);
|
CraftingHelper.addShapedOreRecipe(gemboots, "G G", "G G", 'G', gem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void addFluidGeneratorRecipes() {
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.DIESEL, ModFluids.fluidNitrofuel, 24);
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.DIESEL, ModFluids.fluidNitrocoalfuel, 48);
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.DIESEL, ModFluids.fluidLithium, 24);
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.DIESEL, ModFluids.fluidNitroDiesel, 36);
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.DIESEL, ModFluids.fluidOil, 16);
|
||||||
|
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.SEMIFLUID, ModFluids.fluidOil, 64);
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.SEMIFLUID, ModFluids.fluidSodium, 30);
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.SEMIFLUID, ModFluids.fluidLithium, 60);
|
||||||
|
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.THERMAL, FluidRegistry.LAVA, 60);
|
||||||
|
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.GAS, ModFluids.fluidHydrogen, 15);
|
||||||
|
GeneratorRecipeHelper.registerFluidRecipe(EFluidGenerator.GAS, ModFluids.fluidMethane, 45);
|
||||||
|
}
|
||||||
|
|
||||||
public static ItemStack getBucketWithFluid(Fluid fluid) {
|
public static ItemStack getBucketWithFluid(Fluid fluid) {
|
||||||
return UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, fluid);
|
return UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, fluid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,208 @@
|
||||||
|
package techreborn.tiles.generator;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.network.NetworkManager;
|
||||||
|
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||||
|
import reborncore.api.power.EnumPowerTier;
|
||||||
|
import reborncore.api.tile.IInventoryProvider;
|
||||||
|
import reborncore.common.IWrenchable;
|
||||||
|
import reborncore.common.blocks.BlockMachineBase;
|
||||||
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
||||||
|
import reborncore.common.util.FluidUtils;
|
||||||
|
import reborncore.common.util.Inventory;
|
||||||
|
import reborncore.common.util.Tank;
|
||||||
|
import techreborn.api.generator.EFluidGenerator;
|
||||||
|
import techreborn.api.generator.FluidGeneratorRecipeList;
|
||||||
|
import techreborn.api.generator.GeneratorRecipeHelper;
|
||||||
|
|
||||||
|
public abstract class TileBaseFluidGenerator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
|
||||||
|
|
||||||
|
private final FluidGeneratorRecipeList recipes;
|
||||||
|
|
||||||
|
private final int euTick;
|
||||||
|
|
||||||
|
public final Tank tank;
|
||||||
|
public final Inventory inventory;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We use this to keep track of fractional millibuckets, allowing us to hit
|
||||||
|
* our eu/bucket targets while still only ever removing integer millibucket
|
||||||
|
* amounts.
|
||||||
|
*/
|
||||||
|
double pendingWithdraw = 0.0;
|
||||||
|
|
||||||
|
public TileBaseFluidGenerator(EFluidGenerator type, int tier, String tileName, int tankCapacity, int euTick) {
|
||||||
|
super(tier);
|
||||||
|
|
||||||
|
recipes = GeneratorRecipeHelper.getFluidRecipesForGenerator(type);
|
||||||
|
|
||||||
|
tank = new Tank(tileName, tankCapacity, this);
|
||||||
|
inventory = new Inventory(3, tileName, 64, this);
|
||||||
|
this.euTick = euTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileBaseFluidGenerator(EFluidGenerator type, EnumPowerTier tier, String tileName, int tankCapacity,
|
||||||
|
int euTick) {
|
||||||
|
this(type, tier.ordinal(), tileName, tankCapacity, euTick);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected long lastOutput = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEntity() {
|
||||||
|
super.updateEntity();
|
||||||
|
|
||||||
|
if (!this.world.isRemote) {
|
||||||
|
if (this.acceptFluid() && FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
|
||||||
|
this.syncWithAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.tank.getFluidAmount() > 0 && tryAddingEnergy(euTick)) {
|
||||||
|
this.getRecipes().getRecipeForFluid(tank.getFluidType()).ifPresent(recipe -> {
|
||||||
|
|
||||||
|
final Integer euPerBucket = recipe.getEnergyPerMb() * 1000;
|
||||||
|
final float millibucketsPerTick = 16000f / (float) euPerBucket;
|
||||||
|
this.pendingWithdraw += millibucketsPerTick;
|
||||||
|
|
||||||
|
final int currentWithdraw = (int) this.pendingWithdraw; // float
|
||||||
|
// -->
|
||||||
|
// int
|
||||||
|
// conversion floors
|
||||||
|
// the float
|
||||||
|
this.pendingWithdraw -= currentWithdraw;
|
||||||
|
|
||||||
|
this.tank.drain(currentWithdraw, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.tank.getFluidType() != null && this.getStackInSlot(2) == ItemStack.EMPTY)
|
||||||
|
this.inventory.setInventorySlotContents(2, new ItemStack(this.tank.getFluidType().getBlock()));
|
||||||
|
else if (this.tank.getFluidType() == null && this.getStackInSlot(2) != ItemStack.EMPTY)
|
||||||
|
this.setInventorySlotContents(2, ItemStack.EMPTY);
|
||||||
|
|
||||||
|
if (!this.world.isRemote) {
|
||||||
|
if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive())
|
||||||
|
this.world.setBlockState(this.getPos(),
|
||||||
|
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
|
||||||
|
else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && this.isActive())
|
||||||
|
this.world.setBlockState(this.getPos(),
|
||||||
|
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean tryAddingEnergy(int amount) {
|
||||||
|
if (this.getMaxPower() - this.getEnergy() >= amount) {
|
||||||
|
addEnergy(amount);
|
||||||
|
return true;
|
||||||
|
} else if (this.getMaxPower() - this.getEnergy() > 0) {
|
||||||
|
addEnergy(this.getMaxPower() - this.getEnergy());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean acceptFluid() {
|
||||||
|
if (!this.getStackInSlot(0).isEmpty()) {
|
||||||
|
FluidStack stack = FluidUtils.getFluidStackInContainer(this.getStackInSlot(0));
|
||||||
|
if (stack != null)
|
||||||
|
return recipes.getRecipeForFluid(stack.getFluid()).isPresent();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FluidGeneratorRecipeList getRecipes() {
|
||||||
|
return recipes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getMaxOutput() {
|
||||||
|
return euTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getMaxInput() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumPowerTier getTier() {
|
||||||
|
return EnumPowerTier.values()[this.tier];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canProvideEnergy(EnumFacing direction) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||||
|
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.hasCapability(capability, facing);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||||
|
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||||
|
return (T) tank;
|
||||||
|
}
|
||||||
|
return super.getCapability(capability, facing);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
||||||
|
super.readFromNBT(tagCompound);
|
||||||
|
tank.readFromNBT(tagCompound);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
||||||
|
super.writeToNBT(tagCompound);
|
||||||
|
tank.writeToNBT(tagCompound);
|
||||||
|
return tagCompound;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
|
||||||
|
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
|
||||||
|
getPos().getY(), getPos().getZ());
|
||||||
|
readFromNBT(packet.getNbtCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumFacing getFacing() {
|
||||||
|
return getFacingEnum();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
||||||
|
return entityPlayer.isSneaking();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getWrenchDropRate() {
|
||||||
|
return 1.0F;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,51 +2,15 @@ package techreborn.tiles.generator;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.network.NetworkManager;
|
|
||||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|
||||||
import reborncore.api.fuel.FluidPowerManager;
|
|
||||||
import reborncore.api.power.EnumPowerTier;
|
import reborncore.api.power.EnumPowerTier;
|
||||||
import reborncore.api.tile.IInventoryProvider;
|
import techreborn.api.generator.EFluidGenerator;
|
||||||
import reborncore.common.IWrenchable;
|
|
||||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
|
||||||
import reborncore.common.util.FluidUtils;
|
|
||||||
import reborncore.common.util.Inventory;
|
|
||||||
import reborncore.common.util.Tank;
|
|
||||||
import techreborn.config.ConfigTechReborn;
|
import techreborn.config.ConfigTechReborn;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
|
|
||||||
public class TileDieselGenerator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
|
public class TileDieselGenerator extends TileBaseFluidGenerator {
|
||||||
|
|
||||||
public static final int euTick = ConfigTechReborn.ThermalGeneratorOutput;
|
|
||||||
public Tank tank = new Tank("TileDieselGenerator", 1000 * 10, this);
|
|
||||||
public Inventory inventory = new Inventory(3, "TileDieselGenerator", 64, this);
|
|
||||||
|
|
||||||
public TileDieselGenerator() {
|
public TileDieselGenerator() {
|
||||||
super(ConfigTechReborn.ThermalGeneratorTier);
|
super(EFluidGenerator.DIESEL, ConfigTechReborn.ThermalGeneratorTier, "TileDieselGenerator", 1000*10, ConfigTechReborn.ThermalGeneratorOutput);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumFacing getFacing() {
|
|
||||||
return getFacingEnum();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
|
||||||
return entityPlayer.isSneaking();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getWrenchDropRate() {
|
|
||||||
return 1.0F;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,100 +18,18 @@ public class TileDieselGenerator extends TilePowerAcceptor implements IWrenchabl
|
||||||
return new ItemStack(ModBlocks.dieselGenerator, 1);
|
return new ItemStack(ModBlocks.dieselGenerator, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
|
||||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.hasCapability(capability, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
|
||||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
|
||||||
return (T) tank;
|
|
||||||
}
|
|
||||||
return super.getCapability(capability, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
|
||||||
super.readFromNBT(tagCompound);
|
|
||||||
tank.readFromNBT(tagCompound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
|
||||||
super.writeToNBT(tagCompound);
|
|
||||||
tank.writeToNBT(tagCompound);
|
|
||||||
return tagCompound;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
|
|
||||||
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
|
|
||||||
getPos().getY(), getPos().getZ());
|
|
||||||
readFromNBT(packet.getNbtCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
super.updateEntity();
|
|
||||||
if (!world.isRemote) {
|
|
||||||
FluidUtils.drainContainers(tank, inventory, 0, 1);
|
|
||||||
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType());
|
|
||||||
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) {
|
|
||||||
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
|
|
||||||
syncWithAll();
|
|
||||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {
|
|
||||||
setInventorySlotContents(2, ItemStack.EMPTY);
|
|
||||||
syncWithAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tank.isEmpty() && tank.getFluidType() != null
|
|
||||||
&& FluidPowerManager.fluidPowerValues.containsKey(tank.getFluidType())) {
|
|
||||||
double powerIn = FluidPowerManager.fluidPowerValues.get(tank.getFluidType());
|
|
||||||
if (getFreeSpace() >= powerIn) {
|
|
||||||
addEnergy(powerIn, false);
|
|
||||||
tank.drain(1, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getMaxPower() {
|
public double getMaxPower() {
|
||||||
return ConfigTechReborn.ThermalGeneratorCharge;
|
return ConfigTechReborn.ThermalGeneratorCharge;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canAcceptEnergy(EnumFacing direction) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canProvideEnergy(EnumFacing direction) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getMaxOutput() {
|
public double getMaxOutput() {
|
||||||
return 64;
|
return 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMaxInput() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumPowerTier getTier() {
|
public EnumPowerTier getTier() {
|
||||||
return EnumPowerTier.LOW;
|
return EnumPowerTier.LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Inventory getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,65 +2,15 @@ package techreborn.tiles.generator;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.network.NetworkManager;
|
|
||||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|
||||||
import reborncore.api.power.EnumPowerTier;
|
import reborncore.api.power.EnumPowerTier;
|
||||||
import reborncore.api.tile.IInventoryProvider;
|
import techreborn.api.generator.EFluidGenerator;
|
||||||
import reborncore.common.IWrenchable;
|
|
||||||
import reborncore.common.blocks.BlockMachineBase;
|
|
||||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
|
||||||
import reborncore.common.util.FluidUtils;
|
|
||||||
import reborncore.common.util.Inventory;
|
|
||||||
import reborncore.common.util.Tank;
|
|
||||||
import techreborn.config.ConfigTechReborn;
|
import techreborn.config.ConfigTechReborn;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
|
|
||||||
import java.util.HashMap;
|
public class TileGasTurbine extends TileBaseFluidGenerator {
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
|
|
||||||
|
|
||||||
// TODO: run this off config
|
|
||||||
public static final int euTick = 16;
|
|
||||||
public Tank tank = new Tank("TileGasTurbine", 1000 * 10, this);
|
|
||||||
public Inventory inventory = new Inventory(3, "TileGasTurbine", 64, this);
|
|
||||||
Map<String, Integer> fluids = new HashMap<>();
|
|
||||||
|
|
||||||
// We use this to keep track of fractional millibuckets, allowing us to hit
|
|
||||||
// our eu/bucket targets while still only ever removing integer millibucket
|
|
||||||
// amounts.
|
|
||||||
double pendingWithdraw = 0.0;
|
|
||||||
|
|
||||||
public TileGasTurbine() {
|
public TileGasTurbine() {
|
||||||
super(ConfigTechReborn.ThermalGeneratorTier);
|
super(EFluidGenerator.GAS, ConfigTechReborn.ThermalGeneratorTier, "TileGasTurbine", 1000*10, 16);
|
||||||
// TODO: fix this to have Gas Turbine generator values
|
|
||||||
|
|
||||||
fluids.put("fluidhydrogen", 15000);
|
|
||||||
fluids.put("fluidmethane", 45000);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumFacing getFacing() {
|
|
||||||
return getFacingEnum();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
|
||||||
return entityPlayer.isSneaking();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getWrenchDropRate() {
|
|
||||||
return 1.0F;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,127 +19,12 @@ public class TileGasTurbine extends TilePowerAcceptor implements IWrenchable, II
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
public EnumPowerTier getTier() {
|
||||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
return EnumPowerTier.MEDIUM;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.hasCapability(capability, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
|
||||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
|
||||||
return (T) tank;
|
|
||||||
}
|
|
||||||
return super.getCapability(capability, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
|
||||||
super.readFromNBT(tagCompound);
|
|
||||||
tank.readFromNBT(tagCompound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
|
||||||
super.writeToNBT(tagCompound);
|
|
||||||
tank.writeToNBT(tagCompound);
|
|
||||||
return tagCompound;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
|
|
||||||
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
|
|
||||||
getPos().getY(), getPos().getZ());
|
|
||||||
readFromNBT(packet.getNbtCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
super.updateEntity();
|
|
||||||
|
|
||||||
if (!this.world.isRemote) {
|
|
||||||
if (FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
|
|
||||||
this.syncWithAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.tank.getFluidAmount() > 0 && tryAddingEnergy(euTick)) {
|
|
||||||
final Integer euPerBucket = this.fluids.get(this.tank.getFluidType().getName());
|
|
||||||
// float totalTicks = (float)euPerBucket / 8f; //x eu per bucket / 8
|
|
||||||
// eu per tick
|
|
||||||
// float millibucketsPerTick = 1000f / totalTicks;
|
|
||||||
final float millibucketsPerTick = 16000f / (float) euPerBucket;
|
|
||||||
this.pendingWithdraw += millibucketsPerTick;
|
|
||||||
|
|
||||||
final int currentWithdraw = (int) this.pendingWithdraw; // float -->
|
|
||||||
// int
|
|
||||||
// conversion floors
|
|
||||||
// the float
|
|
||||||
this.pendingWithdraw -= currentWithdraw;
|
|
||||||
|
|
||||||
this.tank.drain(currentWithdraw, true);
|
|
||||||
|
|
||||||
if (!this.isActive())
|
|
||||||
this.world.setBlockState(this.getPos(),
|
|
||||||
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
|
|
||||||
} else if (this.isActive())
|
|
||||||
this.world.setBlockState(this.getPos(),
|
|
||||||
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
|
|
||||||
|
|
||||||
if (this.tank.getFluidType() != null && this.getStackInSlot(2) == ItemStack.EMPTY) {
|
|
||||||
this.inventory.setInventorySlotContents(2, new ItemStack(this.tank.getFluidType().getBlock()));
|
|
||||||
} else if (this.tank.getFluidType() == null && this.getStackInSlot(2) != ItemStack.EMPTY) {
|
|
||||||
this.setInventorySlotContents(2, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean tryAddingEnergy(int amount)
|
|
||||||
{
|
|
||||||
if(this.getMaxPower() - this.getEnergy() >= amount)
|
|
||||||
{
|
|
||||||
addEnergy(amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(this.getMaxPower() - this.getEnergy() > 0)
|
|
||||||
{
|
|
||||||
addEnergy(this.getMaxPower() - this.getEnergy());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getMaxPower() {
|
public double getMaxPower() {
|
||||||
return ConfigTechReborn.ThermalGeneratorCharge;
|
return ConfigTechReborn.ThermalGeneratorCharge;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canAcceptEnergy(EnumFacing direction) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canProvideEnergy(EnumFacing direction) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMaxOutput() {
|
|
||||||
return euTick;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMaxInput() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumPowerTier getTier() {
|
|
||||||
return EnumPowerTier.MEDIUM;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Inventory getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,198 +2,29 @@ package techreborn.tiles.generator;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.network.NetworkManager;
|
|
||||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|
||||||
import reborncore.api.power.EnumPowerTier;
|
import reborncore.api.power.EnumPowerTier;
|
||||||
import reborncore.api.tile.IInventoryProvider;
|
import techreborn.api.generator.EFluidGenerator;
|
||||||
import reborncore.common.IWrenchable;
|
|
||||||
import reborncore.common.blocks.BlockMachineBase;
|
|
||||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
|
||||||
import reborncore.common.util.FluidUtils;
|
|
||||||
import reborncore.common.util.Inventory;
|
|
||||||
import reborncore.common.util.Tank;
|
|
||||||
import techreborn.config.ConfigTechReborn;
|
import techreborn.config.ConfigTechReborn;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
|
|
||||||
import java.util.HashMap;
|
public class TileSemifluidGenerator extends TileBaseFluidGenerator {
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class TileSemifluidGenerator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
|
|
||||||
|
|
||||||
// TODO: run this off config
|
|
||||||
public static final int euTick = 8;
|
|
||||||
public Tank tank = new Tank("TileSemifluidGenerator", 1000 * 10, this);
|
|
||||||
public Inventory inventory = new Inventory(3, "TileSemifluidGenerator", 64, this);
|
|
||||||
Map<String, Integer> fluids = new HashMap<>();
|
|
||||||
|
|
||||||
// We use this to keep track of fractional millibuckets, allowing us to hit
|
|
||||||
// our eu/bucket targets while still only ever removing integer millibucket
|
|
||||||
// amounts.
|
|
||||||
double pendingWithdraw = 0.0;
|
|
||||||
|
|
||||||
public TileSemifluidGenerator() {
|
public TileSemifluidGenerator() {
|
||||||
super(ConfigTechReborn.ThermalGeneratorTier);
|
super(EFluidGenerator.SEMIFLUID, ConfigTechReborn.ThermalGeneratorTier, "TileSemifluidGenerator", 1000*10, 8);
|
||||||
// TODO: fix this to have SemiFluid generator values
|
|
||||||
|
|
||||||
fluids.put("creosote", 3000);
|
|
||||||
fluids.put("biomass", 8000);
|
|
||||||
fluids.put("fluidoil", 64000);
|
|
||||||
fluids.put("fluidsodium", 30000);
|
|
||||||
fluids.put("fluidlithium", 60000);
|
|
||||||
fluids.put("biofuel", 32000);
|
|
||||||
fluids.put("bioethanol", 32000);
|
|
||||||
fluids.put("fuel", 128000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
public ItemStack getWrenchDrop(EntityPlayer arg0) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumFacing getFacing() {
|
|
||||||
return getFacingEnum();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
|
||||||
return entityPlayer.isSneaking();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getWrenchDropRate() {
|
|
||||||
return 1.0F;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
|
||||||
return new ItemStack(ModBlocks.semiFluidGenerator, 1);
|
return new ItemStack(ModBlocks.semiFluidGenerator, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
|
||||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.hasCapability(capability, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
|
||||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
|
||||||
return (T) tank;
|
|
||||||
}
|
|
||||||
return super.getCapability(capability, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
|
||||||
super.readFromNBT(tagCompound);
|
|
||||||
tank.readFromNBT(tagCompound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
|
||||||
super.writeToNBT(tagCompound);
|
|
||||||
tank.writeToNBT(tagCompound);
|
|
||||||
return tagCompound;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
|
|
||||||
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
|
|
||||||
getPos().getY(), getPos().getZ());
|
|
||||||
readFromNBT(packet.getNbtCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
super.updateEntity();
|
|
||||||
if (!world.isRemote)
|
|
||||||
{
|
|
||||||
if(FluidUtils.drainContainers(tank, inventory, 0, 1))
|
|
||||||
this.syncWithAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tank.getFluidAmount() > 0 && tank.getFluidType() != null && fluids.containsKey(tank.getFluidType().getName()) && tryAddingEnergy(euTick)) {
|
|
||||||
Integer euPerBucket = fluids.get(tank.getFluidType().getName());
|
|
||||||
// float totalTicks = (float)euPerBucket / 8f; //x eu per bucket / 8
|
|
||||||
// eu per tick
|
|
||||||
// float millibucketsPerTick = 1000f / totalTicks;
|
|
||||||
float millibucketsPerTick = 8000f / (float) euPerBucket;
|
|
||||||
pendingWithdraw += millibucketsPerTick;
|
|
||||||
|
|
||||||
int currentWithdraw = (int) pendingWithdraw; // float --> int
|
|
||||||
// conversion floors
|
|
||||||
// the float
|
|
||||||
pendingWithdraw -= currentWithdraw;
|
|
||||||
|
|
||||||
tank.drain(currentWithdraw, true);
|
|
||||||
if(!this.isActive())
|
|
||||||
this.world.setBlockState(this.getPos(),
|
|
||||||
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
|
|
||||||
}
|
|
||||||
else if(this.isActive())
|
|
||||||
this.world.setBlockState(this.getPos(),
|
|
||||||
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
|
|
||||||
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) {
|
|
||||||
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
|
|
||||||
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {
|
|
||||||
setInventorySlotContents(2, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean tryAddingEnergy(int amount)
|
|
||||||
{
|
|
||||||
if(this.getMaxPower() - this.getEnergy() >= amount)
|
|
||||||
{
|
|
||||||
addEnergy(amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(this.getMaxPower() - this.getEnergy() > 0)
|
|
||||||
{
|
|
||||||
addEnergy(this.getMaxPower() - this.getEnergy());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMaxPower() {
|
|
||||||
return ConfigTechReborn.ThermalGeneratorCharge;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canAcceptEnergy(EnumFacing direction) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canProvideEnergy(EnumFacing direction) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMaxOutput() {
|
|
||||||
return euTick;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMaxInput() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumPowerTier getTier() {
|
public EnumPowerTier getTier() {
|
||||||
return EnumPowerTier.LOW;
|
return EnumPowerTier.LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Inventory getInventory() {
|
public double getMaxPower() {
|
||||||
return inventory;
|
return ConfigTechReborn.ThermalGeneratorCharge;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,52 +3,19 @@ package techreborn.tiles.generator;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.network.NetworkManager;
|
|
||||||
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
|
||||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
|
||||||
import reborncore.api.power.EnumPowerTier;
|
import reborncore.api.power.EnumPowerTier;
|
||||||
import reborncore.api.tile.IInventoryProvider;
|
|
||||||
import reborncore.common.IWrenchable;
|
|
||||||
import reborncore.common.blocks.BlockMachineBase;
|
|
||||||
import reborncore.common.powerSystem.TilePowerAcceptor;
|
|
||||||
import reborncore.common.util.FluidUtils;
|
import reborncore.common.util.FluidUtils;
|
||||||
import reborncore.common.util.Inventory;
|
import techreborn.api.generator.EFluidGenerator;
|
||||||
import reborncore.common.util.Tank;
|
|
||||||
import techreborn.config.ConfigTechReborn;
|
import techreborn.config.ConfigTechReborn;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
|
|
||||||
public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
|
public class TileThermalGenerator extends TileBaseFluidGenerator {
|
||||||
|
|
||||||
public static final int euTick = ConfigTechReborn.ThermalGeneratorOutput;
|
|
||||||
public Tank tank = new Tank("TileThermalGenerator", 1000 * 10, this);
|
|
||||||
public Inventory inventory = new Inventory(3, "TileThermalGenerator", 64, this);
|
|
||||||
|
|
||||||
public TileThermalGenerator() {
|
public TileThermalGenerator() {
|
||||||
super(ConfigTechReborn.ThermalGeneratorTier);
|
super(EFluidGenerator.THERMAL, ConfigTechReborn.ThermalGeneratorTier, "TileThermalGenerator", 1000 * 10,
|
||||||
}
|
ConfigTechReborn.ThermalGeneratorOutput);
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EnumFacing getFacing() {
|
|
||||||
return getFacingEnum();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
|
||||||
return entityPlayer.isSneaking();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getWrenchDropRate() {
|
|
||||||
return 1.0F;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,50 +24,11 @@ public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchab
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
|
||||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.hasCapability(capability, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
|
||||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
|
||||||
return (T) tank;
|
|
||||||
}
|
|
||||||
return super.getCapability(capability, facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFromNBT(NBTTagCompound tagCompound) {
|
|
||||||
super.readFromNBT(tagCompound);
|
|
||||||
tank.readFromNBT(tagCompound);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
|
||||||
super.writeToNBT(tagCompound);
|
|
||||||
tank.writeToNBT(tagCompound);
|
|
||||||
return tagCompound;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
|
|
||||||
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
|
|
||||||
getPos().getY(), getPos().getZ());
|
|
||||||
readFromNBT(packet.getNbtCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
private long lastOutput = 0;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
// TODO optimise this code
|
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
|
|
||||||
if (!this.world.isRemote) {
|
if (!this.world.isRemote) {
|
||||||
if (FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
|
if (acceptFluid() && FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
|
||||||
this.syncWithAll();
|
this.syncWithAll();
|
||||||
for (final EnumFacing direction : EnumFacing.values()) {
|
for (final EnumFacing direction : EnumFacing.values()) {
|
||||||
if (this.world
|
if (this.world
|
||||||
|
@ -108,49 +36,11 @@ public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchab
|
||||||
this.getPos().getY() + direction.getFrontOffsetY(),
|
this.getPos().getY() + direction.getFrontOffsetY(),
|
||||||
this.getPos().getZ() + direction.getFrontOffsetZ()))
|
this.getPos().getZ() + direction.getFrontOffsetZ()))
|
||||||
.getBlock() == Blocks.LAVA) {
|
.getBlock() == Blocks.LAVA) {
|
||||||
if(this.tryAddingEnergy(1))
|
if (this.tryAddingEnergy(1))
|
||||||
this.lastOutput = this.world.getTotalWorldTime();
|
this.lastOutput = this.world.getTotalWorldTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tank.getFluidAmount() > 0) {
|
|
||||||
if(tryAddingEnergy(euTick))
|
|
||||||
{
|
|
||||||
this.tank.drain(1, true);
|
|
||||||
this.lastOutput = this.world.getTotalWorldTime();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.world.isRemote) {
|
|
||||||
if (this.world.getTotalWorldTime() - this.lastOutput < 30 && !this.isActive())
|
|
||||||
this.world.setBlockState(this.getPos(),
|
|
||||||
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));
|
|
||||||
else if (this.world.getTotalWorldTime() - this.lastOutput > 30 && this.isActive())
|
|
||||||
this.world.setBlockState(this.getPos(),
|
|
||||||
this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.tank.getFluidType() != null && this.getStackInSlot(2) == ItemStack.EMPTY) {
|
|
||||||
this.inventory.setInventorySlotContents(2, new ItemStack(this.tank.getFluidType().getBlock()));
|
|
||||||
} else if (this.tank.getFluidType() == null && this.getStackInSlot(2) != ItemStack.EMPTY) {
|
|
||||||
this.inventory.setInventorySlotContents(2, ItemStack.EMPTY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean tryAddingEnergy(int amount)
|
|
||||||
{
|
|
||||||
if(this.getMaxPower() - this.getEnergy() >= amount)
|
|
||||||
{
|
|
||||||
addEnergy(amount);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(this.getMaxPower() - this.getEnergy() > 0)
|
|
||||||
{
|
|
||||||
addEnergy(this.getMaxPower() - this.getEnergy());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -158,33 +48,13 @@ public class TileThermalGenerator extends TilePowerAcceptor implements IWrenchab
|
||||||
return ConfigTechReborn.ThermalGeneratorCharge;
|
return ConfigTechReborn.ThermalGeneratorCharge;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canAcceptEnergy(EnumFacing direction) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canProvideEnergy(EnumFacing direction) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getMaxOutput() {
|
public double getMaxOutput() {
|
||||||
return 128;
|
return 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMaxInput() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumPowerTier getTier() {
|
public EnumPowerTier getTier() {
|
||||||
return EnumPowerTier.LOW;
|
return EnumPowerTier.LOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Inventory getInventory() {
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue