Skip to content

Instantly share code, notes, and snippets.

@Juuxel
Last active January 6, 2019 17:10
Show Gist options
  • Save Juuxel/946536e67264ca735c2046429871738e to your computer and use it in GitHub Desktop.
Save Juuxel/946536e67264ca735c2046429871738e to your computer and use it in GitHub Desktop.
Fabric block example
package com.example.mod;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.block.BlockItem;
/* The block class.
* This does not include models, translation files, loot tables or textures (those have to be defined in
/data and /assets).
* The item will be in the Decorations tab of the creative menu.
*/
public class ExampleBlock extends Block {
public ExampleBlock() {
super(Block.Settings.of(Material.STONE));
}
public static class Item extends BlockItem {
public Item(Block block) {
// The item is put in the decoration creative tab
super(block, new Item.Settings().itemGroup(ItemGroup.DECORATIONS));
}
}
}
package com.example.mod;
import net.fabricmc.api.ModInitializer;
import net.minecraft.block.Block;
import net.minecraft.registry.Registry;
/* The mod class.
* You should clone the Fabric example repository to get all of the required files.
*/
public class ExampleMod implements ModInitializer {
@Override
public void onInitialize() {
Block block = new ExampleBlock();
Registry.register(Registry.BLOCK, "modid:test_block", block);
Registry.register(Registry.ITEM, "modid:test_block", new ExampleBlock.Item(block));
}
}
{
"id": "modid",
"name": "ExampleMod",
"description": "NOTE: This file must be in /src/main/resources",
"version": "1.0.0",
"side": "universal",
"initializer": "com.example.mod.ExampleMod",
"requires": {
"fabric": "*"
}
}
@FinnT730
Copy link

Thanks for making this!! It is working!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment