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

Good days

Broken english alert!

 

iM trying to fix mi chainsaw item for that i need to identified the target blocks

 

i need to identified the log blocks from the tree but i don't wanna break Plank blocks or any other block by mistake

so i can't use Material  blkstate.getMaterial()

 

in the old time i just do something like

	           for( int l = 0 ; l < list9.size() ; l ++){
	                xpos = ypos.add(list9.get(l));
                xbst = this.world.getBlockState(xpos);
                xblk = xbst.getBlock();
                
                Block logblk1 = Blocks.LOG;
	                Block logblk2 = Blocks.LOG2;
     
	               // i remember doing it this way long time ago
	                //but now throw error    Blocks.LOG cannot be resolved to a type,    blockLog is not instanciable anymore ??
                if( xblk instanceof  Blocks.LOG || xblk instanceof  Blocks.LOG2 ){
                    System.out.println( "Is definitively a log block ="+xpos);
                }
	 
	                 if(  xbst.getMaterial() == Material.LEAVES){
                    System.out.println( "Is a leaves block ="+xpos);
                }
	 
	                 if(  xbst.getMaterial() == Material.WOOD){
                    System.out.println( "could be a log a fence a door or any other block made of wood ="+xpos);
                }
	}
	

Edited by perromercenary00

There are methods in the Block class for exactly this purpose: Block#isLeaves and Block#isWood. These return true if the block is leaves or a log, respectively.

 

The right-hand operand of instanceof must be a type, but Blocks.LOG and Blocks.LOG2 aren't types, they're values. This is basic Java knowledge.

 

Blocks.LOG is an instance of the BlockOldLog type and Blocks.LOG2 is an instance of the BlockNewLog type, these both extend BlockLog.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

thansk for answering

 

but its little odd that is working

xblk.isWood(world, xpos)  is true only if the block is log

but is false if the block is  door fence ladder or plank

 

anyway  thats is exactly what i need

 

	            ArrayList<BlockPos> list9 = new ArrayList<BlockPos>();
	                       
            list9.add( new BlockPos(  1,0,-1 ));
            list9.add( new BlockPos(  1,0,0  ));
            list9.add( new BlockPos(  1,0,1  ));
            
            list9.add( new BlockPos(  0,0,-1 ));
            list9.add( new BlockPos(  0,0,0  ));
            list9.add( new BlockPos(  0,0,1  ));
            
            list9.add( new BlockPos( -1,0,-1 ));
            list9.add( new BlockPos( -1,0,0  ));
            list9.add( new BlockPos( -1,0,1  ));
	 
	            for( int l = 0 ; l < list9.size() ; l ++){
            
                xpos = ypos.add(list9.get(l));
                xbst = this.world.getBlockState(xpos);
                xblk = xbst.getBlock();
                               
                if( xblk.isWood(world, xpos) ){
                    System.out.println("Tronco ="+xpos);
                    troncos.add(xpos);
                }                
                
                if( xblk.isLeaves(xbst, world, xpos) ){
                    System.out.println("hojas ="+xpos);
                    hojas.add(xpos);
                }
          
            }
	

The doc comment for Block#isWood says that it returns "true if the block is wood (logs)", it's not meant to check for other types of wooden blocks. The name could probably be clearer, though.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.