Jump to content

Recommended Posts

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!

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!

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

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

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

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