TechReborn/src/main/java/techreborn/compat/crafttweaker/CTRollingMachine.java

90 lines
3.3 KiB
Java
Raw Normal View History

/*
* 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;
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;
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-06-11 22:22:07 +02:00
//TODO 1.12 Crafttweaker
2017-06-12 15:23:32 +02:00
// @ZenMethod
// public static void addShaped(IItemStack output, IIngredient[][] ingredients) {
// TechRebornAPI.addRollingOreMachinceRecipe(toStack(output), toShapedObjects(ingredients));
// }
2017-06-11 22:22:07 +02:00
2017-06-12 15:23:32 +02:00
// @ZenMethod
// public static void addShapeless(IItemStack output, IIngredient[] ingredients) {
// TechRebornAPI.addShapelessOreRollingMachinceRecipe(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-09 00:54:43 +02:00
2016-10-08 21:46:16 +02:00
public static Object[] toShapedObjects(IIngredient[][] ingredients) {
if (ingredients == null)
return null;
else {
2017-09-09 00:54:43 +02:00
ArrayList<Object> prep = new ArrayList<Object>();
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-09-09 00:54:43 +02:00
prep.add(CraftTweakerCompat.toObject(ingredients[x][y]));
2016-10-08 21:46:16 +02:00
}
}
}
}
return prep.toArray();
}
}
2016-03-02 14:52:17 +01:00
}