添加一个高级方块

image-20231029150618990

添加方块代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

package net.tutorialmod.block.custom;

import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;

public class JumpyBlock extends Block {
public JumpyBlock(Properties properties) {
super(properties);
}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
player.sendSystemMessage(Component.literal("Right Clicked this!"));

return InteractionResult.SUCCESS;
}


@Override
public void stepOn(Level level, BlockPos blockPos, BlockState blockState, Entity entity) {
if(entity instanceof LivingEntity entity1){
entity1.addEffect(new MobEffectInstance(new MobEffectInstance(MobEffects.JUMP,200)));
}
super.stepOn(level, blockPos, blockState, entity);
}
}

注册方块

1
2
3

public static final RegistrySupplier<Block> JUMPY_BLOCK = registerBlock("jumpy_block",()-> new JumpyBlock(BlockBehaviour.Properties.copy(Blocks.STONE)));

添加blockstate

1
2
3
4
5
6
7
8

{
"variants": {
"": {
"model": "tutorialmod:block/jumpy_block"
}
}
}

添加方块model

1
2
3
4
5
6
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "tutorialmod:block/jumpy_block"
}
}

添加方块item

1
2
3
4
{
"parent": "tutorialmod:block/jumpy_block"
}

添加方块贴图