File size: 2,882 Bytes
d517dc9
 
 
 
1
2
3
4
5
{"type": "session", "harness": "opencode", "id": "mc-0002", "name": "Custom Blocks"}
{"type": "message", "message": {"role": "system", "content": "You are an expert Fabric mod developer. You write idiomatic Minecraft Fabric mods using Java, Fabric API, and Yarn mappings."}}
{"type": "message", "message": {"role": "user", "content": "How do I create custom blocks with different settings, block states, and properties?"}}
{"type": "message", "message": {"role": "assistant", "content": "```java\npackage com.example.mymod;\n\nimport net.minecraft.block.Block;\nimport net.minecraft.block.BlockState;\nimport net.minecraft.block.MapColor;\nimport net.minecraft.state.property.BooleanProperty;\nimport net.minecraft.state.property.IntProperty;\n\npublic class MyBlocks {\n    public static final Block SIMPLE_BLOCK = new Block(\n        Block.Settings.create().mapColor(MapColor.STONE_GRAY)\n            .requiresTool().strength(3.0f, 3.0f).sounds(BlockSoundGroup.STONE)\n    );\n\n    public static final BooleanProperty LIT = BooleanProperty.of(\"lit\");\n\n    public static final Block POWERED_BLOCK = new PoweredBlock(\n        Block.Settings.create().strength(5.0f, 6.0f)\n            .luminance(state -> state.get(LIT) ? 15 : 0)\n    );\n\n    public static final Block GLASS_BLOCK = new TransparentBlock(\n        Block.Settings.create().strength(0.3f, 0.3f).sounds(BlockSoundGroup.GLASS).nonOpaque()\n    );\n\n    public static final Block CUSTOM_SLAB = new SlabBlock(\n        Block.Settings.create().strength(2.0f, 3.0f).sounds(BlockSoundGroup.WOOD)\n    );\n\n    public static final Block CUSTOM_STAIRS = new StairsBlock(\n        SIMPLE_BLOCK.getDefaultState(),\n        Block.Settings.create().strength(2.0f, 3.0f).sounds(BlockSoundGroup.WOOD)\n    );\n\n    public static void registerBlocks() {\n        Registry.register(Registries.BLOCK, MyMod.id(\"simple_block\"), SIMPLE_BLOCK);\n        Registry.register(Registries.BLOCK, MyMod.id(\"powered_block\"), POWERED_BLOCK);\n        Registry.register(Registries.BLOCK, MyMod.id(\"glass_block\"), GLASS_BLOCK);\n        Registry.register(Registries.BLOCK, MyMod.id(\"custom_slab\"), CUSTOM_SLAB);\n        Registry.register(Registries.BLOCK, MyMod.id(\"custom_stairs\"), CUSTOM_STAIRS);\n        Registry.register(Registries.ITEM, MyMod.id(\"simple_block\"),\n            new BlockItem(SIMPLE_BLOCK, new Item.Settings()));\n    }\n}\n```\n\nBlock with custom state:\n```java\npublic class PoweredBlock extends Block {\n    public static final BooleanProperty POWERED = Properties.POWERED;\n\n    public PoweredBlock(Settings settings) {\n        super(settings);\n        this.setDefaultState(this.stateManager.getDefaultState().with(POWERED, false));\n    }\n\n    @Override\n    protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {\n        builder.add(POWERED);\n    }\n}\n```"}}