mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-10-05 06:54:24 +02:00
6e34f9e345
Prepared for 1.11 ItemStack updates
227 lines
7.6 KiB
Java
227 lines
7.6 KiB
Java
/*
|
|
* 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://ellpeck.de/actaddlicense
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
*
|
|
* © 2015-2016 Ellpeck
|
|
*/
|
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
|
|
|
import cofh.api.energy.EnergyStorage;
|
|
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
|
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;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.EnumFacing;
|
|
import net.minecraftforge.fluids.*;
|
|
import net.minecraftforge.fluids.capability.IFluidHandler;
|
|
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
public class TileEntityCanolaPress extends TileEntityInventoryBase implements ICustomEnergyReceiver, ISharingFluidHandler{
|
|
|
|
public static final int PRODUCE = 80;
|
|
public static final int ENERGY_USE = 35;
|
|
private static final int TIME = 30;
|
|
public final EnergyStorage storage = new EnergyStorage(40000);
|
|
public final FluidTank tank = new FluidTank(2*Util.BUCKET){
|
|
@Override
|
|
public boolean canFill(){
|
|
return false;
|
|
}
|
|
};
|
|
public int currentProcessTime;
|
|
private int lastEnergyStored;
|
|
private int lastTankAmount;
|
|
private int lastProcessTime;
|
|
|
|
public TileEntityCanolaPress(){
|
|
super(1, "canolaPress");
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
@Override
|
|
public void updateEntity(){
|
|
super.updateEntity();
|
|
if(!this.worldObj.isRemote){
|
|
if(this.isCanola(0) && PRODUCE <= this.tank.getCapacity()-this.tank.getFluidAmount()){
|
|
if(this.storage.getEnergyStored() >= ENERGY_USE){
|
|
this.currentProcessTime++;
|
|
this.storage.extractEnergy(ENERGY_USE, false);
|
|
if(this.currentProcessTime >= TIME){
|
|
this.currentProcessTime = 0;
|
|
|
|
this.slots[0] = StackUtil.addStackSize(this.slots[0], -1);
|
|
|
|
this.tank.fillInternal(new FluidStack(InitFluids.fluidCanolaOil, PRODUCE), true);
|
|
this.markDirty();
|
|
}
|
|
}
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
|
return (i == 0 && stack.getItem() == InitItems.itemMisc && stack.getItemDamage() == TheMiscItems.CANOLA.ordinal());
|
|
}
|
|
|
|
public boolean isCanola(int slot){
|
|
return StackUtil.isValid(this.slots[slot]) && this.slots[slot].getItem() == InitItems.itemMisc && this.slots[slot].getItemDamage() == TheMiscItems.CANOLA.ordinal();
|
|
}
|
|
|
|
@Override
|
|
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
|
|
return this.isItemValidForSlot(slot, stack);
|
|
}
|
|
|
|
@Override
|
|
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate){
|
|
return this.storage.receiveEnergy(maxReceive, simulate);
|
|
}
|
|
|
|
@Override
|
|
public int getEnergyStored(EnumFacing from){
|
|
return this.storage.getEnergyStored();
|
|
}
|
|
|
|
@Override
|
|
public int getMaxEnergyStored(EnumFacing from){
|
|
return this.storage.getMaxEnergyStored();
|
|
}
|
|
|
|
@Override
|
|
public boolean canConnectEnergy(EnumFacing from){
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public FluidTank getFluidHandler(EnumFacing facing){
|
|
return facing != EnumFacing.UP ? this.tank : null;
|
|
}
|
|
|
|
@Override
|
|
public int fill(EnumFacing from, FluidStack resource, boolean doFill){
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
return handler == null ? 0 : handler.fill(resource, doFill);
|
|
}
|
|
|
|
@Override
|
|
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain){
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
return handler == null ? null : handler.drain(resource, doDrain);
|
|
}
|
|
|
|
@Override
|
|
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain){
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
return handler == null ? null : handler.drain(maxDrain, doDrain);
|
|
}
|
|
|
|
@Override
|
|
public boolean canFill(EnumFacing from, Fluid fluid){
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
if(handler != null){
|
|
for(IFluidTankProperties prop : handler.getTankProperties()){
|
|
if(prop != null && prop.canFillFluidType(new FluidStack(fluid, Integer.MAX_VALUE))){
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean canDrain(EnumFacing from, Fluid fluid){
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
if(handler != null){
|
|
for(IFluidTankProperties prop : handler.getTankProperties()){
|
|
if(prop != null && prop.canDrainFluidType(new FluidStack(fluid, Integer.MAX_VALUE))){
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public FluidTankInfo[] getTankInfo(EnumFacing from){
|
|
IFluidHandler handler = this.getFluidHandler(from);
|
|
if(handler instanceof IFluidTank){
|
|
return new FluidTankInfo[]{((IFluidTank)handler).getInfo()};
|
|
}
|
|
else{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getFluidAmountToSplitShare(){
|
|
return this.tank.getFluidAmount();
|
|
}
|
|
|
|
@Override
|
|
public boolean doesShareFluid(){
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public EnumFacing[] getFluidShareSides(){
|
|
return EnumFacing.values();
|
|
}
|
|
}
|