From dd7e522605d96a1e195d8607cad6a0b2519b58c9 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 21 Nov 2016 13:30:38 +0100 Subject: [PATCH] Made the Oil Generator scale per time, not per energy --- .../api/ActuallyAdditionsAPI.java | 16 ++++- .../api/recipe/OilGenRecipe.java | 27 ++++++++ .../mod/crafting/InitCrafting.java | 8 +-- .../mod/inventory/gui/GuiOilGenerator.java | 7 +- .../mod/tile/TileEntityOilGenerator.java | 64 +++++++++++++------ 5 files changed, 91 insertions(+), 31 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/api/recipe/OilGenRecipe.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index ffa8a6c5a..a74ca330b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -31,7 +31,7 @@ public final class ActuallyAdditionsAPI{ public static final String MOD_ID = "actuallyadditions"; public static final String API_ID = MOD_ID+"api"; - public static final String API_VERSION = "29"; + public static final String API_VERSION = "30"; public static final List CRUSHER_RECIPES = new ArrayList(); public static final List BALL_OF_FUR_RETURN_ITEMS = new ArrayList(); @@ -41,7 +41,7 @@ public final class ActuallyAdditionsAPI{ public static final Map RECONSTRUCTOR_LENS_COLOR_CHANGERS = new HashMap(); public static final List COFFEE_MACHINE_INGREDIENTS = new ArrayList(); public static final List COMPOST_RECIPES = new ArrayList(); - public static final Map OIL_GENERATOR_RECIPES = new HashMap(); + public static final List OIL_GENERATOR_RECIPES = new ArrayList(); public static final List BOOKLET_ENTRIES = new ArrayList(); //This is added to automatically, you don't need to add anything to this list public static final List ALL_CHAPTERS = new ArrayList(); @@ -148,7 +148,17 @@ public final class ActuallyAdditionsAPI{ * @param genAmount The amount of energy generated per operation */ public static void addOilGenRecipe(String fluidName, int genAmount){ - OIL_GENERATOR_RECIPES.put(fluidName, genAmount); + addOilGenRecipe(fluidName, genAmount, 100); + } + + /** + * Adds a Recipe to the Oil generator + * + * @param fluidName The name of the fluid to be consumed + * @param genAmount The amount of energy generated per operation + */ + public static void addOilGenRecipe(String fluidName, int genAmount, int genTime){ + OIL_GENERATOR_RECIPES.add(new OilGenRecipe(fluidName, genAmount, genTime)); } /** diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/OilGenRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/OilGenRecipe.java new file mode 100644 index 000000000..137e99537 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/OilGenRecipe.java @@ -0,0 +1,27 @@ +/* + * This file ("OilGenRecipe.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.api.recipe; + +import net.minecraftforge.fluids.FluidStack; + +public class OilGenRecipe{ + + public final String fluidName; + public final int genAmount; + public final int genTime; + + public OilGenRecipe(String fluidName, int genAmount, int genTime){ + this.fluidName = fluidName; + this.genAmount = genAmount; + this.genTime = genTime; + } + +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java index 7e15d8f79..73e8f526c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/InitCrafting.java @@ -33,10 +33,10 @@ public final class InitCrafting{ ActuallyAdditionsAPI.addCompostRecipe(new ItemStack(InitItems.itemMisc, 10, TheMiscItems.MASHED_FOOD.ordinal()), Blocks.LEAVES, new ItemStack(InitItems.itemFertilizer, 10), Blocks.DIRT); ActuallyAdditionsAPI.addCompostRecipe(new ItemStack(InitItems.itemCanolaSeed, 20), Blocks.DIRT, new ItemStack(InitItems.itemMisc, 1, TheMiscItems.BIOMASS.ordinal()), Blocks.SOUL_SAND); - ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCanolaOil.getName(), 40); - ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidOil.getName(), 100); - ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCrystalOil.getName(), 200); - ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidEmpoweredOil.getName(), 350); + ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCanolaOil.getName(), 40, 100); + ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidOil.getName(), 60, 100); + ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidCrystalOil.getName(), 80, 200); + ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.fluidEmpoweredOil.getName(), 80, 350); RecipeSorter.register(ModUtil.MOD_ID+":recipeKeepDataShaped", RecipeKeepDataShaped.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped"); RecipeSorter.register(ModUtil.MOD_ID+":recipeKeepDataShapeless", RecipeKeepDataShapeless.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiOilGenerator.java index 25be3c131..d454d9976 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiOilGenerator.java @@ -75,13 +75,14 @@ public class GuiOilGenerator extends GuiContainer{ this.mc.getTextureManager().bindTexture(RES_LOC); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93); - if(this.generator.currentBurnTime > 0){ + if(this.generator.currentBurnTime > 0 && this.generator.maxBurnTime > 0){ int i = this.generator.getBurningScaled(13); this.drawTexturedModalRect(this.guiLeft+72, this.guiTop+44+12-i, 176, 96-i, 14, i); } - if(this.generator.currentEnergyProduce > 0){ - this.drawCenteredString(this.fontRendererObj, this.generator.currentEnergyProduce+" RF/t", this.guiLeft+87, this.guiTop+75, 0xFFFFFF); + if(this.generator.maxBurnTime > 0 && this.generator.currentEnergyProduce > 0){ + this.drawCenteredString(this.fontRendererObj, this.generator.currentEnergyProduce+" RF/t", this.guiLeft+87, this.guiTop+65, 0xFFFFFF); + this.drawCenteredString(this.fontRendererObj, "for "+this.generator.maxBurnTime+" t", this.guiLeft+87, this.guiTop+75, 0xFFFFFF); } this.energy.draw(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java index d83964527..afd7e7cfd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java @@ -12,18 +12,19 @@ package de.ellpeck.actuallyadditions.mod.tile; import cofh.api.energy.EnergyStorage; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; +import de.ellpeck.actuallyadditions.api.recipe.OilGenRecipe; import de.ellpeck.actuallyadditions.mod.util.Util; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; -import net.minecraftforge.fluids.*; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.fluids.capability.IFluidTankProperties; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class TileEntityOilGenerator extends TileEntityBase implements ISharingEnergyProvider, ISharingFluidHandler{ - private static final int BURN_TIME = 100; public final EnergyStorage storage = new EnergyStorage(50000); public final FluidTank tank = new FluidTank(2*Util.BUCKET){ @Override @@ -34,14 +35,16 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn @Override public boolean canFillFluidType(FluidStack stack){ Fluid fluid = stack.getFluid(); - return fluid != null && ActuallyAdditionsAPI.OIL_GENERATOR_RECIPES.containsKey(fluid.getName()); + return fluid != null && getRecipeForFluid(fluid.getName()) != null; } }; public int currentEnergyProduce; public int currentBurnTime; + public int maxBurnTime; private int lastEnergy; private int lastTank; private int lastBurnTime; + private int lastMaxBurnTime; private int lastEnergyProduce; public TileEntityOilGenerator(){ @@ -50,7 +53,29 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn @SideOnly(Side.CLIENT) public int getBurningScaled(int i){ - return this.currentBurnTime*i/BURN_TIME; + return this.currentBurnTime*i/this.maxBurnTime; + } + + private OilGenRecipe getRecipeForCurrentFluid(){ + FluidStack stack = this.tank.getFluid(); + if(stack != null){ + Fluid fluid = stack.getFluid(); + if(fluid != null){ + return getRecipeForFluid(fluid.getName()); + } + } + return null; + } + + private static OilGenRecipe getRecipeForFluid(String fluidName){ + if(fluidName != null){ + for(OilGenRecipe recipe : ActuallyAdditionsAPI.OIL_GENERATOR_RECIPES){ + if(recipe != null && fluidName.equals(recipe.fluidName)){ + return recipe; + } + } + } + return null; } @Override @@ -58,6 +83,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn if(type != NBTType.SAVE_BLOCK){ compound.setInteger("BurnTime", this.currentBurnTime); compound.setInteger("CurrentEnergy", this.currentEnergyProduce); + compound.setInteger("MaxBurnTime", this.maxBurnTime); } this.storage.writeToNBT(compound); this.tank.writeToNBT(compound); @@ -69,6 +95,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn if(type != NBTType.SAVE_BLOCK){ this.currentBurnTime = compound.getInteger("BurnTime"); this.currentEnergyProduce = compound.getInteger("CurrentEnergy"); + this.maxBurnTime = compound.getInteger("MaxBurnTime"); } this.storage.readFromNBT(compound); this.tank.readFromNBT(compound); @@ -86,15 +113,20 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn this.storage.receiveEnergy(this.currentEnergyProduce, false); } else{ - this.currentEnergyProduce = this.getEnergyForCurrentFluid(); - int fuelUsed = 50; - if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored() && this.tank.getFluidAmount() >= fuelUsed){ - this.currentBurnTime = BURN_TIME; + + OilGenRecipe recipe = this.getRecipeForCurrentFluid(); + if(recipe != null && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored() && this.tank.getFluidAmount() >= fuelUsed){ + this.currentEnergyProduce = recipe.genAmount; + this.maxBurnTime = recipe.genTime; + this.currentBurnTime = this.maxBurnTime; + this.tank.drainInternal(fuelUsed, true); } else{ + this.currentEnergyProduce = 0; this.currentBurnTime = 0; + this.maxBurnTime = 0; } } @@ -102,26 +134,16 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn this.markDirty(); } - if((this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.lastBurnTime != this.currentBurnTime || this.lastEnergyProduce != this.currentEnergyProduce) && this.sendUpdateWithInterval()){ + if((this.storage.getEnergyStored() != this.lastEnergy || this.tank.getFluidAmount() != this.lastTank || this.lastBurnTime != this.currentBurnTime || this.lastEnergyProduce != this.currentEnergyProduce || this.lastMaxBurnTime != this.maxBurnTime) && this.sendUpdateWithInterval()){ this.lastEnergy = this.storage.getEnergyStored(); this.lastTank = this.tank.getFluidAmount(); this.lastBurnTime = this.currentBurnTime; this.lastEnergyProduce = this.currentEnergyProduce; + this.lastMaxBurnTime = this.maxBurnTime; } } } - private int getEnergyForCurrentFluid(){ - FluidStack stack = this.tank.getFluid(); - if(stack != null){ - Fluid fluid = stack.getFluid(); - if(fluid != null){ - return ActuallyAdditionsAPI.OIL_GENERATOR_RECIPES.get(fluid.getName()); - } - } - return 0; - } - @Override public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate){ return this.storage.extractEnergy(maxExtract, simulate);