tinycodinglm / mc /mc-0002.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame Contribute Delete
2.88 kB
opencode trace
System You are an expert Fabric mod developer. You write idiomatic Minecraft Fabric mods using Java, Fabric API, and Yarn mappings.

You are an expert Fabric mod developer. You write idiomatic Minecraft Fabric mods using Java, Fabric API, and Yarn mappings.

User

How do I create custom blocks with different settings, block states, and properties?

Assistant
java
package com.example.mymod;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.MapColor;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;

public class MyBlocks {
    public static final Block SIMPLE_BLOCK = new Block(
        Block.Settings.create().mapColor(MapColor.STONE_GRAY)
            .requiresTool().strength(3.0f, 3.0f).sounds(BlockSoundGroup.STONE)
    );

    public static final BooleanProperty LIT = BooleanProperty.of("lit");

    public static final Block POWERED_BLOCK = new PoweredBlock(
        Block.Settings.create().strength(5.0f, 6.0f)
            .luminance(state -> state.get(LIT) ? 15 : 0)
    );

    public static final Block GLASS_BLOCK = new TransparentBlock(
        Block.Settings.create().strength(0.3f, 0.3f).sounds(BlockSoundGroup.GLASS).nonOpaque()
    );

    public static final Block CUSTOM_SLAB = new SlabBlock(
        Block.Settings.create().strength(2.0f, 3.0f).sounds(BlockSoundGroup.WOOD)
    );

    public static final Block CUSTOM_STAIRS = new StairsBlock(
        SIMPLE_BLOCK.getDefaultState(),
        Block.Settings.create().strength(2.0f, 3.0f).sounds(BlockSoundGroup.WOOD)
    );

    public static void registerBlocks() {
        Registry.register(Registries.BLOCK, MyMod.id("simple_block"), SIMPLE_BLOCK);
        Registry.register(Registries.BLOCK, MyMod.id("powered_block"), POWERED_BLOCK);
        Registry.register(Registries.BLOCK, MyMod.id("glass_block"), GLASS_BLOCK);
        Registry.register(Registries.BLOCK, MyMod.id("custom_slab"), CUSTOM_SLAB);
        Registry.register(Registries.BLOCK, MyMod.id("custom_stairs"), CUSTOM_STAIRS);
        Registry.register(Registries.ITEM, MyMod.id("simple_block"),
            new BlockItem(SIMPLE_BLOCK, new Item.Settings()));
    }
}

Block with custom state:

java
public class PoweredBlock extends Block {
    public static final BooleanProperty POWERED = Properties.POWERED;

    public PoweredBlock(Settings settings) {
        super(settings);
        this.setDefaultState(this.stateManager.getDefaultState().with(POWERED, false));
    }

    @Override
    protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
        builder.add(POWERED);
    }
}