Jump to content

Block method differences: updatePostPlacement, onNeighborChange, neighborChanged


Recommended Posts

Posted

There are 3 methods which sound like they do something very similar, overridden by various different blocks:

 

  • updatePostPlacement is used to make connections with adjacent blocks (fences/walls).
/**
* Update the provided state given the provided neighbor facing and neighbor state, returning a new state.
* For example, fences make their connections to the passed in state if possible, and wet concrete powder immediately
* returns its solidified counterpart.
* Note that this method should ideally consider only the specific face passed in.
*/
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos)
  • neighborChanged appears to be used for detecting redstone changes (or water in the case of sponge)
// No Javadoc
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving)
  • And the forge-added onNeighborChange is called from World#updateComparatorOutputLevel:
/**
* Called when a tile entity on a side of this block changes is created or is destroyed.
* @param world The world
* @param pos Block position in world
* @param neighbor Block position of neighbor
*/
default void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor)

My question is which method should be overridden for what purpose, as many of the call paths are similar. I have spent quite a bit of time trying to trace the call paths and have become lost multiple times.

I was using neighborChanged, but switched to using updatePostPlacement (as that already supplies the direction, and sounds more like what I needed (making connections between blocks)). The effect in-game did not change, so I am wondering when I should be using each of these methods.

 

There is also the following forge-added method, which doesn't appear to be overridden anywhere, and is only called by the blockstate method of the same name, which is itself not called:

/**
* Called on an Observer block whenever an update for an Observer is received.
*
* @param observerState The Observer block's state.
* @param world The current world.
* @param observerPos The Observer block's position.
* @param changedBlock The updated block.
* @param changedBlockPos The updated block's position.
*/
default void observedNeighborChange(BlockState observerState, World world, BlockPos observerPos, Block changedBlock, BlockPos changedBlockPos)

 

Posted

So here's my understanding (assuming all positions are loaded):

updatePostPlacement - Connections of a block with adjacent block called for all directions given a face.

neighborChanged - Connections of a block with the adjacent block called for all directions (doesn't rely on a specific face).

onNeighborChange - Connections of a tile entity with the adjacent block for all directions (doesn't rely on a specific face).

observedNeighborChange - Probably a misaligned patch when ported but was originally used for observer updates.

 

So the difference is mainly that updatePostPlacement are used for changing the state of a block in most cases. neighborChanged is for changing the block state that doesn't rely on a specific situation based on the specific block face. Then onNeighborChange is the tile entity version of neighborChanged.

Posted

Slight correction, based on my understanding:

updatePostPlacement - called immediately after the player places the block in order to check to see if any state change should occur based on neighbors. (Eg. placing concrete powder next to existing water)

neighborChanged onNeighborChange - called when a neighbor changes state in order to see if any state change is necessary. (Eg. water flows into the space next to concrete powder)

observedNeighborChange - specific to the observer block, but similar to neighborChanged. I haven't messed with it.

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.