80 lines
3.4 KiB
Java
80 lines
3.4 KiB
Java
/*
|
|
*
|
|
* BlockManager
|
|
*
|
|
* The mod block manager
|
|
*
|
|
*
|
|
*/
|
|
|
|
package jesse.keeblarcraft.CustomBlocks;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import jesse.keeblarcraft.Keeblarcraft;
|
|
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.Blocks;
|
|
import net.minecraft.block.ExperienceDroppingBlock;
|
|
import net.minecraft.item.BlockItem;
|
|
import net.minecraft.registry.Registries;
|
|
import net.minecraft.registry.Registry;
|
|
import net.minecraft.sound.BlockSoundGroup;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.math.intprovider.UniformIntProvider;
|
|
|
|
public class BlockManager {
|
|
|
|
/// The block list. DO NOT ADD TO THE LIST YOURSELF. USE
|
|
/// THE RegisterBlock(...) FUNCTION OTHERWISE YOUR BLOCK WILL
|
|
/// NOT BE REGISTERED PROPERLY AND MAY BREAK THE GAME
|
|
public static final List<Block> blockList = new ArrayList<Block>();
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @fn RegisterBlock
|
|
///
|
|
/// @arg[in] name is the block name. IMPORTANT: Name must adhere to rules:
|
|
/// 1. The name provided here must match these names:
|
|
/// * This blocks models/block name
|
|
/// * This blocks textures/block name
|
|
/// 2 Name must be lowercase & no special characters besides '_'
|
|
///
|
|
/// @arg[in] block is the block to be added to the block list
|
|
///
|
|
/// @brief This is the call to register your block to the game! Please
|
|
/// do not forget to update the models/block json file, the
|
|
/// textures/block png name, and finally the lang/en_us.json file
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
public static void RegisterBlock(String name, Block block) {
|
|
|
|
// This call registers the block as an item in inventories
|
|
Registry.register(Registries.ITEM, new Identifier(Keeblarcraft.MOD_ID, name), new BlockItem(block, new FabricItemSettings()));
|
|
|
|
// This call registers the block as placed
|
|
Block newBlock = Registry.register(Registries.BLOCK, new Identifier(Keeblarcraft.MOD_ID, name), block);
|
|
|
|
// Add the block to the block list
|
|
blockList.add(newBlock);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/// @fn RegisterBlocks
|
|
///
|
|
/// @brief This function is only meant to be called by the main mod
|
|
/// execution path and should only be called once. This is a
|
|
/// glorified print statement - but also serves to add the
|
|
/// example block in the game
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
public static void RegisterBlocks() {
|
|
Keeblarcraft.LOGGER.info("Registering modded blocks for " + Keeblarcraft.MOD_ID);
|
|
|
|
// Register example block to the mod
|
|
Block exampleBlock = new Block(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).sounds(BlockSoundGroup.AMETHYST_BLOCK).requiresTool().breakInstantly());
|
|
Block exampleBlockOre = new ExperienceDroppingBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).sounds(BlockSoundGroup.ANCIENT_DEBRIS).requiresTool(), UniformIntProvider.create(4, 20));
|
|
RegisterBlock("example_block_ore", exampleBlockOre);
|
|
RegisterBlock("example_block", exampleBlock);
|
|
}
|
|
}
|