mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-12 16:37:28 +00:00
Add in-place retrimming
This commit is contained in:
1 parent
e146f976ee
commit
abdc006b5c
13 files changed
+467
-2
No files matched your search
+1
-1
@@ -17,7 +17,7 @@ buildscript {
|
||||
|
||||
apply plugin: 'forge'
|
||||
|
||||
version = "1.7.10-1.7.5"
|
||||
version = "1.7.10-1.7.6"
|
||||
group= "com.jaquadro.minecraft.storagedrawers" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
archivesBaseName = "StorageDrawers"
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.jaquadro.minecraft.storagedrawers;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.StorageDrawersApi;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.api.BlockRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler;
|
||||
import com.jaquadro.minecraft.storagedrawers.integration.IntegrationRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
@@ -43,6 +45,7 @@ public class StorageDrawers
|
||||
public static RecipeHandlerRegistry recipeHandlerRegistry;
|
||||
public static RenderRegistry renderRegistry;
|
||||
public static WailaRegistry wailaRegistry;
|
||||
public static BlockRegistry blockRegistry;
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static StorageDrawers instance;
|
||||
@@ -69,6 +72,7 @@ public class StorageDrawers
|
||||
recipeHandlerRegistry = new RecipeHandlerRegistry();
|
||||
renderRegistry = new RenderRegistry();
|
||||
wailaRegistry = new WailaRegistry();
|
||||
blockRegistry = new BlockRegistry();
|
||||
|
||||
blocks.init();
|
||||
items.init();
|
||||
@@ -90,6 +94,8 @@ public class StorageDrawers
|
||||
recipes.init();
|
||||
|
||||
IntegrationRegistry.instance().postInit();
|
||||
|
||||
StorageDrawersApi.instance().packFactory().registerResolver(ModBlocks.resolver);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -21,4 +21,9 @@ public interface IPackBlockFactory
|
||||
* Hides block from NEI if NEI is active.
|
||||
*/
|
||||
void hideBlock (String blockID);
|
||||
|
||||
/**
|
||||
* Registers block metadata from an initialized DataResolver with Storage Drawers.
|
||||
*/
|
||||
void registerResolver (IExtendedDataResolver resolver);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
|
||||
@@ -52,6 +53,11 @@ public class BlockCompDrawers extends BlockDrawers implements INetworked
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockType retrimType () {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntityDrawers createNewTileEntity (World world, int meta) {
|
||||
return new TileEntityDrawersComp();
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.jaquadro.minecraft.storagedrawers.block;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute;
|
||||
@@ -11,6 +13,7 @@ import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandar
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModItems;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler;
|
||||
import com.jaquadro.minecraft.storagedrawers.item.ItemTrim;
|
||||
import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
@@ -122,6 +125,48 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
setLightOpacity(255);
|
||||
}
|
||||
|
||||
public boolean retrimBlock (World world, int x, int y, int z, ItemStack prototype) {
|
||||
if (retrimType() == null)
|
||||
return false;
|
||||
|
||||
Block protoBlock = Block.getBlockFromItem(prototype.getItem());
|
||||
int protoMeta = prototype.getItemDamage();
|
||||
|
||||
BlockConfiguration config = BlockConfiguration.by(retrimType(), drawerCount, halfDepth);
|
||||
|
||||
Block plankBlock = StorageDrawers.blockRegistry.getPlankBlock(BlockConfiguration.Trim, protoBlock, protoMeta);
|
||||
int plankMeta = StorageDrawers.blockRegistry.getPlankMeta(BlockConfiguration.Trim, protoBlock, protoMeta);
|
||||
|
||||
Block newBlock = StorageDrawers.blockRegistry.getBlock(config, plankBlock, plankMeta);
|
||||
int newMeta = StorageDrawers.blockRegistry.getMeta(config, plankBlock, plankMeta);
|
||||
|
||||
if (newBlock == null)
|
||||
return false;
|
||||
|
||||
if (newBlock == this)
|
||||
world.setBlockMetadataWithNotify(x, y, z, newMeta, 3);
|
||||
else {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
TileEntity newDrawer = createNewTileEntity(world, newMeta);
|
||||
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tile.writeToNBT(tag);
|
||||
newDrawer.readFromNBT(tag);
|
||||
|
||||
world.removeTileEntity(x, y, z);
|
||||
world.setBlockToAir(x, y, z);
|
||||
|
||||
world.setBlock(x, y, z, newBlock, newMeta, 3);
|
||||
world.setTileEntity(x, y, z, newDrawer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected BlockType retrimType () {
|
||||
return BlockType.Drawers;
|
||||
}
|
||||
|
||||
public float getTrimWidth () {
|
||||
return trimWidth;
|
||||
}
|
||||
@@ -252,7 +297,18 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
|
||||
}
|
||||
|
||||
if (item != null && item.getItem() != null) {
|
||||
if (item.getItem() == ModItems.upgrade || item.getItem() == ModItems.upgradeStatus || item.getItem() == ModItems.upgradeVoid || item.getItem() == ModItems.upgradeCreative) {
|
||||
if (item.getItem() instanceof ItemTrim && player.isSneaking()) {
|
||||
if (!retrimBlock(world, x, y, z, item))
|
||||
return false;
|
||||
|
||||
if (player != null && !player.capabilities.isCreativeMode) {
|
||||
if (--item.stackSize <= 0)
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (item.getItem() == ModItems.upgrade || item.getItem() == ModItems.upgradeStatus || item.getItem() == ModItems.upgradeVoid || item.getItem() == ModItems.upgradeCreative) {
|
||||
if (!tileDrawers.addUpgrade(item)) {
|
||||
player.addChatMessage(new ChatComponentTranslation("storagedrawers.msg.maxUpgrades"));
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.block;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.ExtendedDataResolver;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModBlocks;
|
||||
import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs;
|
||||
import com.jaquadro.minecraft.storagedrawers.integration.RefinedRelocation;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockWood;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
public class DataResolver extends ExtendedDataResolver
|
||||
{
|
||||
private static String[] textureNames = BlockWood.field_150096_a;
|
||||
|
||||
public DataResolver (String modID) {
|
||||
super(modID, textureNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreativeTabs getCreativeTabs (BlockType type) {
|
||||
return ModCreativeTabs.tabStorageDrawers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block getBlock (BlockConfiguration blockConfig) {
|
||||
switch (blockConfig.getBlockType()) {
|
||||
case Drawers:
|
||||
if (blockConfig.getDrawerCount() == 1)
|
||||
return ModBlocks.fullDrawers1;
|
||||
if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth())
|
||||
return ModBlocks.fullDrawers2;
|
||||
if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth())
|
||||
return ModBlocks.fullDrawers4;
|
||||
if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth())
|
||||
return ModBlocks.halfDrawers2;
|
||||
if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth())
|
||||
return ModBlocks.halfDrawers4;
|
||||
break;
|
||||
case DrawersSorting:
|
||||
if (blockConfig.getDrawerCount() == 1)
|
||||
return RefinedRelocation.fullDrawers1;
|
||||
if (blockConfig.getDrawerCount() == 2 && !blockConfig.isHalfDepth())
|
||||
return RefinedRelocation.fullDrawers2;
|
||||
if (blockConfig.getDrawerCount() == 4 && !blockConfig.isHalfDepth())
|
||||
return RefinedRelocation.fullDrawers4;
|
||||
if (blockConfig.getDrawerCount() == 2 && blockConfig.isHalfDepth())
|
||||
return RefinedRelocation.halfDrawers2;
|
||||
if (blockConfig.getDrawerCount() == 4 && blockConfig.isHalfDepth())
|
||||
return RefinedRelocation.halfDrawers4;
|
||||
break;
|
||||
case Trim:
|
||||
return ModBlocks.trim;
|
||||
case TrimSorting:
|
||||
return RefinedRelocation.trim;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init () {
|
||||
for (int i = 0, p = 0, m = 0; i < 6; i++, p++, m++)
|
||||
setPlankSlab(i, Blocks.planks, p, Blocks.wooden_slab, m);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class ModBlocks
|
||||
{
|
||||
public static DataResolver resolver;
|
||||
|
||||
public static BlockDrawers fullDrawers1;
|
||||
public static BlockDrawers fullDrawers2;
|
||||
public static BlockDrawers fullDrawers4;
|
||||
@@ -30,6 +32,8 @@ public class ModBlocks
|
||||
public static BlockSlave controllerSlave;
|
||||
|
||||
public void init () {
|
||||
resolver = new DataResolver(StorageDrawers.MOD_ID);
|
||||
|
||||
fullDrawers1 = new BlockDrawers("fullDrawers1", 1, false);
|
||||
fullDrawers2 = new BlockDrawers("fullDrawers2", 2, false);
|
||||
fullDrawers4 = new BlockDrawers("fullDrawers4", 4, false);
|
||||
@@ -91,6 +95,8 @@ public class ModBlocks
|
||||
OreDictionary.registerOre(key, new ItemStack(halfDrawers2, 1, OreDictionary.WILDCARD_VALUE));
|
||||
for (String key : new String[] { "drawerBasic" })
|
||||
OreDictionary.registerOre(key, new ItemStack(halfDrawers4, 1, OreDictionary.WILDCARD_VALUE));
|
||||
|
||||
resolver.init();
|
||||
}
|
||||
|
||||
public static String getQualifiedName (String name) {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.core.api;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.IExtendedDataResolver;
|
||||
import com.jaquadro.minecraft.storagedrawers.util.UniqueMetaIdentifier;
|
||||
import com.jaquadro.minecraft.storagedrawers.util.UniqueMetaRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockRegistry
|
||||
{
|
||||
private Map<BlockConfiguration, UniqueMetaRegistry<UniqueMetaIdentifier>> registry = new HashMap<BlockConfiguration, UniqueMetaRegistry<UniqueMetaIdentifier>>();
|
||||
private Map<BlockConfiguration, UniqueMetaRegistry<UniqueMetaIdentifier>> invertRegistry = new HashMap<BlockConfiguration, UniqueMetaRegistry<UniqueMetaIdentifier>>();
|
||||
|
||||
public void register (BlockConfiguration config, IExtendedDataResolver resolver) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (resolver.isValidMetaValue(i))
|
||||
register(config, resolver.getBlock(config), i, resolver.getPlankBlock(i), resolver.getPlankMeta(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void register (BlockConfiguration config, Block block, int meta, Block plankBlock, int plankMeta) {
|
||||
UniqueMetaRegistry<UniqueMetaIdentifier> uniq = registry.get(config);
|
||||
if (uniq == null) {
|
||||
uniq = new UniqueMetaRegistry<UniqueMetaIdentifier>();
|
||||
registry.put(config, uniq);
|
||||
}
|
||||
|
||||
uniq.register(UniqueMetaIdentifier.createFor(plankBlock, plankMeta), UniqueMetaIdentifier.createFor(block, meta));
|
||||
|
||||
UniqueMetaRegistry<UniqueMetaIdentifier> blockReg = invertRegistry.get(config);
|
||||
if (blockReg == null) {
|
||||
blockReg = new UniqueMetaRegistry<UniqueMetaIdentifier>();
|
||||
invertRegistry.put(config, blockReg);
|
||||
}
|
||||
|
||||
blockReg.register(UniqueMetaIdentifier.createFor(block, meta), UniqueMetaIdentifier.createFor(plankBlock, plankMeta));
|
||||
}
|
||||
|
||||
public Block getBlock (BlockConfiguration config, Block plankBlock, int plankMeta) {
|
||||
return blockLookup(registry, config, plankBlock, plankMeta);
|
||||
}
|
||||
|
||||
public int getMeta (BlockConfiguration config, Block plankBlock, int plankMeta) {
|
||||
return metaLookup(registry, config, plankBlock, plankMeta);
|
||||
}
|
||||
|
||||
public Block getPlankBlock (BlockConfiguration config, Block block, int meta) {
|
||||
return blockLookup(invertRegistry, config, block, meta);
|
||||
}
|
||||
|
||||
public int getPlankMeta (BlockConfiguration config, Block block, int meta) {
|
||||
return metaLookup(invertRegistry, config, block, meta);
|
||||
}
|
||||
|
||||
private Block blockLookup (Map<BlockConfiguration, UniqueMetaRegistry<UniqueMetaIdentifier>> reg, BlockConfiguration config, Block block, int meta) {
|
||||
UniqueMetaRegistry<UniqueMetaIdentifier> uniq = reg.get(config);
|
||||
if (uniq == null)
|
||||
return null;
|
||||
|
||||
UniqueMetaIdentifier id = uniq.getEntry(UniqueMetaIdentifier.createFor(block, meta));
|
||||
if (id == null)
|
||||
return null;
|
||||
|
||||
return id.getBlock();
|
||||
}
|
||||
|
||||
private int metaLookup (Map<BlockConfiguration, UniqueMetaRegistry<UniqueMetaIdentifier>> reg, BlockConfiguration config, Block block, int meta) {
|
||||
UniqueMetaRegistry<UniqueMetaIdentifier> uniq = reg.get(config);
|
||||
if (uniq == null)
|
||||
return 0;
|
||||
|
||||
UniqueMetaIdentifier id = uniq.getEntry(UniqueMetaIdentifier.createFor(block, meta));
|
||||
if (id == null)
|
||||
return 0;
|
||||
|
||||
return id.meta;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,11 @@ package com.jaquadro.minecraft.storagedrawers.core.api;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.IExtendedDataResolver;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.IPackBlockFactory;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.IPackDataResolver;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.pack.BlockSortingTrimPack;
|
||||
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
|
||||
import com.jaquadro.minecraft.storagedrawers.integration.IntegrationRegistry;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.pack.BlockDrawersPack;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.pack.BlockSortingDrawersPack;
|
||||
@@ -83,4 +85,39 @@ public class PackFactory implements IPackBlockFactory
|
||||
public void hideBlock (String blockID) {
|
||||
NEIStorageDrawersConfig.hideBlock(blockID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerResolver (IExtendedDataResolver resolver) {
|
||||
ConfigManager config = StorageDrawers.config;
|
||||
if (config.isBlockEnabled("fulldrawers1")) {
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull1, resolver);
|
||||
if (config.cache.enableRefinedRelocationIntegration)
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull1, resolver);
|
||||
}
|
||||
if (config.isBlockEnabled("fulldrawers2")) {
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull2, resolver);
|
||||
if (config.cache.enableRefinedRelocationIntegration)
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull2, resolver);
|
||||
}
|
||||
if (config.isBlockEnabled("fulldrawers4")) {
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.BasicFull4, resolver);
|
||||
if (config.cache.enableRefinedRelocationIntegration)
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.SortingFull4, resolver);
|
||||
}
|
||||
if (config.isBlockEnabled("halfdrawers2")) {
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.BasicHalf2, resolver);
|
||||
if (config.cache.enableRefinedRelocationIntegration)
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.SortingHalf2, resolver);
|
||||
}
|
||||
if (config.isBlockEnabled("halfdrawers4")) {
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.BasicHalf4, resolver);
|
||||
if (config.cache.enableRefinedRelocationIntegration)
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.SortingHalf4, resolver);
|
||||
}
|
||||
if (config.isBlockEnabled("trim")) {
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.Trim, resolver);
|
||||
if (config.cache.enableRefinedRelocationIntegration)
|
||||
StorageDrawers.blockRegistry.register(BlockConfiguration.TrimSorting, resolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -1,6 +1,7 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.integration.refinedrelocation;
|
||||
|
||||
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.BlockDrawers;
|
||||
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandard;
|
||||
import com.jaquadro.minecraft.storagedrawers.integration.RefinedRelocation;
|
||||
@@ -54,6 +55,11 @@ public class BlockSortingDrawers extends BlockDrawers
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockType retrimType () {
|
||||
return BlockType.DrawersSorting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileSortingDrawersStandard createNewTileEntity (World world, int meta) {
|
||||
return new TileSortingDrawersStandard();
|
||||
|
||||
@@ -2,7 +2,9 @@ package com.jaquadro.minecraft.storagedrawers.item;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockWood;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemMultiTexture;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemTrim extends ItemMultiTexture
|
||||
{
|
||||
@@ -13,4 +15,9 @@ public class ItemTrim extends ItemMultiTexture
|
||||
protected ItemTrim (Block block, String[] names) {
|
||||
super(block, block, names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesSneakBypassUse (World world, int x, int y, int z, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.util;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public final class UniqueMetaIdentifier
|
||||
{
|
||||
public final String modId;
|
||||
public final String name;
|
||||
public final int meta;
|
||||
|
||||
private GameRegistry.UniqueIdentifier cachedUID;
|
||||
|
||||
public UniqueMetaIdentifier (String modId, String name) {
|
||||
this.modId = modId;
|
||||
this.name = name;
|
||||
this.meta = OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
public UniqueMetaIdentifier (String modId, String name, int meta) {
|
||||
this.modId = modId;
|
||||
this.name = name;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public UniqueMetaIdentifier (String qualifiedName, int meta) {
|
||||
String[] parts = qualifiedName.split(":");
|
||||
this.modId = parts[0];
|
||||
this.name = parts[1];
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public UniqueMetaIdentifier (String compoundName) {
|
||||
String[] parts1 = compoundName.split(";");
|
||||
String[] parts2 = parts1[0].split(":");
|
||||
this.modId = parts2[0];
|
||||
|
||||
if (parts2.length >= 2)
|
||||
this.name = parts2[1];
|
||||
else
|
||||
this.name = "";
|
||||
|
||||
if (parts1.length >= 2)
|
||||
this.meta = Integer.parseInt(parts1[1]);
|
||||
else if (parts2.length > 2)
|
||||
this.meta = Integer.parseInt(parts2[parts2.length - 1]);
|
||||
else
|
||||
this.meta = OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
public UniqueMetaIdentifier (String compoundName, char separator) {
|
||||
String[] parts1 = compoundName.split("[ ]*" + separator + "[ ]*");
|
||||
String[] parts2 = parts1[0].split(":");
|
||||
this.modId = parts2[0];
|
||||
|
||||
if (parts2.length >= 2)
|
||||
this.name = parts2[1];
|
||||
else
|
||||
this.name = "";
|
||||
|
||||
if (parts1.length >= 2)
|
||||
this.meta = Integer.parseInt(parts1[1]);
|
||||
else
|
||||
this.meta = OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
public GameRegistry.UniqueIdentifier getUniqueIdentifier () {
|
||||
if (cachedUID == null)
|
||||
cachedUID = new GameRegistry.UniqueIdentifier(modId + ":" + name);
|
||||
return cachedUID;
|
||||
}
|
||||
|
||||
public Block getBlock () {
|
||||
return GameRegistry.findBlock(modId, name);
|
||||
}
|
||||
|
||||
public Item getItem () {
|
||||
return GameRegistry.findItem(modId, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals (Object obj) {
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (obj.getClass() != getClass())
|
||||
return false;
|
||||
|
||||
final UniqueMetaIdentifier other = (UniqueMetaIdentifier) obj;
|
||||
|
||||
return Objects.equal(modId, other.modId)
|
||||
&& Objects.equal(name, other.name)
|
||||
&& meta == other.meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode () {
|
||||
return Objects.hashCode(modId, name) ^ (meta * 37);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString () {
|
||||
return String.format("%s:%s;%d", modId, name, meta);
|
||||
}
|
||||
|
||||
public static UniqueMetaIdentifier createFor (ItemStack itemStack) {
|
||||
if (itemStack.getItem() == null)
|
||||
return null;
|
||||
|
||||
String name = GameData.getItemRegistry().getNameForObject(itemStack.getItem());
|
||||
return new UniqueMetaIdentifier(name, itemStack.getItemDamage());
|
||||
}
|
||||
|
||||
public static UniqueMetaIdentifier createFor (Block block, int meta) {
|
||||
if (block == null)
|
||||
return null;
|
||||
|
||||
String name = GameData.getBlockRegistry().getNameForObject(block);
|
||||
return new UniqueMetaIdentifier(name, meta);
|
||||
}
|
||||
|
||||
public static UniqueMetaIdentifier createFor (Block block) {
|
||||
if (block == null)
|
||||
return null;
|
||||
|
||||
String name = GameData.getBlockRegistry().getNameForObject(block);
|
||||
return new UniqueMetaIdentifier(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.util;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class UniqueMetaRegistry<E>
|
||||
{
|
||||
private Map<UniqueMetaIdentifier, E> registry;
|
||||
|
||||
public UniqueMetaRegistry () {
|
||||
registry = new HashMap<UniqueMetaIdentifier, E>();
|
||||
}
|
||||
|
||||
public void register (UniqueMetaIdentifier id, E entry) {
|
||||
registry.put(id, entry);
|
||||
}
|
||||
|
||||
public E getEntry (UniqueMetaIdentifier id) {
|
||||
if (id == null)
|
||||
return null;
|
||||
|
||||
if (registry.containsKey(id))
|
||||
return registry.get(id);
|
||||
|
||||
if (id.meta != OreDictionary.WILDCARD_VALUE) {
|
||||
id = new UniqueMetaIdentifier(id.modId, id.name);
|
||||
if (registry.containsKey(id))
|
||||
return registry.get(id);
|
||||
|
||||
if (!id.name.isEmpty()) {
|
||||
id = new UniqueMetaIdentifier(id.modId);
|
||||
if (registry.containsKey(id))
|
||||
return registry.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void remove (UniqueMetaIdentifier id) {
|
||||
if (id != null)
|
||||
registry.remove(id);
|
||||
}
|
||||
|
||||
public Set<Map.Entry<UniqueMetaIdentifier, E>> entrySet () {
|
||||
return registry.entrySet();
|
||||
}
|
||||
|
||||
public void clear () {
|
||||
registry.clear();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user