Posted March 12, 20241 yr Say if I want to check if a block has an AGE property, how would that be done with any block? Not an AGE property of a singular block. Specifically if a block even has such a property. Edited March 15, 20241 yr by A tired guy
March 14, 20241 yr BlockState has a .hasProperty() method, so I'd imagine this would work public boolean blockHasAge(BlockState blockState) { return blockState.hasProperty(MyModBlockProperties.AGE); }
March 15, 20241 yr Hm not sure what you're asking for then. Can you give a pseudocode example or explain differently what your intention is here?
March 15, 20241 yr Author As I said in the first message, I want to check if a block even has such type of a property nvm found a solution Quote if(state.getBlock() instanceof BushBlock ) { }
March 15, 20241 yr may you are talking about catching all the AGE declaration even the ones from other mods custom properties ? one would be to check only againts the minecraft BlockStateProperties class Spoiler import net.minecraft.world.level.block.state.properties.BlockStateProperties; // ########## ########## ########## ########## public int get_AGE() { if (this.level > -1) { return this.level; } BlockState blkstate = this.getBlockState(); if (blkstate.hasProperty(BlockStateProperties.AGE_1)) { return blkstate.getValue(BlockStateProperties.AGE_1); } if (blkstate.hasProperty(BlockStateProperties.AGE_2)) { return blkstate.getValue(BlockStateProperties.AGE_2); } if (blkstate.hasProperty(BlockStateProperties.AGE_3)) { return blkstate.getValue(BlockStateProperties.AGE_3); } if (blkstate.hasProperty(BlockStateProperties.AGE_4)) { return blkstate.getValue(BlockStateProperties.AGE_4); } if (blkstate.hasProperty(BlockStateProperties.AGE_5)) { return blkstate.getValue(BlockStateProperties.AGE_5); } if (blkstate.hasProperty(BlockStateProperties.AGE_7)) { return blkstate.getValue(BlockStateProperties.AGE_7); } if (blkstate.hasProperty(BlockStateProperties.AGE_15)) { return blkstate.getValue(BlockStateProperties.AGE_15); } if (blkstate.hasProperty(BlockStateProperties.AGE_25)) { return blkstate.getValue(BlockStateProperties.AGE_25); } return -1; } the other would be dirt your hands on the nbt data of the block and check if it have a string whit same name // ########## public String print() { BlockState blkstate = this.getBlockState(); String json = ""; //int id = Block.getId(blkstate); String propiedades = ""; for (Property<?> porp : blkstate.getProperties()) { System.out.println(porp.getName() + " -> " + blkstate.getValue(porp)); propiedades += String.format( ",\"%1$s\":\"%2$s\"", porp.getName(), blkstate.getValue(porp) ); } json = String.format("{\"blockname\":\"%1$s\",\"x\":\"%2$s\",\"y\":\"%3$s\",\"z\":\"%4$s\"%5$s}", this.get_blkfullname(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), propiedades ); //System.out.println("\n" + json + "\n" ); return json; }
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.