2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TileEntityFermentingBarrel.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-29 17:38:31 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
2016-05-06 23:23:29 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.util.Direction;
|
2016-11-26 21:32:27 +01:00
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTank;
|
2016-06-05 02:16:52 +02:00
|
|
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
|
|
|
import net.minecraftforge.fluids.capability.templates.FluidHandlerFluidMap;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.OnlyIn;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class TileEntityFermentingBarrel extends TileEntityBase implements ISharingFluidHandler {
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
private static final int PROCESS_TIME = 100;
|
2019-05-02 09:10:29 +02:00
|
|
|
public final FluidTank canolaTank = new FluidTank(2 * Util.BUCKET) {
|
2016-06-05 02:16:52 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canDrain() {
|
2016-06-05 02:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canFillFluidType(FluidStack fluid) {
|
2016-06-05 02:16:52 +02:00
|
|
|
return fluid.getFluid() == InitFluids.fluidCanolaOil;
|
|
|
|
}
|
|
|
|
};
|
2019-05-02 09:10:29 +02:00
|
|
|
public final FluidTank oilTank = new FluidTank(2 * Util.BUCKET) {
|
2016-06-05 02:16:52 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean canFill() {
|
2016-06-05 02:16:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2016-12-05 14:16:53 +01:00
|
|
|
private final FluidHandlerFluidMap handlerMap;
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
public int currentProcessTime;
|
2015-10-03 10:16:18 +02:00
|
|
|
private int lastCanola;
|
|
|
|
private int lastOil;
|
2015-07-02 04:21:21 +02:00
|
|
|
private int lastProcessTime;
|
2016-11-28 13:11:29 +01:00
|
|
|
private int lastCompare;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public TileEntityFermentingBarrel() {
|
2016-05-06 23:23:29 +02:00
|
|
|
super("fermentingBarrel");
|
2016-12-05 14:16:53 +01:00
|
|
|
|
|
|
|
this.handlerMap = new FluidHandlerFluidMap();
|
|
|
|
this.handlerMap.addHandler(InitFluids.fluidCanolaOil, this.canolaTank);
|
2017-07-12 20:19:48 +02:00
|
|
|
this.handlerMap.addHandler(InitFluids.fluidRefinedCanolaOil, this.oilTank);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public void writeSyncableNBT(CompoundNBT compound, NBTType type) {
|
2016-02-01 17:49:55 +01:00
|
|
|
compound.setInteger("ProcessTime", this.currentProcessTime);
|
|
|
|
this.canolaTank.writeToNBT(compound);
|
2021-02-26 22:15:48 +01:00
|
|
|
CompoundNBT tag = new CompoundNBT();
|
2016-02-01 17:49:55 +01:00
|
|
|
this.oilTank.writeToNBT(tag);
|
|
|
|
compound.setTag("OilTank", tag);
|
2016-07-02 15:01:46 +02:00
|
|
|
super.writeSyncableNBT(compound, type);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-26 22:15:48 +01:00
|
|
|
public void readSyncableNBT(CompoundNBT compound, NBTType type) {
|
2016-02-01 17:49:55 +01:00
|
|
|
this.currentProcessTime = compound.getInteger("ProcessTime");
|
|
|
|
this.canolaTank.readFromNBT(compound);
|
2021-02-26 22:15:48 +01:00
|
|
|
CompoundNBT tag = compound.getCompoundTag("OilTank");
|
2019-05-02 09:10:29 +02:00
|
|
|
if (tag != null) {
|
2016-12-03 12:31:17 +01:00
|
|
|
this.oilTank.readFromNBT(tag);
|
|
|
|
}
|
2016-07-02 15:01:46 +02:00
|
|
|
super.readSyncableNBT(compound, type);
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void updateEntity() {
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!this.world.isRemote) {
|
2015-12-22 17:54:55 +01:00
|
|
|
int produce = 80;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.canolaTank.getFluidAmount() >= produce && produce <= this.oilTank.getCapacity() - this.oilTank.getFluidAmount()) {
|
2015-05-20 22:39:43 +02:00
|
|
|
this.currentProcessTime++;
|
2019-05-02 09:10:29 +02:00
|
|
|
if (this.currentProcessTime >= PROCESS_TIME) {
|
2015-05-20 22:39:43 +02:00
|
|
|
this.currentProcessTime = 0;
|
|
|
|
|
2017-07-12 20:19:48 +02:00
|
|
|
this.oilTank.fillInternal(new FluidStack(InitFluids.fluidRefinedCanolaOil, produce), true);
|
2016-06-05 02:16:52 +02:00
|
|
|
this.canolaTank.drainInternal(produce, true);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2015-10-02 16:48:01 +02:00
|
|
|
this.currentProcessTime = 0;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-11-28 13:11:29 +01:00
|
|
|
int compare = this.getComparatorStrength();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (compare != this.lastCompare) {
|
2016-11-28 13:11:29 +01:00
|
|
|
this.lastCompare = compare;
|
|
|
|
|
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if ((this.canolaTank.getFluidAmount() != this.lastCanola || this.oilTank.getFluidAmount() != this.lastOil || this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()) {
|
2015-07-02 04:21:21 +02:00
|
|
|
this.lastProcessTime = this.currentProcessTime;
|
|
|
|
this.lastCanola = this.canolaTank.getFluidAmount();
|
|
|
|
this.lastOil = this.oilTank.getFluidAmount();
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 13:11:29 +01:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getComparatorStrength() {
|
|
|
|
float calc = (float) this.oilTank.getFluidAmount() / (float) this.oilTank.getCapacity() * 15F;
|
|
|
|
return (int) calc;
|
2016-11-28 13:11:29 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getProcessScaled(int i) {
|
|
|
|
return this.currentProcessTime * i / PROCESS_TIME;
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getOilTankScaled(int i) {
|
|
|
|
return this.oilTank.getFluidAmount() * i / this.oilTank.getCapacity();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getCanolaTankScaled(int i) {
|
|
|
|
return this.canolaTank.getFluidAmount() * i / this.canolaTank.getCapacity();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 13:24:45 +01:00
|
|
|
public IFluidHandler getFluidHandler(Direction facing) {
|
2016-12-05 14:16:53 +01:00
|
|
|
return this.handlerMap;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
2015-12-15 18:51:13 +01:00
|
|
|
|
2016-06-10 21:52:37 +02:00
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public int getMaxFluidAmountToSplitShare() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return this.oilTank.getFluidAmount();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public boolean doesShareFluid() {
|
2016-08-31 20:16:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 13:24:45 +01:00
|
|
|
public Direction[] getFluidShareSides() {
|
|
|
|
return Direction.values();
|
2016-08-31 20:16:36 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|