add isSunVisible and canSeeSky to the geolyzer

this is a potential solution to robots that need to know if their solar panels are able to charge
if a geolyzer is also added to a robot, it can use the geolyzer component to check for charge options

issue #1778 specifically asked for similar api on the solar upgrade, but we didn't want to make the solar upgrade a component. Doing so would increase the component load of existing robots, which could cause existing robots to simply fail.

thus this is a compromise to that request

closes #1778
This commit is contained in:
payonel 2018-03-17 20:46:30 -07:00
parent 4a83d4426d
commit 8cac5dfcd3

View File

@ -26,6 +26,7 @@ import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.world.biome.BiomeGenDesert
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.common.util.ForgeDirection
@ -51,6 +52,25 @@ class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment with
// ----------------------------------------------------------------------- //
private def canSeeSky: Boolean = {
val blockPos = BlockPosition(host).offset(ForgeDirection.UP)
!host.world.provider.hasNoSky && host.world.canBlockSeeTheSky(blockPos.x, blockPos.y, blockPos.z)
}
@Callback(doc = """function():boolean -- Returns whether there is a clear line of sight to the sky directly above.""")
def canSeeSky(computer: Context, args: Arguments): Array[AnyRef] = {
result(canSeeSky)
}
@Callback(doc = """function():boolean -- Return whether the sun is currently visible directly above.""")
def isSunVisible(computer: Context, args: Arguments): Array[AnyRef] = {
val blockPos = BlockPosition(host).offset(ForgeDirection.UP)
result(
host.world.isDaytime &&
canSeeSky &&
(host.world.getWorldChunkManager.getBiomeGenAt(blockPos.x, blockPos.z).isInstanceOf[BiomeGenDesert] || (!host.world.isRaining && !host.world.isThundering)))
}
@Callback(doc = """function(x:number, z:number[, y:number, w:number, d:number, h:number][, ignoreReplaceable:boolean|options:table]):table -- Analyzes the density of the column at the specified relative coordinates.""")
def scan(computer: Context, args: Arguments): Array[AnyRef] = {
val (minX, minY, minZ, maxX, maxY, maxZ, optIndex) = getScanArgs(args)