tutorial:blockstate
Differences
This shows you the differences between two versions of the page.
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. tsunaminal | tutorial: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, | player.playSound(SoundEvents.BLOCK_RESPAWN_ANCHOR_CHARGE, | ||
- | world.setBlockState(pos, | + | world.setBlockState(pos, |
return ActionResult.SUCCESS; | return ActionResult.SUCCESS; | ||
} | } | ||
Line 48: | Line 48: | ||
</ | </ | ||
- | + | And Finally, to use the '' | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | And Finally, to use the '' | + | |
<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, | + | world.setBlockState(pos, |
super.onSteppedOn(world, | super.onSteppedOn(world, | ||
} | } |
tutorial/blockstate.txt · Last modified: 2023/11/18 08:13 by solidblock