2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityFurnaceSolar.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-03-30 15:08:19 +02:00
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
import cofh.api.energy.EnergyStorage;
|
|
|
|
import cofh.api.energy.IEnergyProvider;
|
2016-01-07 23:42:42 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.Position;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.tile.IEnergyDisplay;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
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-21 22:18:33 +01:00
|
|
|
public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyProvider, IEnergySaver, IEnergyDisplay{
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2016-01-07 16:07:23 +01:00
|
|
|
public static final int PRODUCE = 8;
|
2015-12-01 19:48:09 +01:00
|
|
|
public EnergyStorage storage = new EnergyStorage(30000);
|
2015-12-21 22:18:33 +01:00
|
|
|
private int oldEnergy;
|
2015-11-28 19:02:01 +01:00
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.storage.extractEnergy(maxExtract, simulate);
|
|
|
|
}
|
2015-03-30 15:08:19 +02:00
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int getEnergyStored(EnumFacing from){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.storage.getEnergyStored();
|
2015-04-24 19:22:03 +02:00
|
|
|
}
|
|
|
|
|
2015-05-20 22:39:43 +02:00
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public int getMaxEnergyStored(EnumFacing from){
|
2015-05-20 22:39:43 +02:00
|
|
|
return this.storage.getMaxEnergyStored();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 23:42:42 +01:00
|
|
|
public boolean canConnectEnergy(EnumFacing from){
|
|
|
|
return from != EnumFacing.UP;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-03-30 15:08:19 +02:00
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
super.updateEntity();
|
2015-03-30 15:08:19 +02:00
|
|
|
if(!worldObj.isRemote){
|
2015-11-26 18:45:06 +01:00
|
|
|
if(!this.hasBlockAbove() && worldObj.isDaytime()){
|
2016-01-07 23:42:42 +01:00
|
|
|
if(PRODUCE <= this.storage.getMaxEnergyStored()-this.storage.getEnergyStored()){
|
2015-11-28 19:02:01 +01:00
|
|
|
this.storage.receiveEnergy(PRODUCE, false);
|
2015-05-20 22:39:43 +02:00
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
}
|
2015-03-30 15:08:19 +02:00
|
|
|
|
2016-01-07 23:42:42 +01:00
|
|
|
if(this.storage.getEnergyStored() > 0){
|
|
|
|
WorldUtil.pushEnergyToAllSides(worldObj, Position.fromTileEntity(this), this.storage);
|
2015-03-31 20:37:55 +02:00
|
|
|
}
|
2015-12-21 22:18:33 +01:00
|
|
|
|
|
|
|
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
|
|
|
this.oldEnergy = this.storage.getEnergyStored();
|
|
|
|
}
|
2015-03-31 20:37:55 +02:00
|
|
|
}
|
|
|
|
}
|
2015-12-01 19:48:09 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
|
2015-12-21 22:18:33 +01:00
|
|
|
super.writeSyncableNBT(compound, sync);
|
2015-12-01 19:48:09 +01:00
|
|
|
this.storage.writeToNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
|
2015-12-21 22:18:33 +01:00
|
|
|
super.readSyncableNBT(compound, sync);
|
2015-12-01 19:48:09 +01:00
|
|
|
this.storage.readFromNBT(compound);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasBlockAbove(){
|
2016-01-07 23:42:42 +01:00
|
|
|
Position pos = Position.fromTileEntity(this);
|
|
|
|
for(int y = 1; y <= worldObj.getHeight(); y++){
|
|
|
|
Position offset = pos.getOffsetPosition(0, y, 0);
|
|
|
|
if(!offset.getBlock(worldObj).isAir(worldObj, offset)){
|
2015-12-01 19:48:09 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-13 00:54:25 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEnergy(){
|
|
|
|
return this.storage.getEnergyStored();
|
|
|
|
}
|
|
|
|
|
2015-12-21 22:18:33 +01:00
|
|
|
@Override
|
2015-12-21 22:46:23 +01:00
|
|
|
public void setEnergy(int energy){
|
|
|
|
this.storage.setEnergyStored(energy);
|
2015-12-21 22:18:33 +01:00
|
|
|
}
|
|
|
|
|
2015-12-13 00:54:25 +01:00
|
|
|
@Override
|
2015-12-21 22:46:23 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getMaxEnergy(){
|
|
|
|
return this.storage.getMaxEnergyStored();
|
2015-12-13 00:54:25 +01:00
|
|
|
}
|
2015-03-30 15:08:19 +02:00
|
|
|
}
|