diff --git a/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java index f8b6e2433..405eb552c 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java @@ -1,5 +1,6 @@ package com.jaquadro.minecraft.storagedrawers; +import com.jaquadro.minecraft.storagedrawers.config.CompTierRegistry; import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; import com.jaquadro.minecraft.storagedrawers.core.*; import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; @@ -34,6 +35,7 @@ public class StorageDrawers public static SimpleNetworkWrapper network; public static ConfigManager config; + public static CompTierRegistry compRegistry; @Mod.Instance(MOD_ID) public static StorageDrawers instance; @@ -48,6 +50,8 @@ public void preInit (FMLPreInitializationEvent event) { network = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID); network.registerMessage(BlockClickMessage.Handler.class, BlockClickMessage.class, 0, Side.SERVER); + compRegistry = new CompTierRegistry(); + blocks.init(); items.init(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityCompDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityCompDrawers.java index 0bd8a3935..e2e0eb44a 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityCompDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityCompDrawers.java @@ -1,6 +1,7 @@ package com.jaquadro.minecraft.storagedrawers.block.tile; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.config.CompTierRegistry; import com.jaquadro.minecraft.storagedrawers.config.ConfigManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.*; @@ -329,6 +330,12 @@ private void populateSlot (int slot, ItemStack stack, int conversion) { } private ItemStack findHigherTier (ItemStack stack) { + CompTierRegistry.Record record = StorageDrawers.compRegistry.findHigherTier(stack); + if (record != null) { + lookupSizeResult = record.convRate; + return record.upper; + } + CraftingManager cm = CraftingManager.getInstance(); setupLookup(lookup3, stack); @@ -354,6 +361,12 @@ private ItemStack findHigherTier (ItemStack stack) { } private ItemStack findLowerTier (ItemStack stack) { + CompTierRegistry.Record record = StorageDrawers.compRegistry.findLowerTier(stack); + if (record != null) { + lookupSizeResult = record.convRate; + return record.lower; + } + CraftingManager cm = CraftingManager.getInstance(); List recipeList = cm.getRecipeList(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/config/CompTierRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/config/CompTierRegistry.java new file mode 100644 index 000000000..63fe3f8f4 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/config/CompTierRegistry.java @@ -0,0 +1,61 @@ +package com.jaquadro.minecraft.storagedrawers.config; + +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class CompTierRegistry +{ + public class Record { + public ItemStack upper; + public ItemStack lower; + public int convRate; + } + + private List records = new ArrayList(); + + public CompTierRegistry () { + register(new ItemStack(Blocks.clay), new ItemStack(Items.clay_ball), 4); + register(new ItemStack(Blocks.snow), new ItemStack(Items.snowball), 4); + register(new ItemStack(Blocks.glowstone), new ItemStack(Items.glowstone_dust), 4); + register(new ItemStack(Blocks.brick_block), new ItemStack(Items.brick), 4); + register(new ItemStack(Blocks.nether_brick), new ItemStack(Items.netherbrick), 4); + register(new ItemStack(Blocks.quartz_block), new ItemStack(Items.quartz), 4); + } + + public void register (ItemStack upper, ItemStack lower, int convRate) { + Record r = new Record(); + r.upper = upper; + r.lower = lower; + r.convRate = convRate; + + records.add(r); + } + + public Record findHigherTier (ItemStack stack) { + if (stack == null || stack.getItem() == null) + return null; + + for (Record r : records) { + if (stack.isItemEqual(r.lower) && ItemStack.areItemStackTagsEqual(stack, r.lower)) + return r; + } + + return null; + } + + public Record findLowerTier (ItemStack stack) { + if (stack == null || stack.getItem() == null) + return null; + + for (Record r : records) { + if (stack.isItemEqual(r.upper) && ItemStack.areItemStackTagsEqual(stack, r.upper)) + return r; + } + + return null; + } +}