Posted November 15, 20195 yr Hi I have extended the vanilla BubbleColumn.java in order to add some special behaviours such as allowing blocks with a tag and can be waterlogged to retain the bubble column structure when intersecting. Blocks with this tag while waterlogged does not block bubble columns. Bubble Column is a block with the property DRAG. If true (Magma Block) it drags the player down to the bottom and false (Soul Sand) does the opposite and pushes the player to the surface. BubbleColumn.java public class BlockBubbleColumn extends BubbleColumnBlock { public static final ResourceLocation transparentID = new ResourceLocation(Reference.MODID,"bubble_column_transparent_blocks"); public BlockBubbleColumn(String name, Block.Properties properties) { super(properties); setRegistryName(name); } @Override public boolean isValidPosition(BlockState state, IWorldReader worldIn, BlockPos pos) { Block block = worldIn.getBlockState(pos.down()).getBlock(); return canTransfer(block,worldIn.getBlockState(pos.down())) || block == IntercraftBlocks.VANILLA_BUBBLE_COLUMN || block == Blocks.SOUL_SAND || block == Blocks.MAGMA_BLOCK; } @Override public void onBlockAdded(BlockState state, World worldIn, BlockPos pos, BlockState oldState, boolean isMoving) { BlockState blockState = worldIn.getBlockState(pos.down()); boolean drag; if (canTransfer(blockState.getBlock(),blockState)) { BlockPos p = getNextValidDragPosDown(worldIn,pos.down()); if (p == null) return; else drag = getDrag(worldIn,p); System.out.println(String.format("Block under it has drag %s",drag)); } else drag = getDrag(worldIn,pos.down()); System.out.println(String.format("Drag is %s",drag)); placeBubbleColumn(worldIn, pos.up(), drag); //placeBubbleColumn(worldIn, pos.up(), getDrag(worldIn, pos.down())); } @Override public void tick(BlockState state, World worldIn, BlockPos pos, Random random) { BlockState blockState = worldIn.getBlockState(pos.up()); if (canTransfer(blockState.getBlock(),blockState)) { BlockPos p = getNextValidDragPosUp(worldIn,pos); if (p != null) placeBubbleColumn(worldIn, p, getDrag(worldIn, pos)); } else placeBubbleColumn(worldIn, pos.up(), getDrag(worldIn,pos)); //placeBubbleColumn(worldIn, pos.up(), getDrag(worldIn, pos)); } private static BlockPos getNextValidDragPosUp(IBlockReader reader, BlockPos pos) { BlockPos p; int y = 1; while (reader.getHeight()>pos.getY()+y) { p = pos.up(y); Block block = reader.getBlockState(p).getBlock(); if ( block == IntercraftBlocks.VANILLA_BUBBLE_COLUMN ) { System.out.println(block.getRegistryName().getPath()); System.out.println(p.toString()); return p; } y++; } return null; } private static BlockPos getNextValidDragPosDown(IBlockReader reader, BlockPos pos) { BlockPos p; int y = 1; while (0<pos.getY()-y) { p = pos.down(y); Block block = reader.getBlockState(p).getBlock(); if ( block == IntercraftBlocks.VANILLA_BUBBLE_COLUMN || block == Blocks.SOUL_SAND || block == Blocks.MAGMA_BLOCK ) { System.out.println(block.getRegistryName().getPath()); System.out.println(p.toString()); return p; } y++; } return null; } private static boolean getDrag(IBlockReader blockReader, BlockPos pos) { BlockState blockstate = blockReader.getBlockState(pos); Block block = blockstate.getBlock(); if (block == IntercraftBlocks.VANILLA_BUBBLE_COLUMN || block == Blocks.BUBBLE_COLUMN) { return blockstate.get(DRAG); } else { return block != Blocks.SOUL_SAND; } } private static boolean canTransfer(Block block, BlockState state) { return (BlockTags.getCollection().getOrCreate(transparentID).contains(block) && getWaterLogged(state)); } private static boolean getWaterLogged(BlockState state) { return state.has(WATERLOGGED) ? state.get(WATERLOGGED) : false; } } The idea is to allow this to work with a lot of blocks without having to add extra properties to them, so my plan was to instead of reading the block below, look if it is Bubble Column, Soul Sand or Magma Block and otherwise look for the closest valid column block to continue the pillar. I have narrowed it down to three functions that control this; isValidPosition, onBlockAdded and tick. The problem right now is probably a logic error, but I can't figure it out. From the values I print out it first succeeds in setting the correct value, but the rest does not read the previous block's data and then the first blocks' data is changed to the incorrect value. This example I'm expecting them all to be false, but this is what it prints out and then in-game they all are true: [19:50:18] [Server thread/INFO] [STDOUT/]: [net.intercraft.intercraftcore.block.BlockBubbleColumn:getNextValidDragPosDown:121]: bubble_column [19:50:18] [Server thread/INFO] [STDOUT/]: [net.intercraft.intercraftcore.block.BlockBubbleColumn:getNextValidDragPosDown:122]: BlockPos{x=-5, y=96, z=148} [19:50:18] [Server thread/INFO] [STDOUT/]: [net.intercraft.intercraftcore.block.BlockBubbleColumn:onBlockAdded:55]: Block under it has drag false [19:50:18] [Server thread/INFO] [STDOUT/]: [net.intercraft.intercraftcore.block.BlockBubbleColumn:onBlockAdded:62]: Drag is false [19:50:18] [Server thread/INFO] [STDOUT/]: [net.intercraft.intercraftcore.block.BlockBubbleColumn:onBlockAdded:62]: Drag is true [19:50:18] [Server thread/INFO] [STDOUT/]: [net.intercraft.intercraftcore.block.BlockBubbleColumn:onBlockAdded:62]: Drag is true [19:50:18] [Server thread/INFO] [STDOUT/]: [net.intercraft.intercraftcore.block.BlockBubbleColumn:onBlockAdded:62]: Drag is true
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.