Jump to content

Recommended Posts

Posted (edited)

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
Posted

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.

Posted

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);
                }
          
            }
	

Posted

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...

×   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.