2015-08-29 14:33:25 +02:00
|
|
|
|
/*
|
|
|
|
|
* 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://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD> 2015 Ellpeck
|
|
|
|
|
*/
|
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
import ellpeck.actuallyadditions.blocks.InitBlocks;
|
|
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
|
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
import net.minecraftforge.fluids.*;
|
|
|
|
|
|
2015-10-18 15:28:06 +02:00
|
|
|
|
public class TileEntityFermentingBarrel extends TileEntityInventoryBase implements IFluidHandler{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
|
|
public FluidTank canolaTank = new FluidTank(2*FluidContainerRegistry.BUCKET_VOLUME);
|
|
|
|
|
public FluidTank oilTank = new FluidTank(2*FluidContainerRegistry.BUCKET_VOLUME);
|
|
|
|
|
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(){
|
|
|
|
|
super(4, "fermentingBarrel");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void updateEntity(){
|
|
|
|
|
if(!worldObj.isRemote){
|
2015-08-15 20:41:45 +02:00
|
|
|
|
if(this.canolaTank.getFluidAmount() >= ConfigIntValues.BARREL_MB_PRODUCED.getValue() && ConfigIntValues.BARREL_MB_PRODUCED.getValue() <= this.oilTank.getCapacity()-this.oilTank.getFluidAmount()){
|
2015-05-20 22:39:43 +02:00
|
|
|
|
this.currentProcessTime++;
|
2015-08-15 20:41:45 +02:00
|
|
|
|
if(this.currentProcessTime >= ConfigIntValues.BARREL_PROCESSING_TIME.getValue()){
|
2015-05-20 22:39:43 +02:00
|
|
|
|
this.currentProcessTime = 0;
|
|
|
|
|
|
2015-08-15 20:41:45 +02:00
|
|
|
|
this.oilTank.fill(new FluidStack(InitBlocks.fluidOil, ConfigIntValues.BARREL_MB_PRODUCED.getValue()), true);
|
|
|
|
|
this.canolaTank.drain(ConfigIntValues.BARREL_MB_PRODUCED.getValue(), 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-07-01 15:14:39 +02:00
|
|
|
|
WorldUtil.emptyBucket(canolaTank, slots, 0, 1, InitBlocks.fluidCanolaOil);
|
|
|
|
|
WorldUtil.fillBucket(oilTank, slots, 2, 3);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
2015-07-02 01:26:37 +02:00
|
|
|
|
if(this.oilTank.getFluidAmount() > 0){
|
2015-05-20 22:39:43 +02:00
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.oilTank);
|
2015-07-02 01:26:37 +02:00
|
|
|
|
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, this.oilTank);
|
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, this.oilTank);
|
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, this.oilTank);
|
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.WEST, this.oilTank);
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
|
|
|
|
|
if(this.canolaTank.getFluidAmount() != this.lastCanola || this.oilTank.getFluidAmount() != this.lastOil || this.currentProcessTime != this.lastProcessTime){
|
|
|
|
|
this.lastProcessTime = this.currentProcessTime;
|
|
|
|
|
this.lastCanola = this.canolaTank.getFluidAmount();
|
|
|
|
|
this.lastOil = this.oilTank.getFluidAmount();
|
|
|
|
|
this.sendUpdate();
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public int getProcessScaled(int i){
|
2015-10-02 16:48:01 +02:00
|
|
|
|
return this.currentProcessTime*i/ConfigIntValues.BARREL_PROCESSING_TIME.getValue();
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-18 15:28:06 +02:00
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
|
2015-05-20 22:39:43 +02:00
|
|
|
|
this.currentProcessTime = compound.getInteger("ProcessTime");
|
|
|
|
|
this.canolaTank.readFromNBT(compound);
|
|
|
|
|
this.oilTank.readFromNBT((NBTTagCompound)compound.getTag("OilTank"));
|
2015-10-18 15:28:06 +02:00
|
|
|
|
super.readSyncableNBT(compound, sync);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
|
@Override
|
2015-10-18 15:28:06 +02:00
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
|
2015-10-03 10:19:40 +02:00
|
|
|
|
compound.setInteger("ProcessTime", this.currentProcessTime);
|
|
|
|
|
this.canolaTank.writeToNBT(compound);
|
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
|
|
|
|
this.oilTank.writeToNBT(tag);
|
|
|
|
|
compound.setTag("OilTank", tag);
|
2015-10-18 15:28:06 +02:00
|
|
|
|
super.writeSyncableNBT(compound, sync);
|
2015-10-03 10:19:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
|
|
|
|
return (i == 0 && FluidContainerRegistry.containsFluid(stack, new FluidStack(InitBlocks.fluidCanolaOil, FluidContainerRegistry.BUCKET_VOLUME))) || (i == 2 && stack.getItem() == Items.bucket);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
|
|
|
|
return this.isItemValidForSlot(slot, stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
2015-07-02 01:14:22 +02:00
|
|
|
|
return (slot == 1 && stack.getItem() == Items.bucket) || (slot == 3 && FluidContainerRegistry.containsFluid(stack, new FluidStack(InitBlocks.fluidOil, FluidContainerRegistry.BUCKET_VOLUME)));
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill){
|
2015-10-02 16:48:01 +02:00
|
|
|
|
if(from != ForgeDirection.DOWN && resource.getFluid() == InitBlocks.fluidCanolaOil){
|
|
|
|
|
return this.canolaTank.fill(resource, doFill);
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain){
|
2015-10-03 10:16:18 +02:00
|
|
|
|
if(resource.getFluid() == InitBlocks.fluidOil){
|
|
|
|
|
return this.oilTank.drain(resource.amount, doDrain);
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain){
|
|
|
|
|
return this.oilTank.drain(maxDrain, doDrain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canFill(ForgeDirection from, Fluid fluid){
|
2015-05-25 17:00:54 +02:00
|
|
|
|
return from != ForgeDirection.DOWN && fluid == InitBlocks.fluidCanolaOil;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canDrain(ForgeDirection from, Fluid fluid){
|
2015-05-29 18:17:28 +02:00
|
|
|
|
return from != ForgeDirection.UP && fluid == InitBlocks.fluidOil;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FluidTankInfo[] getTankInfo(ForgeDirection from){
|
|
|
|
|
return new FluidTankInfo[]{this.canolaTank.getInfo(), this.oilTank.getInfo()};
|
|
|
|
|
}
|
|
|
|
|
}
|