Managed to sniff out that damned bug (ImmutableMultimaps prune keys with

a stack size > 1, wtf?)
This commit is contained in:
pahimar 2013-10-27 18:18:09 -04:00
parent f2284af0d2
commit 28ad3b60f4
3 changed files with 23 additions and 41 deletions

View file

@ -2,13 +2,10 @@ package com.pahimar.ee3;
import java.io.File;
import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.common.MinecraftForge;
@ -29,9 +26,8 @@ import com.pahimar.ee3.core.helper.LogHelper;
import com.pahimar.ee3.core.helper.VersionHelper;
import com.pahimar.ee3.core.proxy.CommonProxy;
import com.pahimar.ee3.creativetab.CreativeTabEE3;
import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.emc.EmcRegistry;
import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.item.crafting.RecipeRegistry;
import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes;
import com.pahimar.ee3.lib.InterModComms;
import com.pahimar.ee3.lib.Reference;
@ -168,7 +164,6 @@ public class EquivalentExchange3 {
// recipe registry works
FMLInterModComms.sendMessage(Reference.MOD_ID, InterModComms.ADD_RECIPE, NBTHelper.encodeRecipeAsNBT(Item.bucketWater, Arrays.asList(Item.bucketEmpty, Block.waterStill)));
FMLInterModComms.sendMessage(Reference.MOD_ID, InterModComms.ADD_RECIPE, NBTHelper.encodeRecipeAsNBT(Item.bucketLava, Arrays.asList(Item.bucketEmpty, Block.lavaStill)));
FMLInterModComms.sendMessage(Reference.MOD_ID, InterModComms.ADD_RECIPE, NBTHelper.encodeRecipeAsNBT(new ItemStack(Item.glassBottle.itemID, 3, 0), Arrays.asList(Block.glass, Block.glass, Block.glass)));
}
@EventHandler
@ -177,11 +172,7 @@ public class EquivalentExchange3 {
// Initialize the Addon Handler
AddonHandler.init();
Set<CustomWrappedStack> recipeOutputs = new TreeSet<CustomWrappedStack>(RecipeRegistry.getRecipeMappings().keySet());
for (CustomWrappedStack recipeOutput : recipeOutputs) {
LogHelper.debug(String.format("Recipe Output: %s, Recipe Inputs: %s", recipeOutput, RecipeRegistry.getRecipeMappings().get(recipeOutput)));
}
EmcRegistry.getStacksInRange(0, 10000);
}
@EventHandler

View file

@ -47,10 +47,8 @@ public class EmcDefaultValues {
valueMap.put(new CustomWrappedStack(Block.deadBush), new EmcValue(1, EmcType.CORPOREAL));
valueMap.put(new CustomWrappedStack(Block.ice), new EmcValue(1, EmcType.CORPOREAL));
valueMap.put(new CustomWrappedStack(new ItemStack(Block.sandStone.blockID, 1, OreDictionary.WILDCARD_VALUE)), new EmcValue(4, EmcType.CORPOREAL));
valueMap.put(new CustomWrappedStack(new ItemStack(Block.anvil.blockID, 1, OreDictionary.WILDCARD_VALUE)), new EmcValue(2, EmcType.CORPOREAL));
valueMap.put(new CustomWrappedStack(new OreStack(new ItemStack(Block.wood))), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.ESSENTIA, 1))));
valueMap.put(new CustomWrappedStack(new OreStack(new ItemStack(Block.planks))), new EmcValue(8, EmcType.CORPOREAL));
valueMap.put(new CustomWrappedStack(new OreStack(new ItemStack(Item.stick))), new EmcValue(4, EmcType.CORPOREAL));
valueMap.put(new CustomWrappedStack(Item.ingotIron), new EmcValue(256, EmcType.CORPOREAL));
valueMap.put(new CustomWrappedStack(Block.oreIron), new EmcValue(256, EmcType.CORPOREAL));
valueMap.put(new CustomWrappedStack(Item.ingotGold), new EmcValue(2048, EmcType.CORPOREAL));

View file

@ -2,6 +2,7 @@ package com.pahimar.ee3.item.crafting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
@ -9,27 +10,27 @@ import java.util.TreeSet;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.pahimar.ee3.item.CustomWrappedStack;
public class RecipeRegistry {
private static RecipeRegistry recipeRegistry = null;
private ImmutableMultimap<CustomWrappedStack, List<CustomWrappedStack>> recipeMap;
private ImmutableList<CustomWrappedStack> discoveredStacks;
private Multimap<CustomWrappedStack, List<CustomWrappedStack>> recipeMap;
private List<CustomWrappedStack> discoveredStacks;
public static ImmutableMultimap<CustomWrappedStack, List<CustomWrappedStack>> getRecipeMappings() {
public static Multimap<CustomWrappedStack, List<CustomWrappedStack>> getRecipeMappings() {
lazyInit();
return recipeRegistry.recipeMap;
}
public static ImmutableList<CustomWrappedStack> getDiscoveredStacks() {
public static List<CustomWrappedStack> getDiscoveredStacks() {
lazyInit();
return recipeRegistry.discoveredStacks;
return Collections.unmodifiableList(recipeRegistry.discoveredStacks);
}
private static void lazyInit() {
@ -42,19 +43,16 @@ public class RecipeRegistry {
private void init() {
ImmutableMultimap.Builder<CustomWrappedStack, List<CustomWrappedStack>> immutableRecipeMap = ImmutableMultimap.builder();
recipeMap = HashMultimap.create();
// Add potion recipes
immutableRecipeMap.putAll(RecipesPotions.getPotionRecipes());
recipeMap.putAll(RecipesPotions.getPotionRecipes());
// Add recipes in the vanilla crafting manager
immutableRecipeMap.putAll(RecipesVanilla.getVanillaRecipes());
recipeMap.putAll(RecipesVanilla.getVanillaRecipes());
// Add recipes gathered via IMC
immutableRecipeMap.putAll(RecipesIMC.getIMCRecipes());
// Finalize the Immutable Recipe Map
recipeMap = immutableRecipeMap.build();
recipeMap.putAll(RecipesIMC.getIMCRecipes());
// Discover all stacks that we can
discoverStacks();
@ -62,18 +60,18 @@ public class RecipeRegistry {
private void discoverStacks() {
List<CustomWrappedStack> foundStacks = new ArrayList<CustomWrappedStack>();
discoveredStacks = new ArrayList<CustomWrappedStack>();
// Scan stacks from known recipes
for (CustomWrappedStack recipeOutput : recipeMap.keySet()) {
if (!foundStacks.contains(new CustomWrappedStack(recipeOutput.getWrappedStack()))) {
foundStacks.add(new CustomWrappedStack(recipeOutput.getWrappedStack()));
if (!discoveredStacks.contains(new CustomWrappedStack(recipeOutput.getWrappedStack()))) {
discoveredStacks.add(new CustomWrappedStack(recipeOutput.getWrappedStack()));
}
for (List<CustomWrappedStack> recipeInputList : recipeMap.get(recipeOutput)) {
for (CustomWrappedStack recipeInput : recipeInputList) {
if (!foundStacks.contains(new CustomWrappedStack(recipeInput.getWrappedStack()))) {
foundStacks.add(new CustomWrappedStack(recipeInput.getWrappedStack()));
if (!discoveredStacks.contains(new CustomWrappedStack(recipeInput.getWrappedStack()))) {
discoveredStacks.add(new CustomWrappedStack(recipeInput.getWrappedStack()));
}
}
}
@ -86,25 +84,20 @@ public class RecipeRegistry {
for (int meta = 0; meta < 16; meta++) {
CustomWrappedStack wrappedItemStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i].itemID, 1, meta));
if (!foundStacks.contains(wrappedItemStack)) {
foundStacks.add(wrappedItemStack);
if (!discoveredStacks.contains(wrappedItemStack)) {
discoveredStacks.add(wrappedItemStack);
}
}
}
else {
CustomWrappedStack wrappedItemStack = new CustomWrappedStack(Item.itemsList[i]);
if (!foundStacks.contains(wrappedItemStack)) {
foundStacks.add(wrappedItemStack);
if (!discoveredStacks.contains(wrappedItemStack)) {
discoveredStacks.add(wrappedItemStack);
}
}
}
}
// Add all the discovered stacks to the immutable list of discovered stacks
ImmutableList.Builder<CustomWrappedStack> discoveredStacksBuilder = ImmutableList.builder();
discoveredStacksBuilder.addAll(foundStacks.iterator());
discoveredStacks = discoveredStacksBuilder.build();
}
@Override