Jump to content

[1.7.10] onNeighborBlockChange() method question


Thornack

Recommended Posts

inside the onNeighborBlockChange(World world, int posX, int posY, int posZ, Block neighbourBlock) method, inside the Block Door class there are the following if statements. I have been trying to figure out what they do by breaking the code so that I can understand the door class better and how doors work. But if i remove these methods completely I dont seem to get any noticeable change. Does anyone know what these if statements do?/why are they used

 

if (world.getBlock(posX, posY + 1, posZ) != this)

            {

                world.setBlockToAir(posX, posY, posZ);

                flag = true;

            }

 

            if (!World.doesBlockHaveSolidTopSurface(world, posX, posY - 1, posZ))

            {

                world.setBlockToAir(posX, posY, posZ);

                flag = true;

 

                if (world.getBlock(posX, posY + 1, posZ) == this)

                {

                    world.setBlockToAir(posX, posY + 1, posZ);

                }

            }

Link to comment
Share on other sites

Its how the bottom half of the door functions.  If the top half doesn't exist ("block above me is not also a door") then it sets itself to air (breaking the door).

Secondly, if the block below itself is not solid on top, it also breaks the door.

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.

Link to comment
Share on other sites

awesome thanks! But I am confused about one other thing in this method. there is a flag and i have no idea what this flag does

boolean flag1 = world.isBlockIndirectlyGettingPowered(posX, posY, posZ) || world.isBlockIndirectlyGettingPowered(posX , posY + 1, posZ);

I know that if this flag is true the method calls a function that I suspect opens the door. But I am not sure what exactly is happening here. I know that the isBlockIndirectlyGettingPowered method checks whether any adjacent block is recieving power. but I played around with this and tried 

boolean flag1 = world.isBlockIndirectlyGettingPowered(posX, posY, posZ) || world.isBlockIndirectlyGettingPowered(posX +3, posY , posZ); 

and a block 3 blocks away in the X direction and nothing happened. (I even powered all the blocks in a square and still the door didnt open so i must have my understanding of what is going on here messed up.

 

 

Link to comment
Share on other sites

That should be the door is powered / not powered so open/close the door.  The flag is telling it to run another function, so just because you powered that block over there doesn't mean the door will open: that other function may also check for power.

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.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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