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
|
|
|
|
|
* 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 cofh.api.energy.EnergyStorage;
|
|
|
|
|
import cofh.api.energy.IEnergyReceiver;
|
|
|
|
|
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.items.InitItems;
|
|
|
|
|
import ellpeck.actuallyadditions.items.metalists.TheMiscItems;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
import ellpeck.actuallyadditions.network.sync.IPacketSyncerToClient;
|
|
|
|
|
import ellpeck.actuallyadditions.network.sync.PacketSyncerToClient;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
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-07-02 04:21:21 +02:00
|
|
|
|
public class TileEntityCanolaPress extends TileEntityInventoryBase implements IEnergyReceiver, IFluidHandler, IPacketSyncerToClient{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
|
public EnergyStorage storage = new EnergyStorage(40000);
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastEnergyStored;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
|
|
public FluidTank tank = new FluidTank(2*FluidContainerRegistry.BUCKET_VOLUME);
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastTankAmount;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
|
|
public int currentProcessTime;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastProcessTime;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
|
|
public TileEntityCanolaPress(){
|
|
|
|
|
super(3, "canolaPress");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
public void updateEntity(){
|
|
|
|
|
if(!worldObj.isRemote){
|
2015-08-15 20:41:45 +02:00
|
|
|
|
if(this.isCanola(0) && ConfigIntValues.PRESS_MB_PRODUCED.getValue() <= this.tank.getCapacity()-this.tank.getFluidAmount()){
|
|
|
|
|
if(this.storage.getEnergyStored() >= ConfigIntValues.PRESS_ENERGY_USED.getValue()){
|
2015-06-13 12:52:22 +02:00
|
|
|
|
this.currentProcessTime++;
|
2015-08-15 20:41:45 +02:00
|
|
|
|
this.storage.extractEnergy(ConfigIntValues.PRESS_ENERGY_USED.getValue(), false);
|
|
|
|
|
if(this.currentProcessTime >= ConfigIntValues.PRESS_PROCESSING_TIME.getValue()){
|
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--;
|
|
|
|
|
if(this.slots[0].stackSize == 0) this.slots[0] = null;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
2015-08-15 20:41:45 +02:00
|
|
|
|
this.tank.fill(new FluidStack(InitBlocks.fluidCanolaOil, ConfigIntValues.PRESS_MB_PRODUCED.getValue()), true);
|
2015-06-13 12:52:22 +02:00
|
|
|
|
this.markDirty();
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else this.currentProcessTime = 0;
|
|
|
|
|
|
2015-07-01 15:14:39 +02:00
|
|
|
|
WorldUtil.fillBucket(tank, slots, 1, 2);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
2015-07-02 01:26:37 +02:00
|
|
|
|
if(this.tank.getFluidAmount() > 0){
|
2015-05-20 22:39:43 +02:00
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.DOWN, this.tank);
|
2015-07-02 01:26:37 +02:00
|
|
|
|
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.NORTH, this.tank);
|
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.EAST, this.tank);
|
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.SOUTH, this.tank);
|
|
|
|
|
WorldUtil.pushFluid(worldObj, xCoord, yCoord, zCoord, ForgeDirection.WEST, this.tank);
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
|
|
|
|
|
if(this.storage.getEnergyStored() != this.lastEnergyStored || this.tank.getFluidAmount() != this.lastTankAmount | this.currentProcessTime != this.lastProcessTime){
|
|
|
|
|
this.lastEnergyStored = this.storage.getEnergyStored();
|
|
|
|
|
this.lastProcessTime = this.currentProcessTime;
|
|
|
|
|
this.lastTankAmount = this.tank.getFluidAmount();
|
|
|
|
|
this.sendUpdate();
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isCanola(int slot){
|
|
|
|
|
return this.slots[slot] != null && this.slots[slot].getItem() == InitItems.itemMisc && this.slots[slot].getItemDamage() == TheMiscItems.CANOLA.ordinal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public int getTankScaled(int i){
|
|
|
|
|
return this.tank.getFluidAmount() * i / this.tank.getCapacity();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public int getProcessScaled(int i){
|
2015-08-15 20:41:45 +02:00
|
|
|
|
return this.currentProcessTime * i / ConfigIntValues.PRESS_PROCESSING_TIME.getValue();
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public int getEnergyScaled(int i){
|
2015-07-02 00:35:38 +02:00
|
|
|
|
return this.storage.getEnergyStored() * i / this.storage.getMaxEnergyStored();
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void writeToNBT(NBTTagCompound compound){
|
|
|
|
|
compound.setInteger("ProcessTime", this.currentProcessTime);
|
|
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
|
this.tank.writeToNBT(compound);
|
|
|
|
|
super.writeToNBT(compound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void readFromNBT(NBTTagCompound compound){
|
|
|
|
|
this.currentProcessTime = compound.getInteger("ProcessTime");
|
|
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
|
this.tank.readFromNBT(compound);
|
|
|
|
|
super.readFromNBT(compound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
|
|
|
|
return (i == 0 && stack.getItem() == InitItems.itemMisc && stack.getItemDamage() == TheMiscItems.CANOLA.ordinal()) || (i == 1 && stack.getItem() == Items.bucket);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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-06-06 01:25:53 +02:00
|
|
|
|
return slot == 2 && FluidContainerRegistry.containsFluid(this.slots[0], new FluidStack(InitBlocks.fluidCanolaOil, FluidContainerRegistry.BUCKET_VOLUME));
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate){
|
|
|
|
|
return this.storage.receiveEnergy(maxReceive, simulate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getEnergyStored(ForgeDirection from){
|
|
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getMaxEnergyStored(ForgeDirection from){
|
|
|
|
|
return this.storage.getMaxEnergyStored();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canConnectEnergy(ForgeDirection from){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill){
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain){
|
2015-05-25 17:00:54 +02:00
|
|
|
|
if(resource.getFluid() == InitBlocks.fluidCanolaOil) return this.tank.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.tank.drain(maxDrain, doDrain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canFill(ForgeDirection from, Fluid fluid){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canDrain(ForgeDirection from, Fluid fluid){
|
2015-05-29 18:17:28 +02:00
|
|
|
|
return from != ForgeDirection.UP;
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public FluidTankInfo[] getTankInfo(ForgeDirection from){
|
|
|
|
|
return new FluidTankInfo[]{this.tank.getInfo()};
|
|
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int[] getValues(){
|
|
|
|
|
return new int[]{this.currentProcessTime, this.tank.getFluidAmount(), this.tank.getFluid() == null ? -1 : this.tank.getFluid().getFluidID(), this.storage.getEnergyStored()};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setValues(int[] values){
|
|
|
|
|
this.currentProcessTime = values[0];
|
|
|
|
|
if(values[2] != -1){
|
|
|
|
|
this.tank.setFluid(new FluidStack(FluidRegistry.getFluid(values[2]), values[1]));
|
|
|
|
|
}
|
|
|
|
|
else this.tank.setFluid(null);
|
|
|
|
|
this.storage.setEnergyStored(values[3]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void sendUpdate(){
|
|
|
|
|
PacketSyncerToClient.sendPacket(this);
|
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
}
|