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
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 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-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraftforge.fluids.*;
|
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
|
|
|
|
2015-12-15 18:51:13 +01:00
|
|
|
public class TileEntityFermentingBarrel extends TileEntityInventoryBase implements IFluidHandler, IFluidSaver{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
private static final int PROCESS_TIME = 100;
|
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(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2015-05-20 22:39:43 +02:00
|
|
|
if(!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-01-29 17:38:31 +01:00
|
|
|
this.oilTank.fill(new FluidStack(InitFluids.fluidOil, produce), true);
|
2015-11-28 19:02:01 +01:00
|
|
|
this.canolaTank.drain(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
|
|
|
|
2016-01-29 17:38:31 +01:00
|
|
|
WorldUtil.emptyBucket(canolaTank, slots, 0, 1, InitFluids.fluidCanolaOil);
|
2015-07-01 15:14:39 +02:00
|
|
|
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){
|
2016-01-08 13:31:58 +01:00
|
|
|
WorldUtil.pushFluid(worldObj, this.pos, EnumFacing.DOWN, this.oilTank);
|
2015-12-03 18:40:43 +01:00
|
|
|
if(!this.isRedstonePowered){
|
2016-01-08 13:31:58 +01:00
|
|
|
WorldUtil.pushFluid(worldObj, this.pos, EnumFacing.NORTH, this.oilTank);
|
|
|
|
WorldUtil.pushFluid(worldObj, this.pos, EnumFacing.EAST, this.oilTank);
|
|
|
|
WorldUtil.pushFluid(worldObj, this.pos, EnumFacing.SOUTH, this.oilTank);
|
|
|
|
WorldUtil.pushFluid(worldObj, this.pos, EnumFacing.WEST, this.oilTank);
|
2015-07-02 01:26:37 +02:00
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
2015-07-02 04:21:21 +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-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
|
|
|
}
|
|
|
|
|
2015-10-18 15:31:01 +02:00
|
|
|
@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-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-01-07 21:41:28 +01:00
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.isItemValidForSlot(slot, stack);
|
|
|
|
}
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
2016-01-29 17:38:31 +01:00
|
|
|
return (i == 0 && FluidContainerRegistry.containsFluid(stack, new FluidStack(InitFluids.fluidCanolaOil, FluidContainerRegistry.BUCKET_VOLUME))) || (i == 2 && stack.getItem() == Items.bucket);
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
|
2016-01-29 17:38:31 +01:00
|
|
|
return (slot == 1 && stack.getItem() == Items.bucket) || (slot == 3 && FluidContainerRegistry.containsFluid(stack, new FluidStack(InitFluids.fluidOil, FluidContainerRegistry.BUCKET_VOLUME)));
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
|
2016-01-29 17:38:31 +01:00
|
|
|
if(from != EnumFacing.DOWN && resource.getFluid() == InitFluids.fluidCanolaOil){
|
2015-10-02 16:48:01 +02:00
|
|
|
return this.canolaTank.fill(resource, doFill);
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
|
2016-01-29 17:38:31 +01:00
|
|
|
if(resource.getFluid() == InitFluids.fluidOil){
|
2015-10-03 10:16:18 +02:00
|
|
|
return this.oilTank.drain(resource.amount, doDrain);
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.oilTank.drain(maxDrain, doDrain);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public boolean canFill(EnumFacing from, Fluid fluid){
|
2016-01-29 17:38:31 +01:00
|
|
|
return from != EnumFacing.DOWN && fluid == InitFluids.fluidCanolaOil;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public boolean canDrain(EnumFacing from, Fluid fluid){
|
2016-01-29 17:38:31 +01:00
|
|
|
return from != EnumFacing.UP && fluid == InitFluids.fluidOil;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public FluidTankInfo[] getTankInfo(EnumFacing from){
|
2015-05-20 22:39:43 +02:00
|
|
|
return new FluidTankInfo[]{this.canolaTank.getInfo(), this.oilTank.getInfo()};
|
|
|
|
}
|
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]);
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|