Jump to content

[1.12.x/1.11.x] [SOLVED] Fence connection


Bektor

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
  • Like 1

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.

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.

Announcements



×
×
  • Create New...

Important Information

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