something something oil generator >_>

This commit is contained in:
Flanks255 2022-04-02 16:41:52 -05:00
parent ff27e16bc1
commit 538d77c831
8 changed files with 60 additions and 106 deletions

View file

@ -57,7 +57,6 @@ public final class ActuallyAdditionsAPI {
public static final List<IFarmerBehavior> FARMER_BEHAVIORS = new ArrayList<>();
public static final List<CoffeeIngredient> COFFEE_MACHINE_INGREDIENTS = new ArrayList<>();
// public static final List<CompostRecipe> COMPOST_RECIPES = new ArrayList<>();
public static final List<OilGenRecipe> OIL_GENERATOR_RECIPES = new ArrayList<>();
public static final List<IBookletEntry> BOOKLET_ENTRIES = new ArrayList<>();
//This is added to automatically, you don't need to add anything to this list
public static final List<IBookletChapter> ALL_CHAPTERS = new ArrayList<>();
@ -179,27 +178,6 @@ public final class ActuallyAdditionsAPI {
public static boolean addCrusherRecipes(List<ItemStack> inputs, ItemStack outputOne, int outputOneAmount, ItemStack outputTwo, int outputTwoAmount, int outputTwoChance) {
return methodHandler.addCrusherRecipes(inputs, outputOne, outputOneAmount, outputTwo, outputTwoAmount, outputTwoChance);
}
/**
* 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) {
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));
}
/**
* Adds a new conversion recipe to the compost.
*

View file

@ -1,31 +0,0 @@
/*
* 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-2017 Ellpeck
*/
package de.ellpeck.actuallyadditions.api.recipe;
public class OilGenRecipe {
public final String fluidName;
public final int genAmount;
public final int genTime;
/**
* Oil generator recipe
* @param fluidName The fluid
* @param genAmount The power generated, in CF/t
* @param genTime The length the fluid burns for, in seconds
*/
public OilGenRecipe(String fluidName, int genAmount, int genTime) {
this.fluidName = fluidName;
this.genAmount = genAmount;
this.genTime = genTime;
}
}

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.blocks.base.DirectionalBlock;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityCoalGenerator;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityOilGenerator;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
@ -28,6 +29,7 @@ import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.fml.network.NetworkHooks;
import javax.annotation.Nullable;
import java.util.Random;
public class BlockOilGenerator extends DirectionalBlock.Container {
@ -36,8 +38,14 @@ public class BlockOilGenerator extends DirectionalBlock.Container {
super(ActuallyBlocks.defaultPickProps(0).randomTicks());
}
//@Override
public TileEntity newBlockEntity(IBlockReader worldIn) {
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
@Nullable
@Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) {
return new TileEntityOilGenerator();
}
@ -65,7 +73,7 @@ public class BlockOilGenerator extends DirectionalBlock.Container {
}
}
return ActionResultType.PASS;
return ActionResultType.SUCCESS;
}
@Override

View file

@ -37,12 +37,14 @@ public class CommonConfig {
public static class Machines {
public static ForgeConfigSpec.IntValue FARMER_AREA;
public static ForgeConfigSpec.IntValue RECONSTRUCTOR_POWER;
public static ForgeConfigSpec.IntValue OIL_GENERATOR_TRANSFER;
public static void build() {
BUILDER.comment("Machine Settings").push("machineSettings");
FARMER_AREA = BUILDER.comment("The size of the farmer's farming area. Default is 9x9, must be an odd number.").defineInRange("farmerArea", 9, 1, Integer.MAX_VALUE);
RECONSTRUCTOR_POWER = BUILDER.comment("The amount of power the atomic reconstructor can store.").defineInRange("reconstructorPower", 300000, 300000, Integer.MAX_VALUE);
OIL_GENERATOR_TRANSFER = BUILDER.comment("The amount of power the oil generator can transfer per tick.").defineInRange("oilGeneratorTransfer", 500, 100, Integer.MAX_VALUE);
BUILDER.pop();
}

View file

@ -32,12 +32,6 @@ public final class InitCrafting {
// ActuallyAdditionsAPI.addCompostRecipe(Ingredient.fromStacks(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.MASHED_FOOD.ordinal())), Blocks.LEAVES.getDefaultState(), new ItemStack(InitItems.itemFertilizer), Blocks.DIRT.getDefaultState());
// ActuallyAdditionsAPI.addCompostRecipe(Ingredient.fromItems(InitItems.itemCanolaSeed), Blocks.DIRT.getDefaultState(), new ItemStack(InitItems.itemMisc, 1, TheMiscItems.BIOMASS.ordinal()), Blocks.SOUL_SAND.getDefaultState());
int[] power = ConfigIntListValues.OIL_POWER.getValue();
int[] time = ConfigIntListValues.OIL_TIME.getValue();
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.CANOLA_OIL.getName(), power[0], time[0]);
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.REFINED_CANOLA_OIL.getName(), power[1], time[1]);
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.CRYSTALLIZED_OIL.getName(), power[2], time[2]);
ActuallyAdditionsAPI.addOilGenRecipe(InitFluids.EMPOWERED_OIL.getName(), power[3], time[3]);
ActuallyAdditionsAPI.addFarmerBehavior(new DefaultFarmerBehavior());
ActuallyAdditionsAPI.addFarmerBehavior(new CactusFarmerBehavior());

View file

@ -28,6 +28,13 @@ public class LiquidFuelRecipe implements IRecipe<IInventory> {
private int totalEnergy;
private ResourceLocation id;
/**
* Oil generator recipe
* @param id ResourceLocation of the recipe
* @param fuel The fluid
* @param totalEnergy The total power generated.
* @param burnTime The length the fluid burns for, in ticks.
*/
public LiquidFuelRecipe(ResourceLocation id, FluidStack fuel, int totalEnergy, int burnTime) {
this.fuel = fuel;
this.burnTime = burnTime;
@ -52,6 +59,14 @@ public class LiquidFuelRecipe implements IRecipe<IInventory> {
return this.fuel.isFluidEqual(stack);
}
public int getFuelAmount() {
return this.fuel.getAmount();
}
public FluidStack getFuel() {
return fuel;
}
@Nonnull
@Override
public ItemStack assemble(@Nonnull IInventory pInv) {

View file

@ -45,8 +45,10 @@ public class GuiOilGenerator extends AAScreen<ContainerOilGenerator> {
@Override
public void init() {
super.init();
//this.energy = new EnergyDisplay(this.leftPos + 42, this.topPos + 5, this.generator.storage);
//this.fluid = new FluidDisplay(this.leftPos + 116, this.topPos + 5, this.generator.tank);
this.energy = new EnergyDisplay(this.leftPos + 42, this.topPos + 5, this.generator.storage);
this.fluid = new FluidDisplay(this.leftPos + 116, this.topPos + 5, this.generator.tank);
titleLabelX = (int) (imageWidth / 2.0f - font.width(title) / 2.0f);
titleLabelY = -10;
}
@Override
@ -56,11 +58,6 @@ public class GuiOilGenerator extends AAScreen<ContainerOilGenerator> {
this.fluid.render(matrices, x, y);
}
@Override
public void renderLabels(@Nonnull MatrixStack matrices, int x, int y) {
AssetUtil.displayNameString(matrices, this.font, this.imageWidth, -10, this.generator);
}
@Override
public void renderBg(MatrixStack matrices, float f, int x, int y) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
@ -77,12 +74,13 @@ public class GuiOilGenerator extends AAScreen<ContainerOilGenerator> {
}
if (this.generator.maxBurnTime > 0 && this.generator.currentEnergyProduce > 0) {
drawCenteredString(matrices, this.font, this.generator.currentEnergyProduce + " " + I18n.get("actuallyadditions.cft"), this.leftPos + 87, this.topPos + 65, 0xFFFFFF);
drawCenteredString(matrices, this.font, this.generator.currentEnergyProduce + " " + I18n.get("actuallyadditions.fet"), this.leftPos + 87, this.topPos + 65, 0xFFFFFF);
drawCenteredString(matrices, this.font, "for " + this.generator.maxBurnTime + " t", this.leftPos + 87, this.topPos + 75, 0xFFFFFF);
matrices.pushPose();
matrices.scale(0.75F, 0.75F, 1F);
float xS = (this.leftPos + 87) * 1.365F - this.font.width("(per 50 mB)") / 2F;
StringUtil.renderScaledAsciiString(this.font, "(per 50 mB)", xS, (this.topPos + 85) * 1.345F, 0xFFFFFF, true, 0.75F);
int usage = this.generator.fuelUsage;
float xS = (this.leftPos + 87) * 1.365F - this.font.width("(per " + usage + " mB)") / 2F;
StringUtil.renderScaledAsciiString(this.font, "(per " + usage + " mB)", xS, (this.topPos + 85) * 1.345F, 0xFFFFFF, true, 0.75F);
matrices.popPose();
}

View file

@ -11,14 +11,12 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.OilGenRecipe;
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues;
import de.ellpeck.actuallyadditions.mod.config.CommonConfig;
import de.ellpeck.actuallyadditions.mod.crafting.LiquidFuelRecipe;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerOilGenerator;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.fluid.Fluid;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.nbt.CompoundNBT;
@ -26,10 +24,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.energy.IEnergyStorage;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.templates.FluidTank;
@ -38,12 +38,9 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class TileEntityOilGenerator extends TileEntityBase implements ISharingEnergyProvider, ISharingFluidHandler, INamedContainerProvider {
int[] i = ConfigIntListValues.OIL_POWER.getValue();
public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 0, Math.max(Math.max(this.i[0], this.i[1]), Math.max(this.i[2], this.i[3])) + 20);
public final CustomEnergyStorage storage = new CustomEnergyStorage(50000, 0, CommonConfig.Machines.OIL_GENERATOR_TRANSFER.get());
public final LazyOptional<IEnergyStorage> lazyEnergy = LazyOptional.of(() -> this.storage);
public final FluidTank tank = new FluidTank(2 * Util.BUCKET) {
public final FluidTank tank = new FluidTank(2 * FluidAttributes.BUCKET_VOLUME, fluid -> getRecipeForFluid(fluid) != null) {
@Nonnull
@Override
public FluidStack drain(FluidStack resource, FluidAction action) {
@ -55,14 +52,6 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
public FluidStack drain(int maxDrain, FluidAction action) {
return FluidStack.EMPTY;
}
//@Override
public boolean canFillFluidType(FluidStack stack) {
Fluid fluid = stack == null
? null
: stack.getFluid();
return fluid != null && getRecipeForFluid(fluid.getRegistryName().toString()) != null;
}
};
public final LazyOptional<IFluidHandler> lazyTank = LazyOptional.of(() -> this.tank);
public int currentEnergyProduce;
@ -74,15 +63,16 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
private int lastMaxBurnTime;
private int lastEnergyProduce;
private int lastCompare;
public int fuelUsage;
public TileEntityOilGenerator() {
super(ActuallyBlocks.OIL_GENERATOR.getTileEntityType());
}
private static OilGenRecipe getRecipeForFluid(String fluidName) {
if (fluidName != null) {
for (OilGenRecipe recipe : ActuallyAdditionsAPI.OIL_GENERATOR_RECIPES) {
if (recipe != null && fluidName.equals(recipe.fluidName)) {
private static LiquidFuelRecipe getRecipeForFluid(FluidStack fluid) {
if (fluid != null) {
for (LiquidFuelRecipe recipe : ActuallyAdditionsAPI.LIQUID_FUEL_RECIPES) {
if (recipe != null && recipe.matches(fluid)) {
return recipe;
}
}
@ -95,13 +85,10 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
return this.currentBurnTime * i / this.maxBurnTime;
}
private OilGenRecipe getRecipeForCurrentFluid() {
private LiquidFuelRecipe getRecipeForCurrentFluid() {
FluidStack stack = this.tank.getFluid();
if (stack != null) {
Fluid fluid = stack.getFluid();
if (fluid != null) {
return getRecipeForFluid(fluid.getRegistryName().toString());
}
if (!stack.isEmpty()) {
return getRecipeForFluid(stack);
}
return null;
}
@ -112,6 +99,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
compound.putInt("BurnTime", this.currentBurnTime);
compound.putInt("CurrentEnergy", this.currentEnergyProduce);
compound.putInt("MaxBurnTime", this.maxBurnTime);
compound.putInt("FuelUsage", this.fuelUsage);
}
this.storage.writeToNBT(compound);
this.tank.writeToNBT(compound);
@ -124,6 +112,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
this.currentBurnTime = compound.getInt("BurnTime");
this.currentEnergyProduce = compound.getInt("CurrentEnergy");
this.maxBurnTime = compound.getInt("MaxBurnTime");
this.fuelUsage = compound.getInt("FuelUsage");
}
this.storage.readFromNBT(compound);
this.tank.readFromNBT(compound);
@ -141,19 +130,20 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
this.storage.receiveEnergyInternal(this.currentEnergyProduce, false);
} else if (!this.isRedstonePowered) {
int fuelUsed = 50;
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;
LiquidFuelRecipe recipe = this.getRecipeForCurrentFluid();
if (recipe != null && this.storage.getEnergyStored() < this.storage.getMaxEnergyStored() && this.tank.getFluidAmount() >= recipe.getFuelAmount()) {
fuelUsage = recipe.getFuelAmount();
this.currentEnergyProduce = recipe.getTotalEnergy() / recipe.getBurnTime();
this.maxBurnTime = recipe.getBurnTime();
this.currentBurnTime = this.maxBurnTime;
this.tank.drain(fuelUsed, IFluidHandler.FluidAction.EXECUTE);
this.tank.getFluid().shrink(fuelUsage);
} else {
this.currentEnergyProduce = 0;
this.currentBurnTime = 0;
this.maxBurnTime = 0;
this.fuelUsage = 0;
}
}
@ -226,7 +216,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn
@Override
public ITextComponent getDisplayName() {
return StringTextComponent.EMPTY;
return new TranslationTextComponent("container.actuallyadditions.oilGenerator");
}
@Nullable