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

110 lines
3.1 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("TileEntityFurnaceSolar.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-03-30 15:08:19 +02:00
2016-07-04 20:15:41 +02:00
import net.minecraft.block.state.IBlockState;
2015-05-20 22:39:43 +02:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
2016-11-26 08:58:42 +01:00
import net.minecraftforge.energy.IEnergyStorage;
2015-05-20 22:39:43 +02:00
public class TileEntityFurnaceSolar extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay{
2015-05-20 22:39:43 +02:00
2016-01-07 16:07:23 +01:00
public static final int PRODUCE = 8;
2016-11-26 20:43:50 +01:00
public final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 0, 100);
private int oldEnergy;
public TileEntityFurnaceSolar(){
super("solarPanel");
}
2016-02-01 17:49:55 +01:00
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
2016-02-01 17:49:55 +01:00
this.storage.writeToNBT(compound);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
2016-02-01 17:49:55 +01:00
this.storage.readFromNBT(compound);
}
2015-05-20 22:39:43 +02:00
@Override
2015-03-30 15:08:19 +02:00
public void updateEntity(){
super.updateEntity();
2016-11-26 21:32:27 +01:00
if(!this.world.isRemote){
int power = this.getPowerToGenerate(PRODUCE);
2016-11-26 21:32:27 +01:00
if(this.world.isDaytime() && power > 0){
if(power <= this.storage.getMaxEnergyStored()-this.storage.getEnergyStored()){
this.storage.receiveEnergyInternal(power, false);
2015-05-20 22:39:43 +02:00
this.markDirty();
}
}
2015-03-30 15:08:19 +02: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
public int getPowerToGenerate(int power){
2016-11-26 21:32:27 +01:00
for(int y = 1; y <= this.world.getHeight()-this.pos.getY(); y++){
if(power > 0){
BlockPos pos = this.pos.up(y);
2016-11-26 21:32:27 +01:00
IBlockState state = this.world.getBlockState(pos);
if(state.getMaterial().isOpaque()){
power = 0;
}
2016-11-26 21:32:27 +01:00
else if(!state.getBlock().isAir(state, this.world, pos)){
power--;
}
}
else{
break;
2015-12-01 19:48:09 +01:00
}
}
return power;
2015-12-01 19:48:09 +01:00
}
@Override
public CustomEnergyStorage getEnergyStorage(){
return this.storage;
}
@Override
public boolean needsHoldShift(){
return false;
}
@Override
public int getEnergyToSplitShare(){
return this.storage.getEnergyStored();
}
@Override
public boolean doesShareEnergy(){
return true;
}
@Override
public EnumFacing[] getEnergyShareSides(){
return EnumFacing.values();
}
2016-11-26 08:58:42 +01:00
@Override
public IEnergyStorage getEnergyStorage(EnumFacing facing){
return this.storage;
}
2015-03-30 15:08:19 +02:00
}