From 8cac5dfcd315d1489428c0eabb8c1908ebafd610 Mon Sep 17 00:00:00 2001 From: payonel Date: Sat, 17 Mar 2018 20:46:30 -0700 Subject: [PATCH] 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 --- .../li/cil/oc/server/component/Geolyzer.scala | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/scala/li/cil/oc/server/component/Geolyzer.scala b/src/main/scala/li/cil/oc/server/component/Geolyzer.scala index 2f5c0f2f1..5d2cd9fde 100644 --- a/src/main/scala/li/cil/oc/server/component/Geolyzer.scala +++ b/src/main/scala/li/cil/oc/server/component/Geolyzer.scala @@ -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)