2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityCanolaPress.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
|
|
|
|
|
|
|
import cofh.api.energy.EnergyStorage;
|
|
|
|
import cofh.api.energy.IEnergyReceiver;
|
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.items.InitItems;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
2016-05-06 23:23:29 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
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.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 19:47:53 +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 TileEntityCanolaPress extends TileEntityInventoryBase implements IEnergyReceiver, IFluidHandler, IEnergySaver, IFluidSaver{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-23 22:58:40 +01:00
|
|
|
public static final int PRODUCE = 80;
|
2015-12-01 19:48:09 +01:00
|
|
|
public static final int ENERGY_USE = 35;
|
|
|
|
private static final int TIME = 30;
|
2015-06-12 19:12:06 +02:00
|
|
|
public EnergyStorage storage = new EnergyStorage(40000);
|
2016-05-06 23:23:29 +02:00
|
|
|
public FluidTank tank = new FluidTank(2*Util.BUCKET);
|
2015-05-20 22:39:43 +02:00
|
|
|
public int currentProcessTime;
|
2015-10-03 10:16:18 +02:00
|
|
|
private int lastEnergyStored;
|
|
|
|
private int lastTankAmount;
|
2015-07-02 04:21:21 +02:00
|
|
|
private int lastProcessTime;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
public TileEntityCanolaPress(){
|
2016-05-06 23:23:29 +02:00
|
|
|
super(1, "canolaPress");
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getTankScaled(int i){
|
|
|
|
return this.tank.getFluidAmount()*i/this.tank.getCapacity();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getProcessScaled(int i){
|
|
|
|
return this.currentProcessTime*i/TIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getEnergyScaled(int i){
|
|
|
|
return this.storage.getEnergyStored()*i/this.storage.getMaxEnergyStored();
|
|
|
|
}
|
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
compound.setInteger("ProcessTime", this.currentProcessTime);
|
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
this.tank.writeToNBT(compound);
|
|
|
|
super.writeSyncableNBT(compound, sync);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
|
|
|
|
this.currentProcessTime = compound.getInteger("ProcessTime");
|
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
this.tank.readFromNBT(compound);
|
|
|
|
super.readSyncableNBT(compound, sync);
|
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
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-11-28 19:02:01 +01:00
|
|
|
if(this.isCanola(0) && PRODUCE <= this.tank.getCapacity()-this.tank.getFluidAmount()){
|
|
|
|
if(this.storage.getEnergyStored() >= ENERGY_USE){
|
2015-06-13 12:52:22 +02:00
|
|
|
this.currentProcessTime++;
|
2015-11-28 19:02:01 +01:00
|
|
|
this.storage.extractEnergy(ENERGY_USE, false);
|
|
|
|
if(this.currentProcessTime >= TIME){
|
2015-06-13 12:52:22 +02:00
|
|
|
this.currentProcessTime = 0;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-06-13 12:52:22 +02:00
|
|
|
this.slots[0].stackSize--;
|
2015-10-03 10:16:18 +02:00
|
|
|
if(this.slots[0].stackSize == 0){
|
|
|
|
this.slots[0] = null;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-29 17:38:31 +01:00
|
|
|
this.tank.fill(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
|
2015-06-13 12:52:22 +02:00
|
|
|
this.markDirty();
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-10-02 16:48:01 +02:00
|
|
|
else{
|
|
|
|
this.currentProcessTime = 0;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-07-02 01:26:37 +02:00
|
|
|
if(this.tank.getFluidAmount() > 0){
|
2016-05-02 17:46:53 +02:00
|
|
|
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.DOWN, this.tank);
|
2015-12-03 18:40:43 +01:00
|
|
|
if(!this.isRedstonePowered){
|
2016-05-02 17:46:53 +02:00
|
|
|
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.NORTH, this.tank);
|
|
|
|
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.EAST, this.tank);
|
|
|
|
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.SOUTH, this.tank);
|
|
|
|
WorldUtil.pushFluid(this.worldObj, this.pos, EnumFacing.WEST, this.tank);
|
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.storage.getEnergyStored() != this.lastEnergyStored || this.tank.getFluidAmount() != this.lastTankAmount | this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()){
|
2015-07-02 04:21:21 +02:00
|
|
|
this.lastEnergyStored = this.storage.getEnergyStored();
|
|
|
|
this.lastProcessTime = this.currentProcessTime;
|
|
|
|
this.lastTankAmount = this.tank.getFluidAmount();
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
2016-05-06 23:23:29 +02:00
|
|
|
return (i == 0 && stack.getItem() == InitItems.itemMisc && stack.getItemDamage() == TheMiscItems.CANOLA.ordinal());
|
2016-02-01 17:49:55 +01:00
|
|
|
}
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
public boolean isCanola(int slot){
|
|
|
|
return this.slots[slot] != null && this.slots[slot].getItem() == InitItems.itemMisc && this.slots[slot].getItemDamage() == TheMiscItems.CANOLA.ordinal();
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.isItemValidForSlot(slot, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
|
2016-05-06 23:23:29 +02:00
|
|
|
return false;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.storage.receiveEnergy(maxReceive, simulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public int getEnergyStored(EnumFacing from){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public int getMaxEnergyStored(EnumFacing from){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.storage.getMaxEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public boolean canConnectEnergy(EnumFacing from){
|
2015-05-20 22:39:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
|
2015-05-20 22:39:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
|
2016-01-29 17:38:31 +01:00
|
|
|
if(resource.getFluid() == InitFluids.fluidCanolaOil){
|
2015-10-03 10:16:18 +02:00
|
|
|
return this.tank.drain(resource.amount, doDrain);
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.tank.drain(maxDrain, doDrain);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public boolean canFill(EnumFacing from, Fluid fluid){
|
2015-05-20 22:39:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public boolean canDrain(EnumFacing from, Fluid fluid){
|
|
|
|
return from != EnumFacing.UP;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 19:47:53 +01:00
|
|
|
public FluidTankInfo[] getTankInfo(EnumFacing from){
|
2015-05-20 22:39:43 +02:00
|
|
|
return new FluidTankInfo[]{this.tank.getInfo()};
|
|
|
|
}
|
2015-12-13 00:54:25 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergy(){
|
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setEnergy(int energy){
|
|
|
|
this.storage.setEnergyStored(energy);
|
|
|
|
}
|
2015-12-15 18:51:13 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack[] getFluids(){
|
|
|
|
return new FluidStack[]{this.tank.getFluid()};
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFluids(FluidStack[] fluids){
|
|
|
|
this.tank.setFluid(fluids[0]);
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|