perromercenary00 Posted April 23, 2017 Posted April 23, 2017 (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 April 23, 2017 by perromercenary00 Quote
Choonster Posted April 23, 2017 Posted April 23, 2017 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. Quote 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.
perromercenary00 Posted April 23, 2017 Author Posted April 23, 2017 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); } } Quote
Choonster Posted April 23, 2017 Posted April 23, 2017 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. Quote 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.
Recommended Posts
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.