ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCanolaPress.java

152 lines
5.2 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("TileEntityCanolaPress.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-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.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
2015-05-20 22:39:43 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
2016-11-26 08:58:42 +01:00
import net.minecraftforge.energy.IEnergyStorage;
2016-11-26 21:32:27 +01:00
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2016-05-19 20:05:12 +02:00
2016-11-26 20:43:50 +01:00
public class TileEntityCanolaPress extends TileEntityInventoryBase implements ISharingFluidHandler{
2015-05-20 22:39:43 +02: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;
2016-11-26 20:43:50 +01:00
public final CustomEnergyStorage storage = new CustomEnergyStorage(40000, 100, 0);
2016-06-05 02:16:52 +02:00
public final FluidTank tank = new FluidTank(2*Util.BUCKET){
@Override
public boolean canFill(){
return false;
}
};
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;
private int lastProcessTime;
2015-05-20 22:39:43 +02:00
public TileEntityCanolaPress(){
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();
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
if(type != NBTType.SAVE_BLOCK){
compound.setInteger("ProcessTime", this.currentProcessTime);
}
this.storage.writeToNBT(compound);
this.tank.writeToNBT(compound);
super.writeSyncableNBT(compound, type);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
if(type != NBTType.SAVE_BLOCK){
this.currentProcessTime = compound.getInteger("ProcessTime");
}
this.storage.readFromNBT(compound);
this.tank.readFromNBT(compound);
super.readSyncableNBT(compound, type);
}
2015-05-20 22:39:43 +02:00
@Override
public void updateEntity(){
super.updateEntity();
2016-11-26 21:32:27 +01:00
if(!this.world.isRemote){
if(this.isCanola(0) && PRODUCE <= this.tank.getCapacity()-this.tank.getFluidAmount()){
if(this.storage.getEnergyStored() >= ENERGY_USE){
this.currentProcessTime++;
this.storage.extractEnergyInternal(ENERGY_USE, false);
if(this.currentProcessTime >= TIME){
this.currentProcessTime = 0;
2015-05-20 22:39:43 +02:00
this.slots.setStackInSlot(0, StackUtil.addStackSize(this.slots.getStackInSlot(0), -1));
2015-05-20 22:39:43 +02:00
2016-06-05 02:16:52 +02:00
this.tank.fillInternal(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
this.markDirty();
}
2015-05-20 22:39:43 +02:00
}
}
2015-10-02 16:48:01 +02:00
else{
this.currentProcessTime = 0;
}
if((this.storage.getEnergyStored() != this.lastEnergyStored || this.tank.getFluidAmount() != this.lastTankAmount | this.currentProcessTime != this.lastProcessTime) && this.sendUpdateWithInterval()){
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){
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 StackUtil.isValid(this.slots.getStackInSlot(slot)) && this.slots.getStackInSlot(slot).getItem() == InitItems.itemMisc && this.slots.getStackInSlot(slot).getItemDamage() == TheMiscItems.CANOLA.ordinal();
2015-05-20 22:39:43 +02:00
}
@Override
public boolean canExtractItem(int slot, ItemStack stack){
return false;
2015-05-20 22:39:43 +02:00
}
2016-06-05 02:16:52 +02:00
@Override
public FluidTank getFluidHandler(EnumFacing facing){
return facing != EnumFacing.UP ? this.tank : null;
}
@Override
2016-11-19 21:11:17 +01:00
public int getMaxFluidAmountToSplitShare(){
return this.tank.getFluidAmount();
}
@Override
public boolean doesShareFluid(){
return true;
}
@Override
public EnumFacing[] getFluidShareSides(){
return EnumFacing.values();
}
2016-11-26 08:58:42 +01:00
@Override
public IEnergyStorage getEnergyStorage(EnumFacing facing){
return this.storage;
}
2015-05-20 22:39:43 +02:00
}