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
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 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;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-06-10 21:52:37 +02:00
|
|
|
import net.minecraftforge.fluids.*;
|
2016-06-05 02:16:52 +02:00
|
|
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
2016-06-10 21:52:37 +02:00
|
|
|
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
2016-06-05 02:16:52 +02:00
|
|
|
import net.minecraftforge.fluids.capability.templates.FluidHandlerFluidMap;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-06-10 21:52:37 +02:00
|
|
|
public class TileEntityFermentingBarrel extends TileEntityBase implements IFluidSaver, net.minecraftforge.fluids.IFluidHandler{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
private static final int PROCESS_TIME = 100;
|
2016-06-05 02:16:52 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
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;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
public TileEntityFermentingBarrel(){
|
2016-05-06 23:23:29 +02:00
|
|
|
super("fermentingBarrel");
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
compound.setInteger("ProcessTime", this.currentProcessTime);
|
|
|
|
this.canolaTank.writeToNBT(compound);
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
this.oilTank.writeToNBT(tag);
|
|
|
|
compound.setTag("OilTank", tag);
|
|
|
|
super.writeSyncableNBT(compound, sync);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
this.currentProcessTime = compound.getInteger("ProcessTime");
|
|
|
|
this.canolaTank.readFromNBT(compound);
|
|
|
|
this.oilTank.readFromNBT((NBTTagCompound)compound.getTag("OilTank"));
|
|
|
|
super.readSyncableNBT(compound, sync);
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2016-05-02 17:46:53 +02:00
|
|
|
if(!this.worldObj.isRemote){
|
2015-12-22 17:54:55 +01:00
|
|
|
int produce = 80;
|
2015-11-28 19:02:01 +01:00
|
|
|
if(this.canolaTank.getFluidAmount() >= produce && produce <= this.oilTank.getCapacity()-this.oilTank.getFluidAmount()){
|
2015-05-20 22:39:43 +02:00
|
|
|
this.currentProcessTime++;
|
2015-11-28 19:02:01 +01:00
|
|
|
if(this.currentProcessTime >= PROCESS_TIME){
|
2015-05-20 22:39:43 +02:00
|
|
|
this.currentProcessTime = 0;
|
|
|
|
|
2016-06-05 02:16:52 +02:00
|
|
|
this.oilTank.fillInternal(new FluidStack(InitFluids.fluidOil, produce), true);
|
|
|
|
this.canolaTank.drainInternal(produce, true);
|
2015-05-20 22:39:43 +02:00
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
else{
|
|
|
|
this.currentProcessTime = 0;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-12-01 17:28:50 +01: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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getProcessScaled(int i){
|
|
|
|
return this.currentProcessTime*i/PROCESS_TIME;
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getOilTankScaled(int i){
|
2015-10-02 16:48:01 +02:00
|
|
|
return this.oilTank.getFluidAmount()*i/this.oilTank.getCapacity();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getCanolaTankScaled(int i){
|
2015-10-02 16:48:01 +02:00
|
|
|
return this.canolaTank.getFluidAmount()*i/this.canolaTank.getCapacity();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-06-05 02:16:52 +02:00
|
|
|
public IFluidHandler getFluidHandler(EnumFacing facing){
|
|
|
|
FluidHandlerFluidMap map = new FluidHandlerFluidMap();
|
|
|
|
if(facing != EnumFacing.DOWN){
|
|
|
|
map.addHandler(InitFluids.fluidCanolaOil, this.canolaTank);
|
2015-10-02 16:48:01 +02:00
|
|
|
}
|
2016-06-05 02:16:52 +02:00
|
|
|
if(facing != EnumFacing.UP){
|
|
|
|
map.addHandler(InitFluids.fluidOil, this.oilTank);
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2016-06-05 02:16:52 +02:00
|
|
|
return map;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
2015-12-15 18:51:13 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack[] getFluids(){
|
|
|
|
return new FluidStack[]{this.oilTank.getFluid(), this.canolaTank.getFluid()};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFluids(FluidStack[] fluids){
|
|
|
|
this.oilTank.setFluid(fluids[0]);
|
|
|
|
this.canolaTank.setFluid(fluids[1]);
|
|
|
|
}
|
2016-06-10 21:52:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
|
|
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
|
|
return handler == null ? 0 : handler.fill(resource, doFill);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
|
|
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
|
|
return handler == null ? null : handler.drain(resource, doDrain);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
|
|
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
|
|
return handler == null ? null : handler.drain(maxDrain, doDrain);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(EnumFacing from, Fluid fluid){
|
|
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
|
|
if(handler != null){
|
|
|
|
for(IFluidTankProperties prop : handler.getTankProperties()){
|
|
|
|
if(prop != null && prop.canFillFluidType(new FluidStack(fluid, Integer.MAX_VALUE))){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(EnumFacing from, Fluid fluid){
|
|
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
|
|
if(handler != null){
|
|
|
|
for(IFluidTankProperties prop : handler.getTankProperties()){
|
|
|
|
if(prop != null && prop.canDrainFluidType(new FluidStack(fluid, Integer.MAX_VALUE))){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(EnumFacing from){
|
|
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
|
|
if(handler instanceof IFluidTank){
|
|
|
|
return new FluidTankInfo[]{((IFluidTank)handler).getInfo()};
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|