添加多状态的方块 添加方块123456789101112131415161718192021222324252627282930313233343536package net.tutorialmod.block.custom;import net.minecraft.core.BlockPos;import net.minecraft.world.InteractionHand;import net.minecraft.world.InteractionResult;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.level.block.state.StateDefinition;import net.minecraft.world.level.block.state.properties.BooleanProperty;import net.minecraft.world.phys.BlockHitResult;public class ZirconLampBlock extends Block { public static final BooleanProperty LIT = BooleanProperty.create("lit"); public ZirconLampBlock(Properties properties) { super(properties); } @Override public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) { if(!level.isClientSide() && interactionHand == InteractionHand.MAIN_HAND) { level.setBlock(blockPos, blockState.cycle(LIT),3); } return InteractionResult.SUCCESS; } @Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(LIT); }} 注册方块1234567//lamppublic static final RegistrySupplier<Block> ZIRCON_LAMP = registerBlock("zircon_lamp", () -> new ZirconLampBlock(BlockBehaviour.Properties.copy(Blocks.STONE) .strength(6f).requiresCorrectToolForDrops() .lightLevel(state -> state.getValue(ZirconLampBlock.LIT) ? 15 : 0))); 添加blockstate1234567891011{ "variants": { "lit=false": { "model": "tutorialmod:block/zircon_lamp_off" }, "lit=true": { "model": "tutorialmod:block/zircon_lamp_on" } }} 添加方块model123456{ "parent": "minecraft:block/cube_all", "textures": { "all": "tutorialmod:block/zircon_lamp_off" }} 1234567{ "parent": "minecraft:block/cube_all", "textures": { "all": "tutorialmod:block/zircon_lamp_on" }} 添加物品model123{ "parent": "tutorialmod:block/zircon_lamp_off"} 添加贴图略 添加语言文件略