mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Fermenting Barrel should be done for now.
This commit is contained in:
parent
b6e4b5a8b3
commit
87bc236287
2 changed files with 138 additions and 55 deletions
|
@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.blocks.base.BlockFluidFlowing;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.item.Rarity;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
@ -24,10 +25,10 @@ import java.util.Locale;
|
|||
public final class InitFluids {
|
||||
public static final DeferredRegister<Fluid> FLUIDS = DeferredRegister.create(ForgeRegistries.FLUIDS, ActuallyAdditions.MODID);
|
||||
|
||||
public static final RegistryObject<Fluid> fluidCanolaOil = FLUIDS.register("canolaoil", () -> registerFluid("block_canola_oil"));
|
||||
public static final RegistryObject<Fluid> fluidRefinedCanolaOil = FLUIDS.register("refinedcanolaoil", () -> registerFluid("block_refined_canola_oil"));
|
||||
public static final RegistryObject<Fluid> fluidCrystalOil = FLUIDS.register("crystaloil", () -> registerFluid("block_crystal_oil"));
|
||||
public static final RegistryObject<Fluid> fluidEmpoweredOil = FLUIDS.register("empoweredoil", () -> registerFluid("block_empowered_oil"));
|
||||
public static final RegistryObject<Fluid> fluidCanolaOil = FLUIDS.register("canolaoil", () -> registerFluid("canolaoil","block_canola_oil"));
|
||||
public static final RegistryObject<Fluid> fluidRefinedCanolaOil = FLUIDS.register("refinedcanolaoil", () -> registerFluid("refinedcanolaoil","block_refined_canola_oil"));
|
||||
public static final RegistryObject<Fluid> fluidCrystalOil = FLUIDS.register("crystaloil", () -> registerFluid("crystaloil","block_crystal_oil"));
|
||||
public static final RegistryObject<Fluid> fluidEmpoweredOil = FLUIDS.register("empoweredoil", () -> registerFluid("empoweredoil","block_empowered_oil"));
|
||||
|
||||
public static Block blockCanolaOil;
|
||||
public static Block blockRefinedCanolaOil;
|
||||
|
@ -35,15 +36,15 @@ public final class InitFluids {
|
|||
public static Block blockEmpoweredOil;
|
||||
|
||||
public static void init() {
|
||||
fluidCanolaOil = registerFluid("canolaoil", "block_canola_oil", EnumRarity.UNCOMMON);
|
||||
fluidRefinedCanolaOil = registerFluid("refinedcanolaoil", "block_refined_canola_oil", EnumRarity.UNCOMMON);
|
||||
fluidCrystalOil = registerFluid("crystaloil", "block_crystal_oil", EnumRarity.RARE);
|
||||
fluidEmpoweredOil = registerFluid("empoweredoil", "block_empowered_oil", EnumRarity.EPIC);
|
||||
//fluidCanolaOil = registerFluid("canolaoil", "block_canola_oil", Rarity.COMMON);
|
||||
//fluidRefinedCanolaOil = registerFluid("refinedcanolaoil", "block_refined_canola_oil", Rarity.UNCOMMON);
|
||||
//fluidCrystalOil = registerFluid("crystaloil", "block_crystal_oil", Rarity.RARE);
|
||||
//fluidEmpoweredOil = registerFluid("empoweredoil", "block_empowered_oil", Rarity.EPIC);
|
||||
|
||||
blockCanolaOil = registerFluidBlock(fluidCanolaOil, Material.WATER, "block_canola_oil");
|
||||
blockRefinedCanolaOil = registerFluidBlock(fluidRefinedCanolaOil, Material.WATER, "block_refined_canola_oil");
|
||||
blockCrystalOil = registerFluidBlock(fluidCrystalOil, Material.WATER, "block_crystal_oil");
|
||||
blockEmpoweredOil = registerFluidBlock(fluidEmpoweredOil, Material.WATER, "block_empowered_oil");
|
||||
blockCanolaOil = registerFluidBlock(fluidCanolaOil.get(), Material.WATER, "block_canola_oil");
|
||||
blockRefinedCanolaOil = registerFluidBlock(fluidRefinedCanolaOil.get(), Material.WATER, "block_refined_canola_oil");
|
||||
blockCrystalOil = registerFluidBlock(fluidCrystalOil.get(), Material.WATER, "block_crystal_oil");
|
||||
blockEmpoweredOil = registerFluidBlock(fluidEmpoweredOil.get(), Material.WATER, "block_empowered_oil");
|
||||
}
|
||||
|
||||
private static Fluid registerFluid(String fluidName, String fluidTextureName) {
|
||||
|
@ -55,6 +56,6 @@ public final class InitFluids {
|
|||
}
|
||||
|
||||
private static Block registerFluidBlock(Fluid fluid, Material material, String name) {
|
||||
return new BlockFluidFlowing(fluid, material, name);
|
||||
return new BlockFluidFlowing(fluid, material, name); //TODO ohhhh boy, all this fluid stuff needs to be redone.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.tile;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
||||
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFermentingBarrel;
|
||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||
|
@ -23,10 +24,13 @@ import net.minecraft.util.text.ITextComponent;
|
|||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
import net.minecraftforge.fluids.FluidAttributes;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.templates.FluidTank;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType;
|
||||
|
@ -34,24 +38,9 @@ import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase.NBTType;
|
|||
public class TileEntityFermentingBarrel extends TileEntityBase implements ISharingFluidHandler, INamedContainerProvider {
|
||||
|
||||
private static final int PROCESS_TIME = 100;
|
||||
public final FluidTank canolaTank = new FluidTank(2 * Util.BUCKET) {
|
||||
@Override
|
||||
public boolean canDrain() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFillFluidType(FluidStack fluid) {
|
||||
return fluid.getFluid() == InitFluids.fluidCanolaOil;
|
||||
}
|
||||
};
|
||||
public final FluidTank oilTank = new FluidTank(2 * Util.BUCKET) {
|
||||
@Override
|
||||
public boolean canFill() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
private final FluidHandlerFluidMap handlerMap;
|
||||
public final FermentingBarrelMultiTank tanks = new FermentingBarrelMultiTank();
|
||||
public final LazyOptional<IFluidHandler> fluidOptional = LazyOptional.of(()->tanks);
|
||||
|
||||
public int currentProcessTime;
|
||||
private int lastCanola;
|
||||
|
@ -60,30 +49,21 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
|||
private int lastCompare;
|
||||
|
||||
public TileEntityFermentingBarrel() {
|
||||
super(ActuallyTiles.FERMENTINGBARREL_TILE.get());
|
||||
|
||||
this.handlerMap = new FluidHandlerFluidMap();
|
||||
this.handlerMap.addHandler(InitFluids.fluidCanolaOil, this.canolaTank);
|
||||
this.handlerMap.addHandler(InitFluids.fluidRefinedCanolaOil, this.oilTank);
|
||||
super(ActuallyBlocks.FERMENTING_BARREL.getTileEntityType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
|
||||
compound.putInt("ProcessTime", this.currentProcessTime);
|
||||
this.canolaTank.writeToNBT(compound);
|
||||
CompoundNBT tag = new CompoundNBT();
|
||||
this.oilTank.writeToNBT(tag);
|
||||
compound.setTag("OilTank", tag);
|
||||
compound.put("tanks", tanks.writeNBT());
|
||||
super.writeSyncableNBT(compound, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSyncableNBT(CompoundNBT compound, NBTType type) {
|
||||
this.currentProcessTime = compound.getInt("ProcessTime");
|
||||
this.canolaTank.readFromNBT(compound);
|
||||
CompoundNBT tag = compound.getCompoundTag("OilTank");
|
||||
if (tag != null) {
|
||||
this.oilTank.readFromNBT(tag);
|
||||
if (compound.contains("tanks")) {
|
||||
//TODO read
|
||||
}
|
||||
super.readSyncableNBT(compound, type);
|
||||
}
|
||||
|
@ -93,13 +73,13 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
|||
super.updateEntity();
|
||||
if (!this.level.isClientSide) {
|
||||
int produce = 80;
|
||||
if (this.canolaTank.getFluidAmount() >= produce && produce <= this.oilTank.getCapacity() - this.oilTank.getFluidAmount()) {
|
||||
if (this.tanks.getFluidInTank(0).getAmount() >= produce && produce <= this.tanks.getTankCapacity(1) - this.tanks.getFluidInTank(1).getAmount()) {
|
||||
this.currentProcessTime++;
|
||||
if (this.currentProcessTime >= PROCESS_TIME) {
|
||||
this.currentProcessTime = 0;
|
||||
|
||||
this.oilTank.fillInternal(new FluidStack(InitFluids.fluidRefinedCanolaOil, produce), true);
|
||||
this.canolaTank.drainInternal(produce, true);
|
||||
this.tanks.oilTank.grow(produce);
|
||||
this.tanks.canolaTank.shrink(produce);
|
||||
}
|
||||
} else {
|
||||
this.currentProcessTime = 0;
|
||||
|
@ -112,17 +92,17 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
|||
this.setChanged();
|
||||
}
|
||||
|
||||
if ((this.canolaTank.getFluidAmount() != this.lastCanola || this.oilTank.getFluidAmount() != this.lastOil || this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()) {
|
||||
if ((this.tanks.getFluidInTank(0).getAmount() != this.lastCanola || this.tanks.getFluidInTank(1).getAmount() != this.lastOil || this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()) {
|
||||
this.lastProcessTime = this.currentProcessTime;
|
||||
this.lastCanola = this.canolaTank.getFluidAmount();
|
||||
this.lastOil = this.oilTank.getFluidAmount();
|
||||
this.lastCanola = this.tanks.getFluidInTank(0).getAmount();
|
||||
this.lastOil = this.tanks.getFluidInTank(1).getAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getComparatorStrength() {
|
||||
float calc = (float) this.oilTank.getFluidAmount() / (float) this.oilTank.getCapacity() * 15F;
|
||||
float calc = (float) this.tanks.getFluidInTank(1).getAmount() / (float) this.tanks.getTankCapacity(1) * 15F;
|
||||
return (int) calc;
|
||||
}
|
||||
|
||||
|
@ -133,22 +113,22 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
|||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public int getOilTankScaled(int i) {
|
||||
return this.oilTank.getFluidAmount() * i / this.oilTank.getCapacity();
|
||||
return this.tanks.getFluidInTank(1).getAmount() * i / this.tanks.getTankCapacity(1);
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public int getCanolaTankScaled(int i) {
|
||||
return this.canolaTank.getFluidAmount() * i / this.canolaTank.getCapacity();
|
||||
return this.tanks.getFluidInTank(0).getAmount() * i / this.tanks.getTankCapacity(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFluidHandler getFluidHandler(Direction facing) {
|
||||
return this.handlerMap;
|
||||
public LazyOptional<IFluidHandler> getFluidHandler(Direction facing) {
|
||||
return fluidOptional;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxFluidAmountToSplitShare() {
|
||||
return this.oilTank.getFluidAmount();
|
||||
return tanks.getFluidInTank(1).getAmount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -171,4 +151,106 @@ public class TileEntityFermentingBarrel extends TileEntityBase implements IShari
|
|||
public Container createMenu(int windowId, PlayerInventory playerInventory, PlayerEntity p_createMenu_3_) {
|
||||
return new ContainerFermentingBarrel(windowId, playerInventory, this);
|
||||
}
|
||||
|
||||
|
||||
public class FermentingBarrelMultiTank implements IFluidHandler {
|
||||
|
||||
public FluidStack canolaTank = new FluidStack(InitFluids.fluidCanolaOil.get(), 0);
|
||||
public FluidStack oilTank = new FluidStack(InitFluids.fluidRefinedCanolaOil.get(), 0);
|
||||
private int capacity = FluidAttributes.BUCKET_VOLUME * 2;
|
||||
|
||||
@Override
|
||||
public int getTanks() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack getFluidInTank(int tank) {
|
||||
return tank == 0? canolaTank:oilTank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTankCapacity(int tank) {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluidValid(int tank, @Nonnull FluidStack stack) {
|
||||
return tank == 0? stack.getFluid() == InitFluids.fluidCanolaOil.get():stack.getFluid() == InitFluids.fluidRefinedCanolaOil.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
if (resource.isEmpty() || resource.getFluid() != InitFluids.fluidCanolaOil.get())
|
||||
return 0;
|
||||
|
||||
if(action.simulate())
|
||||
{
|
||||
if (canolaTank.isEmpty())
|
||||
return Math.min(capacity, resource.getAmount());
|
||||
else
|
||||
return Math.min(capacity - canolaTank.getAmount(), resource.getAmount());
|
||||
}
|
||||
else {
|
||||
if (canolaTank.isEmpty()) {
|
||||
canolaTank = new FluidStack(resource, Math.min(capacity, resource.getAmount()));
|
||||
//TODO need to set the BE dirty.
|
||||
return canolaTank.getAmount();
|
||||
}
|
||||
else {
|
||||
int filledAmt = capacity - canolaTank.getAmount();
|
||||
if (resource.getAmount() < filledAmt) {
|
||||
canolaTank.grow(resource.getAmount());
|
||||
filledAmt = resource.getAmount();
|
||||
}
|
||||
else
|
||||
canolaTank.setAmount(capacity);
|
||||
|
||||
if (filledAmt > 0){
|
||||
//TODO set BE dirty
|
||||
}
|
||||
return filledAmt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CompoundNBT writeNBT() {
|
||||
CompoundNBT canolaNBT = new CompoundNBT();
|
||||
canolaTank.writeToNBT(canolaNBT);
|
||||
CompoundNBT oilNBT = new CompoundNBT();
|
||||
oilTank.writeToNBT(oilNBT);
|
||||
|
||||
CompoundNBT nbt = new CompoundNBT();
|
||||
nbt.put("canolaTank", canolaNBT);
|
||||
nbt.put("oilTank", oilNBT);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack drain(FluidStack resource, FluidAction action) {
|
||||
if (resource.isEmpty() || resource.getFluid() != InitFluids.fluidRefinedCanolaOil.get())
|
||||
return FluidStack.EMPTY;
|
||||
|
||||
return drain(resource.getAmount(), action);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public FluidStack drain(int maxDrain, FluidAction action) {
|
||||
int drained = maxDrain;
|
||||
if (oilTank.getAmount() < drained)
|
||||
{
|
||||
drained = oilTank.getAmount();
|
||||
}
|
||||
FluidStack stack = new FluidStack(oilTank, drained);
|
||||
if (action.execute() && drained > 0)
|
||||
{
|
||||
oilTank.shrink(drained);
|
||||
//TODO set BE dirty
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue