User Tools

Site Tools


tutorial:blockstate

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:blockstate [2021/07/18 03:06] – The function which the old article was using, getHardness(), was incorrect. I changed what the blockstates did and how they did them. Instead of changing the hardness, I changed the "charge" value, which summons lightning. tsunaminaltutorial:blockstate [2021/07/23 18:02] – Fixed typos fireblast
Line 42: Line 42:
     public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {     public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
         player.playSound(SoundEvents.BLOCK_RESPAWN_ANCHOR_CHARGE, 1, 1);         player.playSound(SoundEvents.BLOCK_RESPAWN_ANCHOR_CHARGE, 1, 1);
-        world.setBlockState(pos, state.with(ACTIVATED, true));+        world.setBlockState(pos, state.with(CHARGED, true));
         return ActionResult.SUCCESS;         return ActionResult.SUCCESS;
     }     }
Line 48: Line 48:
 </code> </code>
  
- +And Finally, to use the ''CHARGED'' property, we call ''onSteppedOn'', with ''world.getBlockState(pos).get(CHARGED)'' inside of it:
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
- +
-And Finally, to use the ''CHARGED'' property, we call ''onSteppedOn'', with ''world.getBlockState(pos).get(ACTIVATED)'' inside of it:+
 <code java> <code java>
 public class MyBlock extends Block { public class MyBlock extends Block {
Line 66: Line 54:
     @Override     @Override
     public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {     public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
-        if (world.getBlockState(pos).get(ACTIVATED)){+        if (world.getBlockState(pos).get(CHARGED)){
             //Summoning the Lighting Bolt at the block             //Summoning the Lighting Bolt at the block
             LightningEntity lightningEntity = (LightningEntity) EntityType.LIGHTNING_BOLT.create(world);             LightningEntity lightningEntity = (LightningEntity) EntityType.LIGHTNING_BOLT.create(world);
Line 73: Line 61:
         }         }
  
-        world.setBlockState(pos, state.with(ACTIVATED, false));+        world.setBlockState(pos, state.with(CHARGED, false));
         super.onSteppedOn(world, pos, state, entity);         super.onSteppedOn(world, pos, state, entity);
     }     }
tutorial/blockstate.txt · Last modified: 2023/11/18 08:13 by solidblock