From a2df79bc01b6908b6c4c38d752f0b9f0b867d412 Mon Sep 17 00:00:00 2001 From: Francesco Macagno Date: Thu, 20 Aug 2015 23:20:15 -0700 Subject: [PATCH] Added MetaBlock to store block and metadata Must be retrieved with MetaBlock.getMetaBlock(block, meta) --- .../java/cr0s/warpdrive/conf/MetaBlock.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/cr0s/warpdrive/conf/MetaBlock.java diff --git a/src/main/java/cr0s/warpdrive/conf/MetaBlock.java b/src/main/java/cr0s/warpdrive/conf/MetaBlock.java new file mode 100644 index 00000000..50ce8dc2 --- /dev/null +++ b/src/main/java/cr0s/warpdrive/conf/MetaBlock.java @@ -0,0 +1,52 @@ +package cr0s.warpdrive.conf; + +import java.util.HashMap; + +import net.minecraft.block.Block; + +public class MetaBlock { + + private static final int MAX_METADATA = 16;//I think this is 16? + + private static HashMap metablocks = new HashMap(); + + private Block block; + private int metadata; + + private MetaBlock(Block b, int metadata) { + this.block = b; + this.metadata = metadata; + } + + /** + * @return the block + */ + public Block getBlock() { + return block; + } + + /** + * @return the metadata + */ + public int getMetadata() { + return metadata; + } + + public static MetaBlock getMetaBlock(Block b, int metadata) { + + MetaBlock[] block = metablocks.get(b.getUnlocalizedName()); + + if (block == null) { + block = new MetaBlock[MAX_METADATA]; + metablocks.put(b.getUnlocalizedName(), block); + } + + if (block[metadata] == null) { + block[metadata] = new MetaBlock(b, metadata); + } + + return block[metadata]; + } + + +}