mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-05 08:29:09 +01:00
e636ab14f1
Closes #221
194 lines
6.5 KiB
Java
194 lines
6.5 KiB
Java
/*
|
|
* This file ("TileEntityFermentingBarrel.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.mod.tile;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
|
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.capability.IFluidHandler;
|
|
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
|
import net.minecraftforge.fluids.capability.templates.FluidHandlerFluidMap;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
public class TileEntityFermentingBarrel extends TileEntityBase implements ISharingFluidHandler{
|
|
|
|
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;
|
|
}
|
|
};
|
|
public int currentProcessTime;
|
|
private int lastCanola;
|
|
private int lastOil;
|
|
private int lastProcessTime;
|
|
|
|
public TileEntityFermentingBarrel(){
|
|
super("fermentingBarrel");
|
|
}
|
|
|
|
@Override
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
compound.setInteger("ProcessTime", this.currentProcessTime);
|
|
this.canolaTank.writeToNBT(compound);
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
this.oilTank.writeToNBT(tag);
|
|
compound.setTag("OilTank", tag);
|
|
super.writeSyncableNBT(compound, type);
|
|
}
|
|
|
|
@Override
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
this.currentProcessTime = compound.getInteger("ProcessTime");
|
|
this.canolaTank.readFromNBT(compound);
|
|
this.oilTank.readFromNBT((NBTTagCompound)compound.getTag("OilTank"));
|
|
super.readSyncableNBT(compound, type);
|
|
}
|
|
|
|
@Override
|
|
public void updateEntity(){
|
|
super.updateEntity();
|
|
if(!this.worldObj.isRemote){
|
|
int produce = 80;
|
|
if(this.canolaTank.getFluidAmount() >= produce && produce <= this.oilTank.getCapacity()-this.oilTank.getFluidAmount()){
|
|
this.currentProcessTime++;
|
|
if(this.currentProcessTime >= PROCESS_TIME){
|
|
this.currentProcessTime = 0;
|
|
|
|
this.oilTank.fillInternal(new FluidStack(InitFluids.fluidOil, produce), true);
|
|
this.canolaTank.drainInternal(produce, true);
|
|
this.markDirty();
|
|
}
|
|
}
|
|
else{
|
|
this.currentProcessTime = 0;
|
|
}
|
|
|
|
if((this.canolaTank.getFluidAmount() != this.lastCanola || this.oilTank.getFluidAmount() != this.lastOil || this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()){
|
|
this.lastProcessTime = this.currentProcessTime;
|
|
this.lastCanola = this.canolaTank.getFluidAmount();
|
|
this.lastOil = this.oilTank.getFluidAmount();
|
|
}
|
|
}
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public int getProcessScaled(int i){
|
|
return this.currentProcessTime*i/PROCESS_TIME;
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public int getOilTankScaled(int i){
|
|
return this.oilTank.getFluidAmount()*i/this.oilTank.getCapacity();
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public int getCanolaTankScaled(int i){
|
|
return this.canolaTank.getFluidAmount()*i/this.canolaTank.getCapacity();
|
|
}
|
|
|
|
@Override
|
|
public IFluidHandler getFluidHandler(EnumFacing facing){
|
|
FluidHandlerFluidMap map = new FluidHandlerFluidMap();
|
|
if(facing != EnumFacing.DOWN){
|
|
map.addHandler(InitFluids.fluidCanolaOil, this.canolaTank);
|
|
}
|
|
if(facing != EnumFacing.UP){
|
|
map.addHandler(InitFluids.fluidOil, this.oilTank);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
@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;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getFluidAmountToSplitShare(){
|
|
return this.oilTank.getFluidAmount();
|
|
}
|
|
|
|
@Override
|
|
public boolean doesShareFluid(){
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public EnumFacing[] getFluidShareSides(){
|
|
return EnumFacing.values();
|
|
}
|
|
}
|