From aa6de6177cbc41483382e8280b0b33458958082f Mon Sep 17 00:00:00 2001 From: Francesco Macagno Date: Sat, 22 Aug 2015 15:50:41 -0700 Subject: [PATCH] Added features to MetaBlock --- .../java/cr0s/warpdrive/conf/MetaBlock.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/conf/MetaBlock.java b/src/main/java/cr0s/warpdrive/conf/MetaBlock.java index 50ce8dc2..af0489ff 100644 --- a/src/main/java/cr0s/warpdrive/conf/MetaBlock.java +++ b/src/main/java/cr0s/warpdrive/conf/MetaBlock.java @@ -4,49 +4,58 @@ import java.util.HashMap; import net.minecraft.block.Block; -public class MetaBlock { - - private static final int MAX_METADATA = 16;//I think this is 16? +public class MetaBlock implements Comparable { - private static HashMap metablocks = new HashMap(); + 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]; } + + @Override + public int compareTo(Object o) { + return block.getUnlocalizedName().compareTo(((MetaBlock) o).block.getUnlocalizedName()); + } - + @Override + public String toString() { + return block.getUnlocalizedName() + ":" + metadata; + } + }