2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2017-03-14 13:59:17 +01:00
|
|
|
package techreborn.compat.crafttweaker;
|
2016-03-02 14:52:17 +01:00
|
|
|
|
2017-06-28 21:50:00 +02:00
|
|
|
import crafttweaker.api.item.IIngredient;
|
|
|
|
import crafttweaker.api.item.IItemStack;
|
2017-10-11 18:42:27 +02:00
|
|
|
import gnu.trove.set.TCharSet;
|
|
|
|
import gnu.trove.set.hash.TCharHashSet;
|
2016-03-02 14:52:17 +01:00
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
2017-06-11 22:22:07 +02:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-02 14:52:17 +01:00
|
|
|
import reborncore.common.util.ItemUtils;
|
|
|
|
import stanhebben.zenscript.annotations.ZenClass;
|
|
|
|
import stanhebben.zenscript.annotations.ZenMethod;
|
|
|
|
import techreborn.api.RollingMachineRecipe;
|
2017-09-27 14:45:49 +02:00
|
|
|
import techreborn.api.TechRebornAPI;
|
2016-03-02 14:52:17 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2017-06-11 22:22:07 +02:00
|
|
|
import java.util.Map;
|
2016-03-02 14:52:17 +01:00
|
|
|
|
|
|
|
@ZenClass("mods.techreborn.rollingMachine")
|
2017-03-14 13:59:17 +01:00
|
|
|
public class CTRollingMachine {
|
2016-03-02 14:52:17 +01:00
|
|
|
|
2017-09-27 14:45:49 +02:00
|
|
|
@ZenMethod
|
|
|
|
public static void addShaped(IItemStack output, IIngredient[][] ingredients) {
|
|
|
|
TechRebornAPI.addRollingOreMachinceRecipe(RollingMachineRecipe.getNameForRecipe(CraftTweakerCompat.toStack(output)), CraftTweakerCompat.toStack(output), toShapedObjects(ingredients));
|
|
|
|
}
|
2017-06-11 22:22:07 +02:00
|
|
|
|
2017-09-27 14:45:49 +02:00
|
|
|
@ZenMethod
|
|
|
|
public static void addShapeless(IItemStack output, IIngredient[] ingredients) {
|
|
|
|
TechRebornAPI.addShapelessOreRollingMachinceRecipe(RollingMachineRecipe.getNameForRecipe(CraftTweakerCompat.toStack(output)), CraftTweakerCompat.toStack(output), toObjects(ingredients));
|
|
|
|
}
|
2016-03-02 14:52:17 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@ZenMethod
|
|
|
|
public static void removeRecipe(IItemStack output) {
|
2017-06-11 22:22:07 +02:00
|
|
|
List<ResourceLocation> toRemove = new ArrayList<>();
|
|
|
|
for (Map.Entry<ResourceLocation, IRecipe> recipe : RollingMachineRecipe.instance.getRecipeList().entrySet()) {
|
|
|
|
if (ItemUtils.isItemEqual(recipe.getValue().getRecipeOutput(), CraftTweakerCompat.toStack(output), true, false)) {
|
|
|
|
toRemove.add(recipe.getKey());
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-12 15:23:32 +02:00
|
|
|
for (ResourceLocation resourceLocation : toRemove) {
|
2017-06-11 22:22:07 +02:00
|
|
|
RollingMachineRecipe.instance.getRecipeList().remove(resourceLocation);
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
2017-09-27 14:45:49 +02:00
|
|
|
|
2017-10-11 18:42:27 +02:00
|
|
|
//Stolen from https://github.com/jaredlll08/MTLib/blob/1.12/src/main/java/com/blamejared/mtlib/helpers/InputHelper.java#L170-L213
|
|
|
|
//License as seen here: https://github.com/jaredlll08/MTLib/blob/1.12/LICENSE.md (MIT at time of writing)
|
2016-10-08 21:46:16 +02:00
|
|
|
public static Object[] toShapedObjects(IIngredient[][] ingredients) {
|
|
|
|
if (ingredients == null)
|
|
|
|
return null;
|
|
|
|
else {
|
2017-10-11 18:42:27 +02:00
|
|
|
ArrayList<Object> prep = new ArrayList<>();
|
|
|
|
TCharSet usedCharSet = new TCharHashSet();
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
prep.add("abc");
|
|
|
|
prep.add("def");
|
|
|
|
prep.add("ghi");
|
|
|
|
char[][] map = new char[][] { { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'g', 'h', 'i' } };
|
|
|
|
for (int x = 0; x < ingredients.length; x++) {
|
|
|
|
if (ingredients[x] != null) {
|
|
|
|
for (int y = 0; y < ingredients[x].length; y++) {
|
|
|
|
if (ingredients[x][y] != null && x < map.length && y < map[x].length) {
|
|
|
|
prep.add(map[x][y]);
|
2017-10-11 18:42:27 +02:00
|
|
|
usedCharSet.add(map[x][y]);
|
2017-09-09 00:54:43 +02:00
|
|
|
prep.add(CraftTweakerCompat.toObject(ingredients[x][y]));
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-11 18:42:27 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
if (prep.get(i) instanceof String) {
|
|
|
|
String s = (String) prep.get(i);
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
char c = s.charAt(j);
|
|
|
|
if (usedCharSet.contains(c)) {
|
|
|
|
sb.append(c);
|
|
|
|
} else {
|
|
|
|
sb.append(" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prep.set(i, sb.toString());
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
return prep.toArray();
|
|
|
|
}
|
|
|
|
}
|
2017-09-27 14:45:49 +02:00
|
|
|
|
|
|
|
public static Object[] toObjects(IIngredient[] ingredient) {
|
|
|
|
if (ingredient == null)
|
|
|
|
return null;
|
|
|
|
else {
|
|
|
|
Object[] output = new Object[ingredient.length];
|
|
|
|
for (int i = 0; i < ingredient.length; i++) {
|
|
|
|
if (ingredient[i] != null) {
|
|
|
|
output[i] = CraftTweakerCompat.toObject(ingredient[i]);
|
|
|
|
} else
|
|
|
|
output[i] = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|
2016-03-02 14:52:17 +01:00
|
|
|
}
|