From 611f39dd6c0aef144bd424fa7177df27161a3d38 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Wed, 28 Aug 2013 16:08:15 -0400 Subject: [PATCH] Working on a handler to manage registering blocks This will be connected to a more advanced config, id, and a few other handlers. This way all block/items will be in sync when it comes to creations, and handling. --- src/dark/core/BlockRegistry.java | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/dark/core/BlockRegistry.java diff --git a/src/dark/core/BlockRegistry.java b/src/dark/core/BlockRegistry.java new file mode 100644 index 00000000..bd880e5f --- /dev/null +++ b/src/dark/core/BlockRegistry.java @@ -0,0 +1,57 @@ +package dark.core; + +import java.util.HashMap; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemBlock; +import net.minecraft.tileentity.TileEntity; + +/** Handler to make registering all parts of a block a bit easier + * + * @author DarkGuardsman */ +public class BlockRegistry +{ + private static HashMap blockMap = new HashMap(); + + public static void addBlockToRegister(BlockData data) + { + if (data != null && data.block != null && !blockMap.containsKey(data.block)) + { + blockMap.put(data.block, data); + } + } + + /** Used to store info on the block that will later be used to register all parts of the block */ + public static class BlockData + { + public Block block; + public Class itemBlock; + public String modBlockID; + public HashMap tiles = new HashMap(); + + public BlockData(Block block, String name) + { + this.block = block; + this.modBlockID = name; + } + + public BlockData(Block block, Class itemBlock, String name) + { + this(block, name); + this.itemBlock = itemBlock; + } + + /** Adds a tileEntity to be registered when this block is registered + * + * @param name - mod name for the tileEntity, should be unique + * @param tile - new instance of the TileEntity to register */ + public BlockData addTileEntity(String name, TileEntity tile) + { + if (!this.tiles.containsKey(name)) + { + this.tiles.put(name, tile); + } + return this; + } + } +}