Added MetaBlock to store block and metadata

Must be retrieved with MetaBlock.getMetaBlock(block, meta)
This commit is contained in:
Francesco Macagno 2015-08-20 23:20:15 -07:00
parent 3dc37dd969
commit a2df79bc01

View file

@ -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<String, MetaBlock[]> metablocks = new HashMap<String, MetaBlock[]>();
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];
}
}