Started by
steven.cgl
on
Topic category: Help with MCreator software
I'm making a keycard reader and when right-clicked with the wrench tool it changes its level from 1 to 5 (if 5 then cycles back to 1), but i don't understand how to make the level became a block property to be seen in F3 or to be directly placed through /setblock command (for instance /setblock x y z lab:keycard_reader[level=2]). Someone knows how to help me?
You could use Blockstates that it implemented through custom coding inside of your block with an specific range between 1 to 5 and then you can just changing the blockstates via procedure blocks.
Then you just need to check if the Keycard level matches the blockstate value.
Here is an little tutorial:
import net.minecraft.world.level.block.state.properties.IntegerProperty;
public static final IntegerProperty EXAMPLE_NUMBER_BLOCKSTATE = IntegerProperty.create("your_blockstate_name_here", minimum_value, maximum_value);
Replace EXAMPLE_NUMBER_BLOCKSTATE to your Blockstate Level e.g. SECURITY_LEVEL. And change the name inside the quotation marks to an lowercase name e.g. security_level. The name inside the quotation marks is the name that you will need to type inside the blockstate Procedure Blocks. The minimum_value is should be 1 and maximum_value should be 5 in your case. And that's the range of your blockstate value.this.registerDefaultState(this.stateDefinition.any()
.setValue(EXAMPLE_BLOCKSTATE, blockstate_default_value_here)
);
There change EXAMPLE_BLOCKSTATE to the name you specified above and then change blockstate_default_value_here with the default value(it should be 1 xD)@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(EXAMPLE_BLOCKSTATE);
}
EXAMPLE_BLOCKSTATE need to be the exact name of EXAMPLE_NUMBER_BLOCKSTATE at Step 3.If you need help just reply your issue here :)