Block properties

Started by steven.cgl on

Topic category: Help with MCreator software

Joined Dec 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Block properties

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?

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could use Blockstates…
Wed, 12/14/2022 - 22:14

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:

  1. Download & install Blockstates Plugin here.
  2. Then after you installed the Plugin open your Keycard Reader and adds this line to use Integer Blockstates:
    1. import net.minecraft.world.level.block.state.properties.IntegerProperty;
  3. Next add this line to create a new Integer Property/Blockstate:
    1. 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.
  4. Add this line inside the block default values( you'll probably need only add the .addValue for it):
    1. 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)
  5. The last thing in the code you will need this line:
    1. @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.
  6. Now it is done. Then change every Procedure that need to get the Keycard Levels etc. replace with the Procedure Block "Set Integer Property"(Block management Category) and "Get Integer Property"(Block Data Category) and use the name in the quotation marks at Step 3 in the Procedure Blocks.

If you need help just reply your issue here :)