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

Hi,

 

I'm wondering how the fence actually checks if it should connect to another fence or not.

 

I know the fence class got these methods which are beeing called in getActualState

    private boolean canFenceConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing)
    {
        Block block = world.getBlockState(pos.offset(facing)).getBlock();
        return block.canBeConnectedTo(world, pos.offset(facing), facing.getOpposite()) || canConnectTo(world, pos.offset(facing));
    }

    public boolean canConnectTo(IBlockAccess worldIn, BlockPos pos)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        return block == Blocks.BARRIER ? false : ((!(block instanceof BlockFence) || block.blockMaterial != this.blockMaterial) && !(block instanceof BlockFenceGate) ? (block.blockMaterial.isOpaque() && iblockstate.isFullCube() ? block.blockMaterial != Material.GOURD : false) : true);
    }

 

My problem is that I don't really get how those methods work, for example the statement if the block is not an instanceof BlockFence. Wouldn't this cause the fence to not be 

able to connect to any other fence??

 

Thx in advance.

Bektor

Edited by Bektor

Developer of Primeval Forest.

So, fence block has these boolean properties:

	/** Whether this fence connects in the northern direction */
    public static final PropertyBool NORTH = PropertyBool.create("north");
    /** Whether this fence connects in the eastern direction */
    public static final PropertyBool EAST = PropertyBool.create("east");
    /** Whether this fence connects in the southern direction */
    public static final PropertyBool SOUTH = PropertyBool.create("south");
    /** Whether this fence connects in the western direction */
    public static final PropertyBool WEST = PropertyBool.create("west");

And in

public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
    {
        return state.withProperty(NORTH, canFenceConnectTo(worldIn, pos, EnumFacing.NORTH))
                    .withProperty(EAST,  canFenceConnectTo(worldIn, pos, EnumFacing.EAST))
                    .withProperty(SOUTH, canFenceConnectTo(worldIn, pos, EnumFacing.SOUTH))
                    .withProperty(WEST,  canFenceConnectTo(worldIn, pos, EnumFacing.WEST));
    }

"canFenceConnectTo()" returns a boolean which is passed to "withProperty()" method and appropriate bounding boxes are added or removed when a neighbor block changes.

  • Author
23 minutes ago, Alexiy said:

"canFenceConnectTo()" returns a boolean which is passed to "withProperty()" method and appropriate bounding boxes are added or removed when a neighbor block changes.

Thats as far as I got, but how does the inner of those methods work:

 

1 hour ago, Bektor said:

for example the statement if the block is not an instanceof BlockFence. Wouldn't this cause the fence to not be 

able to connect to any other fence??

 

Meaning the inner parts of the canFenceConnectTo and canConnectTo etc. methods.

Developer of Primeval Forest.

Quote

...the statement if the block is not an instanceof BlockFence. Wouldn't this cause the fence to not be able to connect to any other fence?

 

Read the trinary expression again VERY carefully so you understand the RESULT of each logical subexpression. If that doesn't give you an aha moment, then run it in the debugger so you can step it. If necessary, write your own nested if-then-else statements to break it down to where you can grasp it.

Edited by jeffryfisher

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.

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.