Skip to content

Commit

Permalink
some fixes, Techy Integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
WanionCane committed Jul 12, 2016
1 parent 0c7d4fc commit ef883eb
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 22 deletions.
Binary file added libs/Techy-1.9.4-1.2.0.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion src/main/java/wanion/unidict/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private Config() {}
public static boolean foundryIntegration;
public static boolean ic2Integration;
public static boolean techRebornIntegration;
public static boolean techyIntegration;

static void init()
{
Expand Down Expand Up @@ -90,6 +91,7 @@ static void init()
foundryIntegration = config.getBoolean("foundry", integrations, true, "Foundry Integration.") && foundry;
ic2Integration = config.getBoolean("industrialCraft2", integrations, true, "Industrial Craft 2 Integration.") && ic2;
techRebornIntegration = config.getBoolean("techReborn", integrations, true, "TechReborn Integration.") && isModLoaded("techreborn");
techyIntegration = config.getBoolean("techy", integrations, true, "Techy Integration.") && isModLoaded("Techy");
} catch (Exception e) {
UniDict.getLogger().info("Something went wrong on " + config.getConfigFile() + "loading. " + e);
}
Expand All @@ -109,7 +111,7 @@ public static TObjectLongMap<String> getOwnerOfEveryKindMap(final long kind)

private static TObjectLongMap<String> getOwnerOfEveryThingMap()
{
final String[] ownerOfEveryThing = config.getStringList("ownerOfEveryThing", resources, new String[]{"substratum", "minecraft", "IC2", "techreborn"}, "all the entries will be sorted according to the modID list below\nmust be the exact modID.\n");
final String[] ownerOfEveryThing = config.getStringList("ownerOfEveryThing", resources, new String[]{"substratum", "minecraft", "ic2", "techreborn"}, "all the entries will be sorted according to the modID list below\nmust be the exact modID.\n");
final TObjectLongMap<String> ownerOfEveryThingMap = new TObjectLongHashMap<>(10, 1, Long.MAX_VALUE);
for (int i = 0; i < ownerOfEveryThing.length; i++)
ownerOfEveryThingMap.put(ownerOfEveryThing[i], i);
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/wanion/unidict/helper/RecipeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,24 @@
public class RecipeHelper
{
public static final List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
private static final char[] DEFAULT_RECIPE_CHARS = {' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'};
private static final char[][] SHAPE = new char[][]{{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
private static final Character[] DEFAULT_RECIPE_CHARS = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'};
private static final char[][] SHAPE = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};

private RecipeHelper() {}

@Nonnull
public static Object[] rawShapeToShape(@Nonnull final Object[] objects)
{
int f = 1;
int f = 0;
final char[][] almostTheShape = Arrays.copyOf(SHAPE, 3);
final TObjectCharMap<Object> thingToCharMap = new TObjectCharHashMap<>();
final Map<Integer ,ItemStack> keyStackMap = new THashMap<>();
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
int value = x * 3 + y;
if (objects[value] == null) {
almostTheShape[x][y] = DEFAULT_RECIPE_CHARS[0];
final Map<Integer, ItemStack> keyStackMap = new THashMap<>();
boolean done = false;
for (int x = 0; x < 3 && !done; x++) {
for (int y = 0; y < 3 && !done; y++) {
final int value = x * 3 + y;
if ((done = !(value < objects.length)) || objects[value] == null)
continue;
}
final Object key = objects[value] instanceof ItemStack ? MetaItem.get((ItemStack) objects[value]) : objects[value];
if (key instanceof Integer)
keyStackMap.put((Integer) key, (ItemStack) objects[value]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ final class CraftingIntegration extends AbstractIntegrationThread
@Override
public String call()
{
experimentalRecipeResearcher();
try {
doTheResearch();
} catch (Exception e) { UniDict.getLogger().error(threadName + e); }
return threadName + "Why so many recipes? I had to deal with a lot of recipes.";
}

private void experimentalRecipeResearcher()
private void doTheResearch()
{
final Map<UniResourceContainer, TIntObjectMap<List<IRecipe>>> smartRecipeMap = new THashMap<>();
IRecipe bufferRecipe;
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/wanion/unidict/integration/IC2Integration.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,48 @@
* file, You can obtain one at http://mozilla.org/MPL/1.1/.
*/

import ic2.api.recipe.IMachineRecipeManager;
import ic2.api.recipe.IRecipeInput;
import ic2.api.recipe.RecipeOutput;
import ic2.api.recipe.Recipes;
import ic2.core.recipe.BasicMachineRecipeManager;
import wanion.unidict.UniDict;
import wanion.unidict.common.FixedSizeList;
import wanion.unidict.common.Util;

import java.util.List;
import java.util.Map;

final class IC2Integration extends AbstractIntegrationThread
{
private final List<Iterable<IMachineRecipeManager.RecipeIoContainer>> ic2MachinesRecipeList = new FixedSizeList<>(5);
private final List<Map<IRecipeInput, RecipeOutput>> ic2MachinesRecipeList = new FixedSizeList<>(5);

@SuppressWarnings("unchecked")
IC2Integration()
{
super("Industrial Craft 2");
try {
ic2MachinesRecipeList.add(Recipes.centrifuge.getRecipes());
ic2MachinesRecipeList.add(Recipes.compressor.getRecipes());
ic2MachinesRecipeList.add(Recipes.blastfurnace.getRecipes());
ic2MachinesRecipeList.add(Recipes.macerator.getRecipes());
ic2MachinesRecipeList.add(Recipes.metalformerRolling.getRecipes());
ic2MachinesRecipeList.add(Util.getField(BasicMachineRecipeManager.class, "recipes", Recipes.centrifuge, Map.class));
ic2MachinesRecipeList.add(Util.getField(BasicMachineRecipeManager.class, "recipes", Recipes.compressor, Map.class));
ic2MachinesRecipeList.add(Util.getField(BasicMachineRecipeManager.class, "recipes", Recipes.blastfurnace, Map.class));
ic2MachinesRecipeList.add(Util.getField(BasicMachineRecipeManager.class, "recipes", Recipes.macerator, Map.class));
ic2MachinesRecipeList.add(Util.getField(BasicMachineRecipeManager.class, "recipes", Recipes.metalformerRolling, Map.class));
} catch (Exception e) { UniDict.getLogger().error(threadName + e); }
}

@Override
public String call()
{
ic2MachinesRecipeList.forEach(recipeIterable -> {
ic2MachinesRecipeList.forEach(map -> {
try {
recipeIterable.forEach(recipe -> resourceHandler.getMainItemStackList(recipe.output.items));
fixMachinesOutputs(map);
} catch (Exception e) { UniDict.getLogger().error(threadName + e); }
});
return threadName + "The world appears to be entirely industrialized.";
}

private void fixMachinesOutputs(Map<IRecipeInput, RecipeOutput> recipes)
{
for (Map.Entry<IRecipeInput, RecipeOutput> recipe : recipes.entrySet())
recipe.setValue(new RecipeOutput(recipe.getValue().metadata, resourceHandler.getMainItemStackList(recipe.getValue().items)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ protected void init()
manager.add(IC2Integration.class);
if (techRebornIntegration)
manager.add(TechRebornIntegration.class);
if (techyIntegration)
manager.add(TechyIntegration.class);
}
}
48 changes: 48 additions & 0 deletions src/main/java/wanion/unidict/integration/TechyIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package wanion.unidict.integration;

/*
* Created by WanionCane(https://github.com/WanionCane).
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 1.1. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/1.1/.
*/

import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.tuple.ImmutableTriple;
import tbsc.techy.recipe.CrusherRecipes;
import wanion.unidict.UniDict;

import java.util.Map;

final class TechyIntegration extends AbstractIntegrationThread
{
TechyIntegration()
{
super("Techy");
}

@Override
public String call()
{
try {
fixCrusherRecipes();
} catch (Exception e) { UniDict.getLogger().error(threadName + e); }
return threadName + "What? something was wrong with Techy Crusher? =O";
}

private void fixCrusherRecipes()
{
final Map<ImmutableTriple<ItemStack, ItemStack, Integer>, Float> experienceMap = CrusherRecipes.instance().getExperienceMap();
final Map<ImmutableTriple<ItemStack, ItemStack, Integer>, Integer> energyMap = CrusherRecipes.instance().getEnergyMap();
CrusherRecipes.instance().getRecipeMap().entrySet().forEach(recipe -> {
final ImmutableTriple<ItemStack, ItemStack, Integer> tripleOutput = recipe.getValue();
final Float experiencePerRecipe = experienceMap.remove(tripleOutput);
final Integer energyRequired = energyMap.remove(tripleOutput);
final ImmutableTriple<ItemStack, ItemStack, Integer> newOutput = ImmutableTriple.of(resourceHandler.getMainItemStack(tripleOutput.getLeft()), resourceHandler.getMainItemStack(tripleOutput.getMiddle()), tripleOutput.right);
experienceMap.put(newOutput, experiencePerRecipe);
energyMap.put(newOutput, energyRequired);
recipe.setValue(newOutput);
});
}
}

0 comments on commit ef883eb

Please sign in to comment.