Jump to content

Is there still a way to check if a block has visibility to the sky[1.7.2]


Recommended Posts

Posted

Pretty much a solar pannel, I need to be able to check if its day, and if it has visibility to the sky, I looked through the block class and did not find any thing interesting.

 

Thanks,

 

-gmod622

Not new to java >> New to modding.

Posted

i would say take the blocks xyz pos, and see if there are any blocks on above the block on the y axis, from the blocks y pos to 256, i would also reccomend passing through glass and other transparent blocks. For example.

while(int y = yPos; y <=256; y++)
{
    if((world.getBlockatCoords(xPos,y,zPos) != null) || (world.getBlockatCoords(xPos,y,zPos) != Blocks.glass))
    {
         skyVisible = false;
    }
}

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

i would say take the blocks xyz pos, and see if there are any blocks on above the block on the y axis, from the blocks y pos to 256, i would also reccomend passing through glass and other transparent blocks. For example.

while(int y = yPos; y <=256; y++)
{
    if((world.getBlockatCoords(xPos,y,zPos) != null) || (world.getBlockatCoords(xPos,y,zPos) != Blocks.glass))
    {
         skyVisible = false;
    }
}

 

The method is getBlock(x, y, z) and the null check is useless. Blocks.air is returned in any case other than a regular block.

Posted

I use this for my solar furnace.

 

 public static boolean sunIsVisible = false;
    
    /**
     * Checks if the specified block is able to see the sky
     */
    public void updateSunVisibility()
    {
      this.sunIsVisible = isSunVisible(this.worldObj, this.xCoord, this.yCoord + 1, this.zCoord);
    }
    
    public static boolean isSunVisible(World world, int x, int y, int z)
    {
      return (world.isDaytime()) && (!world.provider.hasNoSky) && (world.canBlockSeeTheSky(x, y, z)) && (((world.getWorldChunkManager().getBiomeGenAt(x, z) instanceof BiomeGenDesert)) || ((!world.isRaining()) && (!world.isThundering())));
    }
    
     
  

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.