Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm attempting to use canBlockSeeSky() from the World class. However, it will only return false. Is there something else that I should be using to check if a block can see the sky?

 

This is being done in the tile entity for the block. Perhaps I should be doing this check else where?

 

 

import com.tikaji.powerpylons.types.GeneratorType;

import com.tikaji.powerpylons.utility.LogHelper;

 

public class TileEntitySolarGenerator extends TileEntityGenerator

{

public TileEntitySolarGenerator()

{

super(GeneratorType.SOLAR);

}

 

@Override

public void update()

{

if (!worldObj.isRemote)

{

if (worldObj.isDaytime())

{

LogHelper.info(worldObj.canBlockSeeSky(pos));

if (worldObj.canSeeSky(pos))

{

LogHelper.info("GOT HERE");

storage.modifyEnergyStored(type.getGenerationRate());

LogHelper.info("ENERGY: " + storage.getEnergyStored());

}

}

}

}

}

 

 

 

If you need anything else to help diagnose the problem, please ask.

 

And thanks for any help!

  • Author

I'm attempting to use canBlockSeeSky() from the World class. However, it will only return false. Is there something else that I should be using to check if a block can see the sky?

 

This is being done in the tile entity for the block. Perhaps I should be doing this check else where?

 

 

import com.tikaji.powerpylons.types.GeneratorType;

import com.tikaji.powerpylons.utility.LogHelper;

 

public class TileEntitySolarGenerator extends TileEntityGenerator

{

public TileEntitySolarGenerator()

{

super(GeneratorType.SOLAR);

}

 

@Override

public void update()

{

if (!worldObj.isRemote)

{

if (worldObj.isDaytime())

{

LogHelper.info(worldObj.canBlockSeeSky(pos));

if (worldObj.canSeeSky(pos))

{

LogHelper.info("GOT HERE");

storage.modifyEnergyStored(type.getGenerationRate());

LogHelper.info("ENERGY: " + storage.getEnergyStored());

}

}

}

}

}

 

 

 

If you need anything else to help diagnose the problem, please ask.

 

And thanks for any help!

Do the check from pos.up() instead.  The method looks at the block at pos and if it is not transparent, it return false.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Do the check from pos.up() instead.  The method looks at the block at pos and if it is not transparent, it return false.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

That would do it! Thank you for that! I just assumed that this function took this into account, guess not.

  • Author

That would do it! Thank you for that! I just assumed that this function took this into account, guess not.

That would do it! Thank you for that! I just assumed that this function took this into account, guess not.

 

Nope.  It assumes that the block pos being checked must itself be transparent.  I'm sure there's a good reason (it makes sense after the fact, but as for the decision process, I am not sure).

 

Was something I discovered myself back in 1.7.10

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

That would do it! Thank you for that! I just assumed that this function took this into account, guess not.

 

Nope.  It assumes that the block pos being checked must itself be transparent.  I'm sure there's a good reason (it makes sense after the fact, but as for the decision process, I am not sure).

 

Was something I discovered myself back in 1.7.10

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Here's how BlockGrass did its updateTick in 1.8 (several dot-up calls, but using neighbor light instead of seeing sky for some reason):

 

   public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (!worldIn.isRemote)
        {
            if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getBlock().getLightOpacity(worldIn, pos.up()) > 2)
            {
                worldIn.setBlockState(pos, Blocks.dirt.getDefaultState());
            }
            else
            {
                if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
                        Block block = worldIn.getBlockState(blockpos1.up()).getBlock();
                        IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);

                        if (iblockstate1.getBlock() == Blocks.dirt && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos1.up()) >= 4 && block.getLightOpacity(worldIn, blockpos1.up()) <= 2)
                        {
                            worldIn.setBlockState(blockpos1, Blocks.grass.getDefaultState());
                        }
                    }
                }
            }
        }
    }

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Here's how BlockGrass did its updateTick in 1.8 (several dot-up calls, but using neighbor light instead of seeing sky for some reason):

 

   public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
    {
        if (!worldIn.isRemote)
        {
            if (worldIn.getLightFromNeighbors(pos.up()) < 4 && worldIn.getBlockState(pos.up()).getBlock().getLightOpacity(worldIn, pos.up()) > 2)
            {
                worldIn.setBlockState(pos, Blocks.dirt.getDefaultState());
            }
            else
            {
                if (worldIn.getLightFromNeighbors(pos.up()) >= 9)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        BlockPos blockpos1 = pos.add(rand.nextInt(3) - 1, rand.nextInt(5) - 3, rand.nextInt(3) - 1);
                        Block block = worldIn.getBlockState(blockpos1.up()).getBlock();
                        IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);

                        if (iblockstate1.getBlock() == Blocks.dirt && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT && worldIn.getLightFromNeighbors(blockpos1.up()) >= 4 && block.getLightOpacity(worldIn, blockpos1.up()) <= 2)
                        {
                            worldIn.setBlockState(blockpos1, Blocks.grass.getDefaultState());
                        }
                    }
                }
            }
        }
    }

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

(several dot-up calls, but using neighbor light instead of seeing sky for some reason)

 

Light values are cached, seeing sky requires iterating over the entire column of blocks to make sure they are all air/non-solid.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

(several dot-up calls, but using neighbor light instead of seeing sky for some reason)

 

Light values are cached, seeing sky requires iterating over the entire column of blocks to make sure they are all air/non-solid.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.