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.

1.14.4 Notifying block change on tree grow

Featured Replies

Posted

Hey there

I have a problem with generating trees with branches. Branch block has 6 states - for all directions (true/false). Tree is growing from added "schematic" file, and also rotating. And when it rotates, branch blocks don't know that and they stay connected for example to air. That shouldn't happen. So, is there any option to notify the neightbours when the block is placing? Using IWorld.
 

Branch block - when notified
 

Spoiler

@Override
public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) {
    IFluidState ifluidstate = worldIn.getFluidState(pos);
    BlockPos blockpos1 = pos.north();
    BlockPos blockpos2 = pos.east();
    BlockPos blockpos3 = pos.south();
    BlockPos blockpos4 = pos.west();
    BlockPos blockpos5 = pos.up();
    BlockPos blockpos6 = pos.down();
    BlockState blockstate = worldIn.getBlockState(blockpos1);
    BlockState blockstate1 = worldIn.getBlockState(blockpos2);
    BlockState blockstate2 = worldIn.getBlockState(blockpos3);
    BlockState blockstate3 = worldIn.getBlockState(blockpos4);
    BlockState blockstate4 = worldIn.getBlockState(blockpos5);
    BlockState blockstate5 = worldIn.getBlockState(blockpos6);
    boolean flag = this.func_220113_a(blockstate, blockstate.func_224755_d(worldIn, blockpos1, Direction.SOUTH), Direction.SOUTH);
    boolean flag1 = this.func_220113_a(blockstate1, blockstate1.func_224755_d(worldIn, blockpos2, Direction.WEST), Direction.WEST);
    boolean flag2 = this.func_220113_a(blockstate2, blockstate2.func_224755_d(worldIn, blockpos3, Direction.NORTH), Direction.NORTH);
    boolean flag3 = this.func_220113_a(blockstate3, blockstate3.func_224755_d(worldIn, blockpos4, Direction.EAST), Direction.EAST);
    boolean flag4 = this.func_220113_a(blockstate4, blockstate4.func_224755_d(worldIn, blockpos5, Direction.UP), Direction.UP);
    boolean flag5 = this.func_220113_a(blockstate5, blockstate5.func_224755_d(worldIn, blockpos6, Direction.DOWN), Direction.DOWN);
    worldIn.setBlockState(pos, this.getDefaultState().with(UP, Boolean.valueOf(flag4)).with(DOWN, Boolean.valueOf(flag5)).with(NORTH, Boolean.valueOf(flag)).with(EAST, Boolean.valueOf(flag1)).with(SOUTH, Boolean.valueOf(flag2)).with(WEST, Boolean.valueOf(flag3)).with(WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER)));

}

"Schematic" file:

Spoiler


    @Override
    public Set<BlockPos> setBlocks() {
Block(-1,1,-1,"wildnature:mahogany_leaves[distance=7,persistent=true]");
Block(0,1,-1,"wildnature:mahogany_leaves[distance=7,persistent=true]");
Block(0,1,0,"wildnature:mahogany_branch");
Block(-1,2,0,"wildnature:mahogany_leaves[distance=7,persistent=true]");
Block(0,2,0,"wildnature:mahogany_branch");
Block(1,2,0,"wildnature:mahogany_leaves[distance=7,persistent=true]");
Block(0,3,0,"wildnature:mahogany_leaves[distance=7,persistent=true]");
Block(1,3,0,"wildnature:mahogany_leaves[distance=7,persistent=true]");
Block(1,1,1,"wildnature:mahogany_leaves[distance=7,persistent=true]");
Block(0,2,1,"wildnature:mahogany_leaves[distance=7,persistent=true]");
Block(-3,0,3,"minecraft:dirt");

//   wildnature mod
//           created by matez 
//         all rights reserved   
//     http://bit.ly/wildnature-mod
return super.setBlocks();
    }

SchemFeature class(when tree growing)
 

Spoiler

@Override
protected boolean place(Set<BlockPos> changedBlocks, IWorldGenerationReader worldIn, Random rand, BlockPos position, MutableBoundingBox p_208519_5_) {
    if(!isSoil(worldIn, position.down(), getSapling())){
        return false;
    }

    this.world=(IWorld)worldIn;
    this.startBlockPos=position;
    this.random=rand;
    rotation= MathCalc.rint(1,4,rand);
    setBlocks();
    //setAddionalBlocks();
    return true;
}

Block() method (placing blocks)
 

Spoiler

public void Block(int x, int y, int z, BlockState state){
    BlockPos pos = startBlockPos;
    int sx = startBlockPos.getX();
    int sy = startBlockPos.getY()-1;
    int sz = startBlockPos.getZ();
    if(rotation>=1 && rotation<=4){
        if(rotation==1){
            pos = new BlockPos(x+sx,y+sy,z+sz);//north
        }else if(rotation==2){
            pos = new BlockPos(-x+sx,y+sy,-z+sz);//south
        }else if (rotation==3){
            pos = new BlockPos(z+sx,y+sy,x+sz);
        }else{
            pos = new BlockPos(-z+sx,y+sy,-x+sz);
        }
    }else{
        throw new IllegalArgumentException("Unknown rotation for tree at " + startBlockPos.toString() + " :\nrotation = " + rotation + " (1-4)\n   Please report it to author!");
    }

    //world.setBlockState(pos, state, 2);
    //setBlockState(world,pos,state);
    if(state.getBlock() instanceof BranchBase){
        addionalBlocks.add(new BlockStatePos(state,pos));
    }
    world.setBlockState(pos,state,19);
    addedBlocks.add(pos);
}

world.setBlockState flags seems not working

Please help!

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.