Posted October 8, 20178 yr 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 October 9, 20178 yr by Bektor Developer of Primeval Forest.
October 8, 20178 yr 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.
October 8, 20178 yr 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.
October 8, 20178 yr 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 October 8, 20178 yr 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.