Made solar panel lose efficiency with transparent blocks above it

Closes #244
This commit is contained in:
Ellpeck 2016-09-17 11:48:25 +02:00
parent 936df5fd5f
commit f89196a701
2 changed files with 21 additions and 11 deletions

View file

@ -11,8 +11,6 @@
package de.ellpeck.actuallyadditions.mod.tile; package de.ellpeck.actuallyadditions.mod.tile;
import cofh.api.energy.EnergyStorage; import cofh.api.energy.EnergyStorage;
import de.ellpeck.actuallyadditions.mod.blocks.BlockFurnaceSolar;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
@ -64,9 +62,10 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements ISharingEn
public void updateEntity(){ public void updateEntity(){
super.updateEntity(); super.updateEntity();
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
if(!this.hasBlockAbove() && this.worldObj.isDaytime()){ int power = this.getPowerToGenerate(PRODUCE);
if(PRODUCE <= this.storage.getMaxEnergyStored()-this.storage.getEnergyStored()){ if(this.worldObj.isDaytime() && power > 0){
this.storage.receiveEnergy(PRODUCE, false); if(power <= this.storage.getMaxEnergyStored()-this.storage.getEnergyStored()){
this.storage.receiveEnergy(power, false);
this.markDirty(); this.markDirty();
} }
} }
@ -77,14 +76,25 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements ISharingEn
} }
} }
public boolean hasBlockAbove(){ public int getPowerToGenerate(int power){
for(int y = 1; y <= this.worldObj.getHeight()-this.pos.getY(); y++){ for(int y = 1; y <= this.worldObj.getHeight()-this.pos.getY(); y++){
IBlockState state = this.worldObj.getBlockState(this.pos.up(y)); if(power > 0){
if(state.getMaterial().isOpaque()){ BlockPos pos = this.pos.up(y);
return true; IBlockState state = this.worldObj.getBlockState(pos);
if(state.getMaterial().isOpaque()){
power = 0;
}
else if(!state.getBlock().isAir(state, this.worldObj, pos)){
power--;
}
}
else{
break;
} }
} }
return false;
return power;
} }
@Override @Override

View file

@ -831,7 +831,7 @@ booklet.actuallyadditions.chapter.coalGen.name=Coal Generator
booklet.actuallyadditions.chapter.coalGen.text.1=The <item>Coal Generator<r> generates <imp><rf> RF/t<r> through the use of everything that can be put into a furnace. <n>Note that it only starts burning something up if there's enough space for the energy generated. booklet.actuallyadditions.chapter.coalGen.text.1=The <item>Coal Generator<r> generates <imp><rf> RF/t<r> through the use of everything that can be put into a furnace. <n>Note that it only starts burning something up if there's enough space for the energy generated.
booklet.actuallyadditions.chapter.solarPanel.name=Solar Panel booklet.actuallyadditions.chapter.solarPanel.name=Solar Panel
booklet.actuallyadditions.chapter.solarPanel.text.1=The <item>Solar Panel<r> <imp>produces <rf> RF/t<r> when it has direct daylight above it and it is daytime. <n><n><i>Panelled walls booklet.actuallyadditions.chapter.solarPanel.text.1=The <item>Solar Panel<r> <imp>produces <rf> RF/t<r> when it has direct daylight above it and it is daytime. Any blocks above it that are transparent will <imp>decrease its efficiency<r>, however. <n><n><i>Panelled walls
booklet.actuallyadditions.chapter.heatCollector.name=Heat Collector booklet.actuallyadditions.chapter.heatCollector.name=Heat Collector
booklet.actuallyadditions.chapter.heatCollector.text.1=The <item>Heat Collector<r> is a block that <imp>produces <rf> RF/t<r>. <n>To do that, it needs to be <imp>surrounded with at least <min> Lava Blocks<r> directly around it on any side except the top one. But watch out, it sometimes <imp>destroys some of these Lava Blocks<r>! booklet.actuallyadditions.chapter.heatCollector.text.1=The <item>Heat Collector<r> is a block that <imp>produces <rf> RF/t<r>. <n>To do that, it needs to be <imp>surrounded with at least <min> Lava Blocks<r> directly around it on any side except the top one. But watch out, it sometimes <imp>destroys some of these Lava Blocks<r>!