From ecbcc5699753e1a0e33642af4c20077bb5e7d367 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Thu, 11 Jun 2020 00:40:14 +0200 Subject: [PATCH] Added grinder and inscriber recipes. Improved JEI integration. --- .../appeng/api/features/IGrinderRecipe.java | 93 ---- .../api/features/IGrinderRecipeBuilder.java | 115 ---- .../appeng/api/features/IGrinderRegistry.java | 101 ---- .../api/features/IRegistryContainer.java | 5 - src/main/java/appeng/FixupIngredients.java | 182 +++++++ .../container/slot/SlotRestrictedInput.java | 3 +- src/main/java/appeng/core/AEConfig.java | 6 +- src/main/java/appeng/core/Registration.java | 9 +- .../registries/RegistryContainer.java | 9 - .../grinder/AppEngGrinderRecipe.java | 108 ---- .../grinder/GrinderRecipeManager.java | 489 ------------------ .../modules/jei/GrinderRecipeCategory.java | 2 +- .../modules/jei/InscriberRecipeCategory.java | 14 +- .../integration/modules/jei/JEIPlugin.java | 63 +-- .../java/appeng/recipes/AEItemResolver.java | 196 ------- .../recipes/handlers/GrinderRecipe.java | 13 +- .../handlers/GrinderRecipeSerializer.java | 19 +- .../recipes/handlers/GrinderRecipes.java | 41 ++ .../recipes/handlers/InscriberHandler.java | 56 -- .../recipes/handlers/InscriberRecipe.java | 49 +- .../handlers/InscriberRecipeSerializer.java | 79 +++ .../appeng/tile/grindstone/TileGrinder.java | 80 ++- .../recipes/grinder/certus_quartz_dust.json | 12 + .../grinder/certus_quartz_dust_ore.json | 17 + .../recipes/grinder/ender_dust.json | 12 + .../recipes/grinder/flour.json | 12 + .../recipes/grinder/fluix_dust.json | 2 +- .../recipes/grinder/gold_dust_ingot.json | 12 + .../recipes/grinder/gold_dust_ore.json | 17 + .../recipes/grinder/iron_dust_ingot.json | 12 + .../recipes/grinder/iron_dust_ore.json | 17 + .../recipes/grinder/nether_quartz_dust.json | 12 + .../grinder/nether_quartz_dust_ore.json | 17 + .../recipes/misc/seeds_nether.json | 2 +- .../recipes/network/wireless_booster.json | 2 +- .../recipes/smelting/bread.json | 6 +- .../recipes/smelting/gold_ingot.json | 6 +- .../recipes/smelting/iron_ingot.json | 6 +- .../recipes/smelting/silicon.json | 6 +- .../smelting/smooth_sky_stone_block.json | 6 +- .../tags/items/dusts/ender.json | 2 +- .../data/forge/tags/items/dusts/gold.json | 5 + .../data/forge/tags/items/dusts/iron.json | 5 + .../forge/tags/items/gems/certus_quartz.json | 6 + .../forge/tags/items/ores/certus_quartz.json | 6 + 45 files changed, 614 insertions(+), 1318 deletions(-) delete mode 100644 src/api/java/appeng/api/features/IGrinderRecipe.java delete mode 100644 src/api/java/appeng/api/features/IGrinderRecipeBuilder.java delete mode 100644 src/api/java/appeng/api/features/IGrinderRegistry.java create mode 100644 src/main/java/appeng/FixupIngredients.java delete mode 100644 src/main/java/appeng/core/features/registries/grinder/AppEngGrinderRecipe.java delete mode 100644 src/main/java/appeng/core/features/registries/grinder/GrinderRecipeManager.java delete mode 100644 src/main/java/appeng/recipes/AEItemResolver.java create mode 100644 src/main/java/appeng/recipes/handlers/GrinderRecipes.java delete mode 100644 src/main/java/appeng/recipes/handlers/InscriberHandler.java create mode 100644 src/main/java/appeng/recipes/handlers/InscriberRecipeSerializer.java create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/certus_quartz_dust.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/certus_quartz_dust_ore.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/ender_dust.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/flour.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/gold_dust_ingot.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/gold_dust_ore.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/iron_dust_ingot.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/iron_dust_ore.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/nether_quartz_dust.json create mode 100644 src/main/resources/data/appliedenergistics2/recipes/grinder/nether_quartz_dust_ore.json create mode 100644 src/main/resources/data/forge/tags/items/dusts/gold.json create mode 100644 src/main/resources/data/forge/tags/items/dusts/iron.json create mode 100644 src/main/resources/data/forge/tags/items/gems/certus_quartz.json create mode 100644 src/main/resources/data/forge/tags/items/ores/certus_quartz.json diff --git a/src/api/java/appeng/api/features/IGrinderRecipe.java b/src/api/java/appeng/api/features/IGrinderRecipe.java deleted file mode 100644 index 2a2cd4423..000000000 --- a/src/api/java/appeng/api/features/IGrinderRecipe.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * 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. - */ - -package appeng.api.features; - - -import java.util.Optional; - -import javax.annotation.Nonnull; - -import net.minecraft.item.ItemStack; - - -/** - * Registration Records for {@link IGrinderRegistry} - */ -public interface IGrinderRecipe -{ - - /** - * the current input - * - * @return input that the grinder will accept. - */ - @Nonnull - ItemStack getInput(); - - /** - * gets the current output - * - * @return output that the grinder will produce - */ - @Nonnull - ItemStack getOutput(); - - /** - * gets the current output - * - * @return output that the grinder will produce - */ - @Nonnull - Optional getOptionalOutput(); - - /** - * gets the current output - * - * @return output that the grinder will produce - */ - Optional getSecondOptionalOutput(); - - /** - * 0.0 - 1.0 the chance that the optional output will be generated. - * - * @return chance of optional output - */ - @Nonnull - float getOptionalChance(); - - /** - * 0.0 - 1.0 the chance that the optional output will be generated. - * - * @return second optional output chance - */ - float getSecondOptionalChance(); - - /** - * Amount of turns required to process the item. - * - * @return number of turns it takes to produce the output from the input. - */ - int getRequiredTurns(); - -} diff --git a/src/api/java/appeng/api/features/IGrinderRecipeBuilder.java b/src/api/java/appeng/api/features/IGrinderRecipeBuilder.java deleted file mode 100644 index 9c0fcfc76..000000000 --- a/src/api/java/appeng/api/features/IGrinderRecipeBuilder.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * 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. - */ - -package appeng.api.features; - - -import javax.annotation.Nonnegative; -import javax.annotation.Nonnull; - -import net.minecraft.item.ItemStack; - - -/** - * Builder for a grinder recipe. - * - * The only default value provided are turns at a value of 8. - * - * @author yueh - * @version rv5 - * @since rv5 - */ -public interface IGrinderRecipeBuilder -{ - - /** - * Creates an grinder recipe with inputs. - * Needs to be invoked. - * - * @param input new input for the recipe - * - * @return currently used builder - */ - @Nonnull - IGrinderRecipeBuilder withInput( @Nonnull ItemStack input ); - - /** - * Creates an grinder recipe with output. - * Needs to be invoked. - * - * @param output new output for the recipe - * - * @return currently used builder - */ - @Nonnull - IGrinderRecipeBuilder withOutput( @Nonnull ItemStack output ); - - /** - * Creates an grinder recipe with the first optional output and its chance. - * - * @param optional new first optional for the recipe - * @param chance chance for the first optional output, must be within 0.0 - 1.0 - * - * @return currently used builder - */ - @Nonnull - IGrinderRecipeBuilder withFirstOptional( @Nonnull ItemStack optional, float chance ); - - /** - * Creates an grinder recipe with the second optional output and its chance. - * - * @param optional new second optional for the recipe - * @param chance chance for the second optional output, must be within 0.0 - 1.0 - * - * @return currently used builder - */ - @Nonnull - IGrinderRecipeBuilder withSecondOptional( @Nonnull ItemStack optional, float chance ); - - /** - * Creates an grinder recipe with the amount of turns as cost. - * - * Defaults to 8 when not called. - * - * @param turns new turns for the recipe, must be > 0 - * - * @return currently used builder - */ - @Nonnull - IGrinderRecipeBuilder withTurns( @Nonnegative int turns ); - - /** - * Finalizes the process of making the recipe. - * Needs to be invoked to fetch grinder recipe. - * - * @return valid grinder recipe - * - * @throws IllegalStateException when input is not defined - * @throws IllegalStateException when input has no size - * @throws IllegalStateException when output is not defined - * @throws IllegalStateException when both optionals are not defined - * @throws IllegalStateException when process type is not defined - */ - @Nonnull - IGrinderRecipe build(); -} diff --git a/src/api/java/appeng/api/features/IGrinderRegistry.java b/src/api/java/appeng/api/features/IGrinderRegistry.java deleted file mode 100644 index 585b2695f..000000000 --- a/src/api/java/appeng/api/features/IGrinderRegistry.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2013 AlgorithmX2 - * - * 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. - */ - -package appeng.api.features; - - -import java.util.Collection; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraft.item.ItemStack; - - -/** - * Lets you manipulate Grinder Recipes, by adding or editing existing ones. - */ -public interface IGrinderRegistry -{ - - /** - * Extensible way to create a grinder recipe. - * - * @return builder for grinder recipes - */ - @Nonnull - IGrinderRecipeBuilder builder(); - - /** - * An immutable list of the currently registered recipes. - * - * @return currentlyRegisteredRecipes - */ - @Nonnull - Collection getRecipes(); - - /** - * Add a new recipe to the registry. - */ - boolean addRecipe( IGrinderRecipe recipe ); - - /** - * Remove the specific from the recipe list. - * - * @param recipe The recipe to be removed. - * @return true, if it was removed - */ - boolean removeRecipe( @Nonnull IGrinderRecipe recipe ); - - /** - * Searches for a recipe for a given input, and returns it. - * - * @param input The {@link ItemStack} to be grinded. - * - * @return identified recipe or null - */ - @Nullable - IGrinderRecipe getRecipeForInput( @Nonnull ItemStack input ); - - /** - * Allows do add a custom ratio from an ore to dust when being grinded. - * - * The default ratio is 1 ore to 2 dusts. - * - * These have to be added before any recipe is registered. Otherwise it will use the default value. - * - * @param oredictName The name of the ore; - * @param ratio The amount, must be > 0; - */ - void addDustRatio( @Nonnull String oredictName, int ratio ); - - /** - * Remove a custom ratio for a specific ore name. - * - * Will use the default of 2 value afterwards. - * - * @param oredictName The name of the ore; - */ - boolean removeDustRatio( @Nonnull String oredictName ); - -} diff --git a/src/api/java/appeng/api/features/IRegistryContainer.java b/src/api/java/appeng/api/features/IRegistryContainer.java index e3780c0dd..a0f8671f7 100644 --- a/src/api/java/appeng/api/features/IRegistryContainer.java +++ b/src/api/java/appeng/api/features/IRegistryContainer.java @@ -67,11 +67,6 @@ public interface IRegistryContainer */ ICellRegistry cell(); - /** - * Manage grinder recipes via API - */ - IGrinderRegistry grinder(); - /** * Manage inscriber recipes via API */ diff --git a/src/main/java/appeng/FixupIngredients.java b/src/main/java/appeng/FixupIngredients.java new file mode 100644 index 000000000..a9db46085 --- /dev/null +++ b/src/main/java/appeng/FixupIngredients.java @@ -0,0 +1,182 @@ +package appeng; + +import appeng.api.util.AEColor; +import appeng.core.AppEng; +import appeng.items.materials.MaterialType; +import appeng.items.parts.PartType; +import com.google.gson.*; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Map; + +public class FixupIngredients { + + private static Gson gson = new GsonBuilder() + .setPrettyPrinting() + .create(); + + private static JsonObject visitObjProps(JsonObject obj) { + for (Map.Entry e : obj.entrySet()) { + e.setValue(visitAndReplace(e.getValue())); + } + return obj; + } + + private static JsonElement visitAndReplace(JsonElement el) { + if (el.isJsonArray()) { + JsonArray arr = el.getAsJsonArray(); + for (int i = 0; i < arr.size(); i++) { + arr.set(i, visitAndReplace(arr.get(i))); + } + return arr; + } + if (!el.isJsonObject()) { + return el; + } + + JsonObject obj = el.getAsJsonObject(); + if (obj.size() != 2 && (obj.size() != 3 || !obj.has("count"))) { + return visitObjProps(obj); + } + Integer count = null; + if (obj.has("count")) { + count = obj.get("count").getAsInt(); + } + + JsonPrimitive type = obj.getAsJsonPrimitive("type"); + + if (type == null) { + return visitObjProps(obj); + } + + if ("forge:ore_dict".equals(type.getAsString())) { + String ore = obj.get("ore").getAsString(); + JsonObject r = new JsonObject(); + r.add("tag", new JsonPrimitive(AppEng.MOD_ID + ':' + "ore_" + ore)); + return r; + } + + if (!type.getAsString().equals("appliedenergistics2:part")) { + return visitObjProps(obj); + } + String part = obj.getAsJsonPrimitive("part").getAsString(); + + String itemName = null; + if (part.startsWith("material.")) { + String mtName = part.substring(9).toUpperCase(); + if ("WIRELESS".equals(mtName)) { + mtName = "WIRELESS_RECEIVER"; + } + + itemName = mtName.toLowerCase(); + } else if (part.startsWith("part.")) { + part = part.substring(5); + + if ("fluid_interface".equals(part)) { + part = "cable_fluid_interface"; + } else if ("interface".equals(part)) { + part = "cable_interface"; + } + } + + if (itemName == null) { + // Handle tags + String tagName = null; + if ( part.equalsIgnoreCase("cable_glass")) { + tagName = "glass_cable"; + } else if (part.equalsIgnoreCase("cable_covered")) { + tagName = "covered_cable"; + } else if (part.equalsIgnoreCase("cable_smart")) { + tagName = "smart_cable"; + } else if (part.equalsIgnoreCase("cable_dense_covered")) { + tagName = "covered_dense_cable"; + } else if (part.equalsIgnoreCase("cable_dense_smart")) { + tagName = "smart_dense_cable"; + } + if (tagName != null) { + JsonObject r = new JsonObject(); + r.add("tag", new JsonPrimitive(AppEng.MOD_ID + ':' + tagName)); + return r; + } + itemName = part.toLowerCase(); + } + + for (AEColor c : AEColor.values()) { + String colorSuffix = '.' + c.registryPrefix; + if (itemName.endsWith(colorSuffix)) { + String p = itemName.substring(0, itemName.length() - colorSuffix.length()); + itemName = c.registryPrefix + "_" + p; + break; + } + } + + if (itemName.startsWith("p2p_tunnel_")) { + itemName = itemName.substring("p2p_tunnel_".length()) + "_p2p_tunnel"; + } + + JsonObject r = new JsonObject(); + r.add("item", new JsonPrimitive(AppEng.MOD_ID + ':' + itemName)); + if (count != null) { + r.add("count", new JsonPrimitive(count)); + } + return r; + + } + + public static void main(String[] args) throws IOException { + + Path p= Paths.get("D:\\Applied-Energistics-2\\src\\main\\resources\\data\\appliedenergistics2"); + + Files.walkFileTree(p, new FileVisitor() { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (!file.getFileName().toString().endsWith(".json")) { + return FileVisitResult.CONTINUE; + } + if (file.getFileName().toString().contains("_constants")) { + return FileVisitResult.CONTINUE; + } + if (file.getFileName().toString().contains("_factories")) { + return FileVisitResult.CONTINUE; + } + + JsonElement el; + try (Reader r = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { + el = visitAndReplace(gson.fromJson(r, JsonElement.class)); + } catch (Exception e) { + System.err.println("Failed to process file " + file); + e.printStackTrace(); + return FileVisitResult.CONTINUE; + } + + try (Writer w = Files.newBufferedWriter(file, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { + gson.toJson(el, w); + } + + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + }); + + } + +} diff --git a/src/main/java/appeng/container/slot/SlotRestrictedInput.java b/src/main/java/appeng/container/slot/SlotRestrictedInput.java index 4dfb31f36..6e1d353be 100644 --- a/src/main/java/appeng/container/slot/SlotRestrictedInput.java +++ b/src/main/java/appeng/container/slot/SlotRestrictedInput.java @@ -19,6 +19,7 @@ package appeng.container.slot; +import appeng.recipes.handlers.GrinderRecipes; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Slot; @@ -192,7 +193,7 @@ public class SlotRestrictedInput extends AppEngSlot case VIEW_CELL: return items.viewCell().isSameAs( i ); case ORE: - return AEApi.instance().registries().grinder().getRecipeForInput( i ) != null; + return GrinderRecipes.isValidIngredient(p.player.world, i); case FUEL: return ForgeHooks.getBurnTime( i ) > 0; case POWERED_TOOL: diff --git a/src/main/java/appeng/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java index 73971c5ca..613ba1111 100644 --- a/src/main/java/appeng/core/AEConfig.java +++ b/src/main/java/appeng/core/AEConfig.java @@ -101,7 +101,7 @@ public final class AEConfig implements IConfigurableObject, IConfigManagerHost // Grindstone private List grinderOres; private Set grinderBlackList; - private double oreDoublePercentage; + private float oreDoublePercentage; // Batteries private int wirelessTerminalBattery; @@ -154,7 +154,7 @@ public final class AEConfig implements IConfigurableObject, IConfigManagerHost this.grinderOres = new ArrayList<>(config.grinderOres.get()); this.grinderBlackList = new HashSet<>(config.grinderBlackList.get()); - this.oreDoublePercentage = config.oreDoublePercentage.get(); + this.oreDoublePercentage = config.oreDoublePercentage.get().floatValue(); // FIXME: why is this here exactly??? this.settings.registerSetting( Settings.SEARCH_TOOLTIPS, YesNo.YES ); @@ -522,7 +522,7 @@ public final class AEConfig implements IConfigurableObject, IConfigManagerHost return this.grinderBlackList; } - public double getOreDoublePercentage() + public float getOreDoublePercentage() { return this.oreDoublePercentage; } diff --git a/src/main/java/appeng/core/Registration.java b/src/main/java/appeng/core/Registration.java index f0e674081..b296418bf 100644 --- a/src/main/java/appeng/core/Registration.java +++ b/src/main/java/appeng/core/Registration.java @@ -96,6 +96,8 @@ import appeng.recipes.conditions.FeaturesEnabled; import appeng.recipes.game.DisassembleRecipe; import appeng.recipes.handlers.GrinderRecipe; import appeng.recipes.handlers.GrinderRecipeSerializer; +import appeng.recipes.handlers.InscriberRecipe; +import appeng.recipes.handlers.InscriberRecipeSerializer; import appeng.server.AECommand; import appeng.tile.AEBaseTile; import net.minecraft.advancements.CriteriaTriggers; @@ -587,14 +589,13 @@ final class Registration final ApiDefinitions definitions = Api.INSTANCE.definitions(); GrinderRecipe.TYPE = new AERecipeType<>(GrinderRecipeSerializer.INSTANCE.getRegistryName()); + InscriberRecipe.TYPE = new AERecipeType<>(InscriberRecipeSerializer.INSTANCE.getRegistryName()); r.registerAll( DisassembleRecipe.SERIALIZER, - GrinderRecipeSerializer.INSTANCE + GrinderRecipeSerializer.INSTANCE, + InscriberRecipeSerializer.INSTANCE // FacadeRecipe.getSerializer( (ItemFacade) definitions.items().facade().item() ) FIXME reimplement facades -// this.factories.put( new ResourceLocation( AppEng.MOD_ID, "inscriber" ), new InscriberHandler() ); FIXME re-implement machine recipes -// this.factories.put( new ResourceLocation( AppEng.MOD_ID, "smelt" ), new SmeltingHandler() ); -// this.factories.put( new ResourceLocation( AppEng.MOD_ID, "grinder" ), new GrinderHandler() ); ); CraftingHelper.register( FeaturesEnabled.Serializer.INSTANCE ); diff --git a/src/main/java/appeng/core/features/registries/RegistryContainer.java b/src/main/java/appeng/core/features/registries/RegistryContainer.java index 14678d0ec..5ad03e833 100644 --- a/src/main/java/appeng/core/features/registries/RegistryContainer.java +++ b/src/main/java/appeng/core/features/registries/RegistryContainer.java @@ -20,7 +20,6 @@ package appeng.core.features.registries; import appeng.api.features.IChargerRegistry; -import appeng.api.features.IGrinderRegistry; import appeng.api.features.IInscriberRegistry; import appeng.api.features.ILocatableRegistry; import appeng.api.features.IMatterCannonAmmoRegistry; @@ -37,7 +36,6 @@ import appeng.api.parts.IPartModels; import appeng.api.storage.ICellRegistry; import appeng.core.features.registries.cell.CellRegistry; import appeng.core.features.registries.charger.ChargerRegistry; -import appeng.core.features.registries.grinder.GrinderRecipeManager; import appeng.core.features.registries.inscriber.InscriberRegistry; @@ -52,7 +50,6 @@ import appeng.core.features.registries.inscriber.InscriberRegistry; */ public class RegistryContainer implements IRegistryContainer { - private final IGrinderRegistry grinder = new GrinderRecipeManager(); private final IInscriberRegistry inscriber = new InscriberRegistry(); private final IChargerRegistry charger = new ChargerRegistry(); private final ICellRegistry cell = new CellRegistry(); @@ -97,12 +94,6 @@ public class RegistryContainer implements IRegistryContainer return this.cell; } - @Override - public IGrinderRegistry grinder() - { - return this.grinder; - } - @Override public IInscriberRegistry inscriber() { diff --git a/src/main/java/appeng/core/features/registries/grinder/AppEngGrinderRecipe.java b/src/main/java/appeng/core/features/registries/grinder/AppEngGrinderRecipe.java deleted file mode 100644 index 5aeed1336..000000000 --- a/src/main/java/appeng/core/features/registries/grinder/AppEngGrinderRecipe.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.core.features.registries.grinder; - - -import java.util.Optional; - -import net.minecraft.item.ItemStack; - -import appeng.api.features.IGrinderRecipe; - - -public class AppEngGrinderRecipe implements IGrinderRecipe -{ - - private final ItemStack in; - private final ItemStack out; - - private final float optionalChance; - private final Optional optionalOutput; - - private final float optionalChance2; - private final Optional optionalOutput2; - - private final int turns; - - AppEngGrinderRecipe( final ItemStack input, final ItemStack output, final int cost ) - { - this( input, output, null, null, 0, 0, cost ); - } - - AppEngGrinderRecipe( final ItemStack input, final ItemStack output, final ItemStack optional, final float chance, final int cost ) - { - this( input, output, optional, null, chance, 0, cost ); - } - - AppEngGrinderRecipe( final ItemStack input, final ItemStack output, final ItemStack optional1, final ItemStack optional2, final float chance1, final float chance2, final int cost ) - { - this.in = input; - this.out = output; - - this.optionalOutput = Optional.ofNullable( optional1 ); - this.optionalChance = chance1; - - this.optionalOutput2 = Optional.ofNullable( optional2 ); - this.optionalChance2 = chance2; - - this.turns = cost; - } - - @Override - public ItemStack getInput() - { - return this.in; - } - - @Override - public ItemStack getOutput() - { - return this.out; - } - - @Override - public Optional getOptionalOutput() - { - return this.optionalOutput; - } - - @Override - public Optional getSecondOptionalOutput() - { - return this.optionalOutput2; - } - - @Override - public float getOptionalChance() - { - return this.optionalChance; - } - - @Override - public float getSecondOptionalChance() - { - return this.optionalChance2; - } - - @Override - public int getRequiredTurns() - { - return this.turns; - } -} diff --git a/src/main/java/appeng/core/features/registries/grinder/GrinderRecipeManager.java b/src/main/java/appeng/core/features/registries/grinder/GrinderRecipeManager.java deleted file mode 100644 index d69d55fda..000000000 --- a/src/main/java/appeng/core/features/registries/grinder/GrinderRecipeManager.java +++ /dev/null @@ -1,489 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.core.features.registries.grinder; - - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Map.Entry; - -import javax.annotation.Nonnull; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; - -import net.minecraft.block.Blocks; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; - -import appeng.api.features.IGrinderRecipe; -import appeng.api.features.IGrinderRecipeBuilder; -import appeng.api.features.IGrinderRegistry; -import appeng.api.features.IInscriberRecipe; -import appeng.api.features.IInscriberRecipeBuilder; -import appeng.core.AEConfig; -import appeng.core.AELog; -import appeng.util.Platform; - - -public final class GrinderRecipeManager implements IGrinderRegistry // FIXME, IOreListener -{ - private final Map recipes; - private final Map ores; - private final Map ingots; - private final Map dusts; - private final Map dustToOreRatio; - - public GrinderRecipeManager() - { - this.recipes = Maps.newHashMap(); - this.ores = Maps.newHashMap(); - this.ingots = Maps.newHashMap(); - this.dusts = Maps.newHashMap(); - this.dustToOreRatio = Maps.newHashMap(); - - this.addDustRatio( "Obsidian", 1 ); - this.addDustRatio( "Charcoal", 1 ); - this.addDustRatio( "Coal", 1 ); - - this.addOre( "Coal", new ItemStack( Items.COAL ) ); - this.addOre( "Charcoal", new ItemStack( Items.COAL, 1 ) ); - - this.addOre( "NetherQuartz", new ItemStack( Blocks.NETHER_QUARTZ_ORE ) ); - this.addIngot( "NetherQuartz", new ItemStack( Items.QUARTZ ) ); - - this.addOre( "Gold", new ItemStack( Blocks.GOLD_ORE ) ); - this.addIngot( "Gold", new ItemStack( Items.GOLD_INGOT ) ); - - this.addOre( "Iron", new ItemStack( Blocks.IRON_ORE ) ); - this.addIngot( "Iron", new ItemStack( Items.IRON_INGOT ) ); - - this.addOre( "Obsidian", new ItemStack( Blocks.OBSIDIAN ) ); - - this.addIngot( "Ender", new ItemStack( Items.ENDER_PEARL ) ); - this.addIngot( "EnderPearl", new ItemStack( Items.ENDER_PEARL ) ); - - this.addIngot( "Wheat", new ItemStack( Items.WHEAT ) ); - - // FIXME OreDictionaryHandler.INSTANCE.observe( this ); - } - - @Override - public IGrinderRecipeBuilder builder() - { - return new Builder(); - } - - @Override - public boolean addRecipe( IGrinderRecipe recipe ) - { - Preconditions.checkNotNull( recipe, "Cannot add null as recipe." ); - - return this.injectRecipe( recipe ); - } - - @Override - public Collection getRecipes() - { - return Collections.unmodifiableCollection( this.recipes.values() ); - } - - @Override - public boolean removeRecipe( IGrinderRecipe recipe ) - { - Preconditions.checkNotNull( recipe, "Cannot remove null as recipe." ); - - final CacheKey key = new CacheKey( recipe.getInput() ); - final IGrinderRecipe removedRecipe = this.recipes.remove( key ); - - this.log( "Removed Grinding of '%1%s'", Platform.getItemDisplayName( recipe.getInput() ) ); - - return removedRecipe != null; - } - - @Override - public IGrinderRecipe getRecipeForInput( final ItemStack input ) - { - this.log( "Looking up recipe for '%1$s'", Platform.getItemDisplayName( input ) ); - - if( input == null ) - { - return null; - } - - final IGrinderRecipe recipe = this.recipes.get( new CacheKey( input ) ); - - if( recipe == null ) - { - return null; - } - - this.log( "Recipe for '%1$s' found '%2$s'", input.getTranslationKey(), Platform.getItemDisplayName( recipe.getOutput() ) ); - return recipe; - } - - @Override - public void addDustRatio( String oredictName, int ratio ) - { - Preconditions.checkNotNull( oredictName ); - Preconditions.checkArgument( ratio > 0 ); - - this.log( "Added ratio for '%1$s' of %2$d", oredictName, ratio ); - - this.dustToOreRatio.put( oredictName, ratio ); - } - - @Override - public boolean removeDustRatio( String oredictName ) - { - Preconditions.checkNotNull( oredictName ); - - this.log( "Removed ratio for '%1$s'", oredictName ); - - return this.dustToOreRatio.remove( oredictName ) != null; - } - -// FIXME @Override -// FIXME public void oreRegistered( final String name, final ItemStack item ) -// FIXME { -// FIXME if( !AEConfig.instance().getGrinderBlackList().contains( name ) && ( name.startsWith( "ore" ) || name.startsWith( "crystal" ) || name -// FIXME .startsWith( "gem" ) || name.startsWith( "ingot" ) || name.startsWith( "dust" ) ) ) -// FIXME { -// FIXME for( final String ore : AEConfig.instance().getGrinderOres() ) -// FIXME { -// FIXME if( name.equals( "ore" + ore ) ) -// FIXME { -// FIXME this.addOre( ore, item ); -// FIXME } -// FIXME else if( name.equals( "crystal" + ore ) || name.equals( "ingot" + ore ) || name.equals( "gem" + ore ) ) -// FIXME { -// FIXME this.addIngot( ore, item ); -// FIXME } -// FIXME else if( name.equals( "dust" + ore ) ) -// FIXME { -// FIXME this.addDust( ore, item ); -// FIXME } -// FIXME } -// FIXME } -// FIXME } - - private boolean injectRecipe( final IGrinderRecipe grinderRecipe ) - { - final CacheKey cacheKey = new CacheKey( grinderRecipe.getInput() ); - - if( this.recipes.containsKey( cacheKey ) ) - { - this.log( "Tried to add duplicate recipe for '%1$s'", Platform.getItemDisplayName( grinderRecipe.getInput() ) ); - return false; - } - - this.recipes.put( cacheKey, grinderRecipe ); - - return true; - } - - private int getDustToOreRatio( final String name ) - { - return this.dustToOreRatio.getOrDefault( name, 2 ); - } - - private void addOre( final String name, final ItemStack item ) - { - if( item == null ) - { - return; - } - this.log( "Adding Ore: '%1$s'", Platform.getItemDisplayName( item ) ); - - this.ores.put( item, name ); - - if( this.dusts.containsKey( name ) ) - { - final ItemStack is = this.dusts.get( name ).copy(); - final int ratio = this.getDustToOreRatio( name ); - if( ratio > 1 ) - { - final ItemStack extra = is.copy(); - extra.setCount( ratio - 1 ); - - final IGrinderRecipeBuilder builder = this.builder(); - IGrinderRecipe grinderRecipe = builder.withInput( item ) - .withOutput( is ) - .withFirstOptional( extra, (float) ( AEConfig.instance().getOreDoublePercentage() / 100.0 ) ) - .withTurns( 8 ) - .build(); - - this.addRecipe( grinderRecipe ); - } - else - { - final IGrinderRecipeBuilder builder = this.builder(); - IGrinderRecipe grinderRecipe = builder.withInput( item ) - .withOutput( is ) - .withTurns( 8 ) - .build(); - - this.addRecipe( grinderRecipe ); - } - } - } - - private void addIngot( final String name, final ItemStack item ) - { - if( item == null ) - { - return; - } - this.log( "Adding Ingot: '%1$s'", Platform.getItemDisplayName( item ) ); - - this.ingots.put( item, name ); - - if( this.dusts.containsKey( name ) ) - { - final IGrinderRecipeBuilder builder = this.builder(); - IGrinderRecipe grinderRecipe = builder.withInput( item ) - .withOutput( this.dusts.get( name ) ) - .withTurns( 4 ) - .build(); - - this.addRecipe( grinderRecipe ); - } - } - - private void addDust( final String name, final ItemStack item ) - { - if( item == null ) - { - return; - } - - if( this.dusts.containsKey( name ) ) - { - this.log( "Rejecting Dust: '%1$s'", Platform.getItemDisplayName( item ) ); - return; - } - - this.log( "Adding Dust: '%1$s'", Platform.getItemDisplayName( item ) ); - - this.dusts.put( name, item ); - - for( final Entry d : this.ores.entrySet() ) - { - if( name.equals( d.getValue() ) ) - { - final ItemStack is = item.copy(); - is.setCount( 1 ); - final int ratio = this.getDustToOreRatio( name ); - if( ratio > 1 ) - { - final ItemStack extra = is.copy(); - extra.setCount( ratio - 1 ); - - final IGrinderRecipeBuilder builder = this.builder(); - final IGrinderRecipe grinderRecipe = builder.withInput( d.getKey() ) - .withOutput( is ) - .withFirstOptional( extra, (float) ( AEConfig.instance().getOreDoublePercentage() / 100.0 ) ) - .withTurns( 8 ) - .build(); - - this.addRecipe( grinderRecipe ); - } - else - { - final IGrinderRecipeBuilder builder = this.builder(); - final IGrinderRecipe grinderRecipe = builder.withInput( d.getKey() ) - .withOutput( is ) - .withTurns( 8 ) - .build(); - - this.addRecipe( grinderRecipe ); - } - } - } - - for( final Entry d : this.ingots.entrySet() ) - { - if( name.equals( d.getValue() ) ) - { - final IGrinderRecipeBuilder builder = this.builder(); - final IGrinderRecipe grinderRecipe = builder.withInput( d.getKey() ) - .withOutput( item ) - .withTurns( 4 ) - .build(); - - this.addRecipe( grinderRecipe ); - } - } - } - - private void log( final String o, Object... params ) - { - AELog.grinder( o, params ); - } - - private static class CacheKey - { - private final Item item; - - CacheKey( ItemStack input ) - { - Preconditions.checkNotNull( input ); - Preconditions.checkNotNull( input.getItem() ); - - this.item = input.getItem(); - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ( ( this.item == null ) ? 0 : this.item.hashCode() ); - return result; - } - - @Override - public boolean equals( Object obj ) - { - if( this == obj ) - { - return true; - } - if( obj == null || this.getClass() != obj.getClass() ) - { - return false; - } - - CacheKey other = (CacheKey) obj; - - if( this.item == null ) - { - if( other.item != null ) - { - return false; - } - } - else if( this.item != other.item ) - { - return false; - } - - return true; - } - - } - - /** - * Internal {@link IInscriberRecipeBuilder} implementation. - * Needs to be adapted to represent a correct {@link IInscriberRecipe} - */ - private static final class Builder implements IGrinderRecipeBuilder - { - - private ItemStack in; - private ItemStack out; - - private float optionalChance; - private ItemStack optionalOutput; - - private float optionalChance2; - private ItemStack optionalOutput2; - - private int turns = 8; - - @Override - public IGrinderRecipeBuilder withInput( ItemStack input ) - { - Preconditions.checkNotNull( input ); - Preconditions.checkArgument( !input.isEmpty(), "Input cannot be empty." ); - - this.in = this.copy( input ); - - return this; - } - - @Override - public IGrinderRecipeBuilder withOutput( ItemStack output ) - { - Preconditions.checkNotNull( output ); - Preconditions.checkArgument( !output.isEmpty(), "Output cannot be empty." ); - - this.out = this.copy( output ); - - return this; - } - - @Override - public IGrinderRecipeBuilder withFirstOptional( ItemStack optional, float chance ) - { - Preconditions.checkNotNull( optional ); - Preconditions.checkArgument( !optional.isEmpty(), "Optional cannot be empty." ); - Preconditions.checkArgument( chance >= 0 && chance <= 1.0 ); - - this.optionalOutput = this.copy( optional ); - this.optionalChance = chance; - - return this; - } - - @Override - public IGrinderRecipeBuilder withSecondOptional( ItemStack optional, float chance ) - { - Preconditions.checkNotNull( optional ); - Preconditions.checkArgument( !optional.isEmpty(), "Optional cannot be empty." ); - Preconditions.checkArgument( chance >= 0 && chance <= 1.0 ); - - this.optionalOutput2 = this.copy( optional ); - this.optionalChance2 = chance; - - return this; - } - - @Override - public IGrinderRecipeBuilder withTurns( int turns ) - { - Preconditions.checkArgument( turns > 0 ); - - this.turns = turns; - - return this; - } - - @Nonnull - @Override - public IGrinderRecipe build() - { - Preconditions.checkState( this.in != null, "Input itemstack must be defined." ); - Preconditions.checkState( this.out != null, "Output itemstack must be defined." ); - - return new AppEngGrinderRecipe( this.in, this.out, this.optionalOutput, this.optionalOutput2, this.optionalChance, this.optionalChance2, this.turns ); - } - - private ItemStack copy( final ItemStack is ) - { - if( is != null ) - { - return is.copy(); - } - return null; - } - } -} diff --git a/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java b/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java index 70b40c091..945b569bc 100644 --- a/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java +++ b/src/main/java/appeng/integration/modules/jei/GrinderRecipeCategory.java @@ -53,7 +53,7 @@ class GrinderRecipeCategory implements IRecipeCategory public GrinderRecipeCategory( IGuiHelper guiHelper ) { - this.localizedName = I18n.format( "tile.appliedenergistics2.grindstone.name" ); + this.localizedName = I18n.format( "block.appliedenergistics2.grindstone" ); ResourceLocation location = new ResourceLocation( AppEng.MOD_ID, "textures/guis/grinder.png" ); this.background = guiHelper.createDrawable( location, 11, 16, 154, 70 ); diff --git a/src/main/java/appeng/integration/modules/jei/InscriberRecipeCategory.java b/src/main/java/appeng/integration/modules/jei/InscriberRecipeCategory.java index 0da266a18..c0abaaf91 100644 --- a/src/main/java/appeng/integration/modules/jei/InscriberRecipeCategory.java +++ b/src/main/java/appeng/integration/modules/jei/InscriberRecipeCategory.java @@ -32,8 +32,12 @@ import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.ingredients.IIngredients; import mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.client.resources.I18n; +import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; +import java.util.ArrayList; +import java.util.List; + class InscriberRecipeCategory implements IRecipeCategory { @@ -57,7 +61,7 @@ class InscriberRecipeCategory implements IRecipeCategory { ResourceLocation location = new ResourceLocation( AppEng.MOD_ID, "textures/guis/inscriber.png" ); this.background = guiHelper.createDrawable( location, 44, 15, 97, 64 ); - this.localizedName = I18n.format( "tile.appliedenergistics2.inscriber.name" ); + this.localizedName = I18n.format( "block.appliedenergistics2.inscriber" ); IDrawableStatic progressDrawable = guiHelper.drawableBuilder( location, 135, 177, 6, 18 ) .addPadding(24, 0, 91, 0) @@ -110,13 +114,7 @@ class InscriberRecipeCategory implements IRecipeCategory @Override public void setIngredients(InscriberRecipe recipe, IIngredients ingredients) { - -// FIXME List> inputSlots = new ArrayList<>( 3 ); -// FIXME inputSlots.add( Collections.singletonList( recipe.getTopOptional() ) ); -// FIXME inputSlots.add( recipe.getInputs() ); -// FIXME inputSlots.add( Collections.singletonList( recipe.getBottomOptional() ) ); -// FIXME ingredients.setInputLists(VanillaTypes.ITEM, inputSlots ); - + ingredients.setInputIngredients(recipe.getIngredients()); ingredients.setOutput( VanillaTypes.ITEM, recipe.getOutput() ); } diff --git a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java index e2263a66b..b6b426c85 100644 --- a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java +++ b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java @@ -31,6 +31,7 @@ import appeng.core.AEConfig; import appeng.core.AppEng; import appeng.core.localization.GuiText; import appeng.recipes.handlers.GrinderRecipe; +import appeng.recipes.handlers.InscriberRecipe; import com.google.common.collect.ImmutableList; import mezz.jei.api.IModPlugin; import mezz.jei.api.JeiPlugin; @@ -95,90 +96,72 @@ public class JEIPlugin implements IModPlugin // FIXME registration.addRecipeRegistryPlugin( new FacadeRegistryPlugin( (ItemFacade) itemFacade.get(), cableAnchor.get() ) ); // FIXME } - ItemStack condenser = definitions.blocks().condenser().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - if(!condenser.isEmpty()) { - ItemStack matterBall = definitions.materials().matterBall().maybeStack(1).orElse(ItemStack.EMPTY); - if (!matterBall.isEmpty()) { - registration.addRecipes(ImmutableList.of(CondenserOutput.MATTER_BALLS), CondenserCategory.UID); - } - ItemStack singularity = definitions.materials().singularity().maybeStack(1).orElse(ItemStack.EMPTY); - if (!singularity.isEmpty()) { - registration.addRecipes(ImmutableList.of(CondenserOutput.SINGULARITY), CondenserCategory.UID); - } - } - RecipeManager recipeManager = Minecraft.getInstance().world.getRecipeManager(); registration.addRecipes(recipeManager.getRecipes(GrinderRecipe.TYPE).values(), GrinderRecipeCategory.UID); - // FIXME registration.addRecipes( recipeManager.getRecipes(InscriberRecipe.TYPE), InscriberRecipeCategory.UID ); + registration.addRecipes(recipeManager.getRecipes(InscriberRecipe.TYPE).values(), InscriberRecipeCategory.UID ); registration.addRecipes(ImmutableList.of(CondenserOutput.MATTER_BALLS, CondenserOutput.SINGULARITY), CondenserCategory.UID); + + registerDescriptions(definitions, registration); } @Override public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { IDefinitions definitions = AEApi.instance().definitions(); - ItemStack grindstone = definitions.blocks().grindstone().maybeStack( 1 ).orElse( ItemStack.EMPTY ); - if( !grindstone.isEmpty() ) - { - registration.addRecipeCatalyst( grindstone, GrinderRecipeCategory.UID ); - } + ItemStack grindstone = definitions.blocks().grindstone().stack(1); + registration.addRecipeCatalyst( grindstone, GrinderRecipeCategory.UID ); - definitions.blocks().condenser().maybeStack( 1 ).ifPresent(condenser -> { - registration.addRecipeCatalyst(condenser, CondenserCategory.UID); - }); - - // Register the inscriber as the crafting item for the inscription category - definitions.blocks().inscriber().maybeStack( 1 ).ifPresent( inscriber -> - { - registration.addRecipeCatalyst( inscriber, InscriberRecipeCategory.UID ); - } ); + ItemStack condenser = definitions.blocks().condenser().stack(1); + registration.addRecipeCatalyst(condenser, CondenserCategory.UID); + ItemStack inscriber = definitions.blocks().inscriber().stack(1); + registration.addRecipeCatalyst( inscriber, InscriberRecipeCategory.UID ); } private void registerDescriptions(IDefinitions definitions, IRecipeRegistration registry ) { IMaterials materials = definitions.materials(); - final String message; + final String[] message; if( AEConfig.instance().isFeatureEnabled( AEFeature.CERTUS_QUARTZ_WORLD_GEN ) ) { - message = GuiText.ChargedQuartz.getLocal() + "\n\n" + GuiText.ChargedQuartzFind.getLocal(); + message = new String[]{GuiText.ChargedQuartz.getTranslationKey(), "", GuiText.ChargedQuartzFind.getTranslationKey()}; } else { - message = GuiText.ChargedQuartzFind.getLocal(); + message = new String[]{GuiText.ChargedQuartzFind.getTranslationKey()}; } this.addDescription( registry, materials.certusQuartzCrystalCharged(), message ); if( AEConfig.instance().isFeatureEnabled( AEFeature.METEORITE_WORLD_GEN ) ) { - this.addDescription( registry, materials.logicProcessorPress(), GuiText.inWorldCraftingPresses.getLocal() ); - this.addDescription( registry, materials.calcProcessorPress(), GuiText.inWorldCraftingPresses.getLocal() ); - this.addDescription( registry, materials.engProcessorPress(), GuiText.inWorldCraftingPresses.getLocal() ); + this.addDescription( registry, materials.logicProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() ); + this.addDescription( registry, materials.calcProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() ); + this.addDescription( registry, materials.engProcessorPress(), GuiText.inWorldCraftingPresses.getTranslationKey() ); } if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_FLUIX ) ) { - this.addDescription( registry, materials.fluixCrystal(), GuiText.inWorldFluix.getLocal() ); + this.addDescription( registry, materials.fluixCrystal(), GuiText.inWorldFluix.getTranslationKey() ); } if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_SINGULARITY ) ) { - this.addDescription( registry, materials.qESingularity(), GuiText.inWorldSingularity.getLocal() ); + this.addDescription( registry, materials.qESingularity(), GuiText.inWorldSingularity.getTranslationKey() ); } if( AEConfig.instance().isFeatureEnabled( AEFeature.IN_WORLD_PURIFICATION ) ) { - this.addDescription( registry, materials.purifiedCertusQuartzCrystal(), GuiText.inWorldPurificationCertus.getLocal() ); - this.addDescription( registry, materials.purifiedNetherQuartzCrystal(), GuiText.inWorldPurificationNether.getLocal() ); - this.addDescription( registry, materials.purifiedFluixCrystal(), GuiText.inWorldPurificationFluix.getLocal() ); + this.addDescription( registry, materials.purifiedCertusQuartzCrystal(), GuiText.inWorldPurificationCertus.getTranslationKey() ); + this.addDescription( registry, materials.purifiedNetherQuartzCrystal(), GuiText.inWorldPurificationNether.getTranslationKey() ); + this.addDescription( registry, materials.purifiedFluixCrystal(), GuiText.inWorldPurificationFluix.getTranslationKey() ); } } - private void addDescription(IRecipeRegistration registry, IItemDefinition itemDefinition, String message ) + private void addDescription(IRecipeRegistration registry, IItemDefinition itemDefinition, String... message ) { - itemDefinition.maybeStack( 1 ).ifPresent( itemStack -> registry.addIngredientInfo( itemStack, VanillaTypes.ITEM, message ) ); + registry.addIngredientInfo( itemDefinition.stack(1), VanillaTypes.ITEM, message ); } @Override diff --git a/src/main/java/appeng/recipes/AEItemResolver.java b/src/main/java/appeng/recipes/AEItemResolver.java deleted file mode 100644 index 53435a1fb..000000000 --- a/src/main/java/appeng/recipes/AEItemResolver.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. - * - * Applied Energistics 2 is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Applied Energistics 2 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Applied Energistics 2. If not, see . - */ - -package appeng.recipes; - - -import appeng.api.AEApi; -import appeng.api.definitions.IDefinitions; -import appeng.api.definitions.IItems; -import appeng.api.definitions.IParts; -import appeng.api.recipes.ISubItemResolver; -import appeng.api.recipes.ResolverResult; -import appeng.api.recipes.ResolverResultSet; -import appeng.api.util.AEColor; -import appeng.api.util.AEColoredItemDefinition; -import appeng.core.AppEng; -import appeng.items.materials.ItemMaterial; -import appeng.items.materials.MaterialType; -import appeng.items.parts.ItemPart; -import appeng.items.parts.PartType; -import net.minecraft.item.ItemStack; - - -public class AEItemResolver implements ISubItemResolver -{ - - @Override - public Object resolveItemByName( final String nameSpace, final String itemName ) - { - - if( nameSpace.equals( AppEng.MOD_ID ) ) - { - final IDefinitions definitions = AEApi.instance().definitions(); - final IItems items = definitions.items(); - final IParts parts = definitions.parts(); - - if( itemName.startsWith( "paint_ball." ) ) - { - return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), false ); - } - - if( itemName.startsWith( "lumen_paint_ball." ) ) - { - return this.paintBall( items.coloredPaintBall(), itemName.substring( itemName.indexOf( '.' ) + 1 ), true ); - } - - if( itemName.equals( "cable_glass" ) ) - { - return new ResolverResultSet( "cable_glass", parts.cableGlass().allStacks( 1 ) ); - } - - if( itemName.startsWith( "cable_glass." ) ) - { - return this.cableItem( parts.cableGlass(), itemName.substring( itemName.indexOf( '.' ) + 1 ) ); - } - - if( itemName.equals( "cable_covered" ) ) - { - return new ResolverResultSet( "cable_covered", parts.cableCovered().allStacks( 1 ) ); - } - - if( itemName.startsWith( "cable_covered." ) ) - { - return this.cableItem( parts.cableCovered(), itemName.substring( itemName.indexOf( '.' ) + 1 ) ); - } - - if( itemName.equals( "cable_smart" ) ) - { - return new ResolverResultSet( "cable_smart", parts.cableSmart().allStacks( 1 ) ); - } - - if( itemName.startsWith( "cable_smart." ) ) - { - return this.cableItem( parts.cableSmart(), itemName.substring( itemName.indexOf( '.' ) + 1 ) ); - } - - if( itemName.equals( "cable_dense_covered" ) ) - { - return new ResolverResultSet( "cable_dense_covered", parts.cableDenseCovered().allStacks( 1 ) ); - } - - if( itemName.startsWith( "cable_dense_covered." ) ) - { - return this.cableItem( parts.cableDenseCovered(), itemName.substring( itemName.indexOf( '.' ) + 1 ) ); - } - - if( itemName.equals( "cable_dense_smart" ) ) - { - return new ResolverResultSet( "cable_dense_smart", parts.cableDenseSmart().allStacks( 1 ) ); - } - - if( itemName.startsWith( "cable_dense_smart." ) ) - { - return this.cableItem( parts.cableDenseSmart(), itemName.substring( itemName.indexOf( '.' ) + 1 ) ); - } - - if( itemName.startsWith( "crystal_seed." ) ) - { - if( itemName.equalsIgnoreCase( "crystal_seed.certus" ) ) - { - return new ResolverResultSet( "certus_crystal_seed", items.certusCrystalSeed().stack( 1 ) ); - } - if( itemName.equalsIgnoreCase( "crystal_seed.nether" ) ) - { - return new ResolverResultSet( "nether_crystal_seed", items.netherQuartzSeed().stack( 1 ) ); - } - if( itemName.equalsIgnoreCase( "crystal_seed.fluix" ) ) - { - return new ResolverResultSet( "fluix_crystal_seed", items.fluixCrystalSeed().stack( 1 ) ); - } - - return null; - } - - if( itemName.startsWith( "material." ) ) - { - // FIXME entire class is redundant i think -// FIXME final String materialName = itemName.substring( itemName.indexOf( '.' ) + 1 ); -// FIXME final MaterialType mt = MaterialType.valueOf( materialName.toUpperCase() ); -// FIXME // itemName = itemName.substring( 0, itemName.indexOf( "." ) ); -// FIXME if( mt.getItemInstance() == ItemMaterial.instance && mt.getDamageValue() >= 0 && mt.isRegistered() ) -// FIXME { -// FIXME return new ResolverResult( "material", mt.getDamageValue() ); -// FIXME } - } - -// FIXME if( itemName.startsWith( "part." ) ) -// FIXME { -// FIXME final String partName = itemName.substring( itemName.indexOf( '.' ) + 1 ); -// FIXME final PartType pt = PartType.valueOf( partName.toUpperCase() ); -// FIXME // itemName = itemName.substring( 0, itemName.indexOf( "." ) ); -// FIXME final int dVal = ItemPart.instance.getDamageByType( pt ); -// FIXME if( dVal >= 0 ) -// FIXME { -// FIXME return new ResolverResult( "part", dVal ); -// FIXME } -// FIXME } - } - - return null; - } - - private Object paintBall( final AEColoredItemDefinition partType, final String substring, final boolean lumen ) - { - AEColor col; - - try - { - col = AEColor.valueOf( substring.toUpperCase() ); - } - catch( final Throwable t ) - { - col = AEColor.TRANSPARENT; - } - - if( col == AEColor.TRANSPARENT ) - { - return null; - } - - final ItemStack is = partType.stack( col, 1 ); - return new ResolverResult( "paint_ball", ( lumen ? 20 : 0 ) + is.getDamage() ); - } - - private Object cableItem( final AEColoredItemDefinition partType, final String substring ) - { - AEColor col; - - try - { - col = AEColor.valueOf( substring.toUpperCase() ); - } - catch( final Throwable t ) - { - col = AEColor.TRANSPARENT; - } - - final ItemStack is = partType.stack( col, 1 ); - return new ResolverResult( "part", is.getDamage() ); - } -} diff --git a/src/main/java/appeng/recipes/handlers/GrinderRecipe.java b/src/main/java/appeng/recipes/handlers/GrinderRecipe.java index 7bed904ca..5d2089230 100644 --- a/src/main/java/appeng/recipes/handlers/GrinderRecipe.java +++ b/src/main/java/appeng/recipes/handlers/GrinderRecipe.java @@ -20,18 +20,21 @@ public class GrinderRecipe implements IRecipe { private final ResourceLocation id; private final String group; private final Ingredient ingredient; + private final int ingredientCount; private final ItemStack result; private final List optionalResults; private final int turns; - public GrinderRecipe(ResourceLocation id, String group, Ingredient ingredient, ItemStack result, int turns, List optionalResults) { + public GrinderRecipe(ResourceLocation id, String group, Ingredient ingredient, int ingredientCount, ItemStack result, int turns, List optionalResults) { this.id = id; this.group = group; this.ingredient = ingredient; + this.ingredientCount = ingredientCount; this.result = result; this.turns = turns; this.optionalResults = ImmutableList.copyOf(optionalResults); } + @Override public boolean matches(IInventory inv, World worldIn) { return this.ingredient.test(inv.getStackInSlot(0)); @@ -72,6 +75,14 @@ public class GrinderRecipe implements IRecipe { return ingredient; } + public int getTurns() { + return turns; + } + + public int getIngredientCount() { + return ingredientCount; + } + @Override public NonNullList getIngredients() { NonNullList nonnulllist = NonNullList.create(); diff --git a/src/main/java/appeng/recipes/handlers/GrinderRecipeSerializer.java b/src/main/java/appeng/recipes/handlers/GrinderRecipeSerializer.java index aa72a7f83..ba6ab2129 100644 --- a/src/main/java/appeng/recipes/handlers/GrinderRecipeSerializer.java +++ b/src/main/java/appeng/recipes/handlers/GrinderRecipeSerializer.java @@ -1,5 +1,6 @@ package appeng.recipes.handlers; +import appeng.core.AEConfig; import appeng.core.AppEng; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -32,7 +33,12 @@ public class GrinderRecipeSerializer extends ForgeRegistryEntry recipe : world.getRecipeManager().getRecipes(GrinderRecipe.TYPE).values()) { + GrinderRecipe grinderRecipe = (GrinderRecipe) recipe; + if (grinderRecipe.getIngredient().test(input) && input.getCount() >= grinderRecipe.getIngredientCount()) { + return grinderRecipe; + } + } + return null; + } + + /** + * Checks if the given item stack is an ingredient in any grinder recipe, disregarding its current size. + */ + public static boolean isValidIngredient(World world, ItemStack stack) { + for (IRecipe recipe : world.getRecipeManager().getRecipes(GrinderRecipe.TYPE).values()) { + GrinderRecipe grinderRecipe = (GrinderRecipe) recipe; + if (grinderRecipe.getIngredient().test(stack)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/appeng/recipes/handlers/InscriberHandler.java b/src/main/java/appeng/recipes/handlers/InscriberHandler.java deleted file mode 100644 index bac0dea1b..000000000 --- a/src/main/java/appeng/recipes/handlers/InscriberHandler.java +++ /dev/null @@ -1,56 +0,0 @@ - -package appeng.recipes.handlers; - - -import com.google.gson.JsonObject; - - -public class InscriberHandler -{ - -// @Override -// public void register( JsonObject json, JsonContext ctx ) -// { -// ItemStack result = PartRecipeFactory.getResult( json, ctx ); -// String mode = JSONUtils.getString( json, "mode" ); -// -// JsonObject ingredients = JSONUtils.getJsonObject( json, "ingredients" ); -// -// List middle = Arrays.asList( CraftingHelper.getIngredient( ingredients.get( "middle" ), ctx ).getMatchingStacks() ); -// ItemStack[] top = new ItemStack[] { null }; -// if( ingredients.has( "top" ) ) -// { -// top = CraftingHelper.getIngredient( JSONUtils.getJsonObject( ingredients, "top" ), ctx ).getMatchingStacks(); -// } -// -// ItemStack[] bottom = new ItemStack[] { null }; -// if( ingredients.has( "bottom" ) ) -// { -// bottom = CraftingHelper.getIngredient( JSONUtils.getJsonObject( ingredients, "bottom" ), ctx ).getMatchingStacks(); -// } -// -// final IInscriberRegistry reg = AEApi.instance().registries().inscriber(); -// for( int i = 0; i < top.length; ++i ) -// { -// for( int j = 0; j < bottom.length; ++j ) -// { -// final IInscriberRecipeBuilder builder = reg.builder(); -// builder.withOutput( result ); -// builder.withProcessType( "press".equals( mode ) ? InscriberProcessType.PRESS : InscriberProcessType.INSCRIBE ); -// builder.withInputs( middle ); -// -// if( top[i] != null ) -// { -// builder.withTopOptional( top[i] ); -// } -// if( bottom[j] != null ) -// { -// builder.withBottomOptional( bottom[j] ); -// } -// -// reg.addRecipe( builder.build() ); -// } -// } -// } -// -} diff --git a/src/main/java/appeng/recipes/handlers/InscriberRecipe.java b/src/main/java/appeng/recipes/handlers/InscriberRecipe.java index d9184a11f..d45036c2b 100644 --- a/src/main/java/appeng/recipes/handlers/InscriberRecipe.java +++ b/src/main/java/appeng/recipes/handlers/InscriberRecipe.java @@ -1,17 +1,17 @@ package appeng.recipes.handlers; import appeng.api.features.InscriberProcessType; -import com.google.common.collect.ImmutableList; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraft.item.crafting.IRecipeType; import net.minecraft.item.crafting.Ingredient; +import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -import java.util.List; +import javax.annotation.Nullable; public class InscriberRecipe implements IRecipe { @@ -20,20 +20,20 @@ public class InscriberRecipe implements IRecipe { private final ResourceLocation id; private final String group; - private List inputs; + private Ingredient middleInput; + private Ingredient topOptional; + private Ingredient bottomOptional; private ItemStack output; - private ItemStack topOptional; - private ItemStack bottomOptional; - private InscriberProcessType type; + private InscriberProcessType processType; - public InscriberRecipe(ResourceLocation id, String group, List inputs, ItemStack output, ItemStack topOptional, ItemStack bottomOptional, InscriberProcessType type) { + public InscriberRecipe(ResourceLocation id, String group, Ingredient middleInput, ItemStack output, Ingredient topOptional, Ingredient bottomOptional, InscriberProcessType processType) { this.id = id; this.group = group; - this.inputs = inputs; + this.middleInput = middleInput; this.output = output; this.topOptional = topOptional; this.bottomOptional = bottomOptional; - this.type = type; + this.processType = processType; } @Override @@ -43,27 +43,27 @@ public class InscriberRecipe implements IRecipe { @Override public ItemStack getCraftingResult(IInventory inv) { - return null; + return this.output.copy(); } @Override public boolean canFit(int width, int height) { - return false; + return true; } @Override public ItemStack getRecipeOutput() { - return null; + return output; } @Override public ResourceLocation getId() { - return null; + return id; } @Override public IRecipeSerializer getSerializer() { - return null; + return GrinderRecipeSerializer.INSTANCE; } @Override @@ -71,20 +71,33 @@ public class InscriberRecipe implements IRecipe { return TYPE; } - public List getInputs() { - return inputs; + @Override + public NonNullList getIngredients() { + NonNullList nonnulllist = NonNullList.create(); + nonnulllist.add(this.topOptional); + nonnulllist.add(this.middleInput); + nonnulllist.add(this.bottomOptional); + return nonnulllist; + } + + public Ingredient getMiddleInput() { + return middleInput; } public ItemStack getOutput() { return output; } - public ItemStack getTopOptional() { + public Ingredient getTopOptional() { return topOptional; } - public ItemStack getBottomOptional() { + public Ingredient getBottomOptional() { return bottomOptional; } + public InscriberProcessType getProcessType() { + return processType; + } + } diff --git a/src/main/java/appeng/recipes/handlers/InscriberRecipeSerializer.java b/src/main/java/appeng/recipes/handlers/InscriberRecipeSerializer.java new file mode 100644 index 000000000..78066b594 --- /dev/null +++ b/src/main/java/appeng/recipes/handlers/InscriberRecipeSerializer.java @@ -0,0 +1,79 @@ +package appeng.recipes.handlers; + +import appeng.api.features.InscriberProcessType; +import appeng.core.AppEng; +import com.google.gson.JsonObject; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipeSerializer; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.item.crafting.ShapedRecipe; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.JSONUtils; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistryEntry; + +import javax.annotation.Nullable; + +public class InscriberRecipeSerializer extends ForgeRegistryEntry> implements IRecipeSerializer { + + public static final InscriberRecipeSerializer INSTANCE = new InscriberRecipeSerializer(); + + static { + INSTANCE.setRegistryName(AppEng.MOD_ID, "inscriber"); + } + + private InscriberRecipeSerializer() { + } + + private static InscriberProcessType getMode(JsonObject json) { + String mode = JSONUtils.getString( json, "mode", "inscribe" ); + switch (mode) { + case "inscribe": + return InscriberProcessType.INSCRIBE; + case "press": + return InscriberProcessType.PRESS; + default: + throw new IllegalStateException("Unknown mode for inscriber recipe: " + mode); + } + + } + + @Override + public InscriberRecipe read(ResourceLocation recipeId, JsonObject json) { + + InscriberProcessType mode = getMode(json); + + String group = JSONUtils.getString(json, "group", ""); + ItemStack result = ShapedRecipe.deserializeItem(JSONUtils.getJsonObject(json, "result")); + + // Deserialize the three parts of the input + JsonObject ingredients = JSONUtils.getJsonObject( json, "ingredients" ); + Ingredient middle = Ingredient.deserialize( ingredients.get( "middle" ) ); + Ingredient top = Ingredient.EMPTY; + if( ingredients.has( "top" ) ) + { + top = Ingredient.deserialize( ingredients.get( "top" ) ); + } + Ingredient bottom = Ingredient.EMPTY; + if( ingredients.has( "bottom" ) ) + { + bottom = Ingredient.deserialize( ingredients.get( "bottom" ) ); + } + + return new InscriberRecipe(recipeId, group, middle, result, top, bottom, mode); + } + + @Nullable + @Override + public InscriberRecipe read(ResourceLocation recipeId, PacketBuffer buffer) { + // FIXME NOT YET IMPLEMENTED + throw new IllegalStateException(); + } + + @Override + public void write(PacketBuffer buffer, InscriberRecipe recipe) { + // FIXME NOT YET IMPLEMENTED + throw new IllegalStateException(); + } + +} diff --git a/src/main/java/appeng/tile/grindstone/TileGrinder.java b/src/main/java/appeng/tile/grindstone/TileGrinder.java index 11de2bf18..e361963cd 100644 --- a/src/main/java/appeng/tile/grindstone/TileGrinder.java +++ b/src/main/java/appeng/tile/grindstone/TileGrinder.java @@ -19,19 +19,10 @@ package appeng.tile.grindstone; -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.Direction; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.items.wrapper.RangedWrapper; - -import appeng.api.AEApi; -import appeng.api.features.IGrinderRecipe; import appeng.api.implementations.tiles.ICrankable; +import appeng.recipes.handlers.GrinderOptionalResult; +import appeng.recipes.handlers.GrinderRecipe; +import appeng.recipes.handlers.GrinderRecipes; import appeng.tile.AEBaseInvTile; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.InventoryAdaptor; @@ -40,10 +31,21 @@ import appeng.util.inv.AdaptorItemHandler; import appeng.util.inv.InvOperation; import appeng.util.inv.WrapperFilteredItemHandler; import appeng.util.inv.filter.IAEItemFilter; +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.RangedWrapper; + +import java.util.ArrayList; +import java.util.List; public class TileGrinder extends AEBaseInvTile implements ICrankable { + private static final int SLOT_PROCESSING = 6; + private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 7 ); private final IItemHandler invExt = new WrapperFilteredItemHandler( this.inv, new GrinderFilter() ); private int points; @@ -96,24 +98,21 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable continue; } - final IGrinderRecipe r = AEApi.instance().registries().grinder().getRecipeForInput( item ); + GrinderRecipe r = GrinderRecipes.findForInput(world, item); if( r != null ) { - if( item.getCount() >= r.getInput().getCount() ) + final ItemStack ais = item.copy(); + ais.setCount( r.getIngredientCount() ); + item.shrink( r.getIngredientCount() ); + + if( item.getCount() <= 0 ) { - final ItemStack ais = item.copy(); - ais.setCount( r.getInput().getCount() ); - item.shrink( r.getInput().getCount() ); - - if( item.getCount() <= 0 ) - { - item = ItemStack.EMPTY; - } - - this.inv.setStackInSlot( x, item ); - this.inv.setStackInSlot( 6, ais ); - return true; + item = ItemStack.EMPTY; } + + this.inv.setStackInSlot( x, item ); + this.inv.setStackInSlot( 6, ais ); + return true; } } return false; @@ -131,11 +130,11 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable this.points++; - final ItemStack processing = this.inv.getStackInSlot( 6 ); - final IGrinderRecipe r = AEApi.instance().registries().grinder().getRecipeForInput( processing ); + final ItemStack processing = this.inv.getStackInSlot(SLOT_PROCESSING); + GrinderRecipe r = GrinderRecipes.findForInput(world, processing); if( r != null ) { - if( r.getRequiredTurns() > this.points ) + if( r.getTurns() > this.points ) { return; } @@ -143,27 +142,16 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable this.points = 0; final InventoryAdaptor sia = new AdaptorItemHandler( new RangedWrapper( this.inv, 3, 6 ) ); - this.addItem( sia, r.getOutput() ); + this.addItem( sia, r.getRecipeOutput()); - r.getOptionalOutput().ifPresent( itemStack -> - { + for (GrinderOptionalResult optionalResult : r.getOptionalResults()) { final float chance = ( Platform.getRandomInt() % 2000 ) / 2000.0f; - if( chance <= r.getOptionalChance() ) + if( chance <= optionalResult.getChance() ) { - this.addItem( sia, itemStack ); + this.addItem( sia, optionalResult.getResult() ); } - } ); - - r.getSecondOptionalOutput().ifPresent( itemStack -> - { - final float chance = ( Platform.getRandomInt() % 2000 ) / 2000.0f; - - if( chance <= r.getSecondOptionalChance() ) - { - this.addItem( sia, itemStack ); - } - } ); + } this.inv.setStackInSlot( 6, ItemStack.EMPTY ); } @@ -203,7 +191,7 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable @Override public boolean allowInsert( IItemHandler inv, int slotIndex, ItemStack stack ) { - if( AEApi.instance().registries().grinder().getRecipeForInput( stack ) == null ) + if( !GrinderRecipes.isValidIngredient(world, stack) ) { return false; } diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/certus_quartz_dust.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/certus_quartz_dust.json new file mode 100644 index 000000000..571e8b518 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/certus_quartz_dust.json @@ -0,0 +1,12 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:gems/certus_quartz" + }, + "result": { + "primary": { + "item": "appliedenergistics2:certus_quartz_dust" + } + }, + "turns": 4 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/certus_quartz_dust_ore.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/certus_quartz_dust_ore.json new file mode 100644 index 000000000..5dd55962b --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/certus_quartz_dust_ore.json @@ -0,0 +1,17 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:ores/certus_quartz" + }, + "result": { + "primary": { + "item": "appliedenergistics2:certus_quartz_dust" + }, + "optional": [ + { + "item": "appliedenergistics2:certus_quartz_dust" + } + ] + }, + "turns": 8 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/ender_dust.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/ender_dust.json new file mode 100644 index 000000000..459980352 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/ender_dust.json @@ -0,0 +1,12 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:ender_pearls" + }, + "result": { + "primary": { + "item": "appliedenergistics2:ender_dust" + } + }, + "turns": 4 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/flour.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/flour.json new file mode 100644 index 000000000..d31d7a788 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/flour.json @@ -0,0 +1,12 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:crops/wheat" + }, + "result": { + "primary": { + "item": "appliedenergistics2:flour" + } + }, + "turns": 4 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/fluix_dust.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/fluix_dust.json index 6b9ba2520..507db0e2a 100644 --- a/src/main/resources/data/appliedenergistics2/recipes/grinder/fluix_dust.json +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/fluix_dust.json @@ -8,5 +8,5 @@ "item": "appliedenergistics2:fluix_dust" } }, - "turns": 8 + "turns": 4 } \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/gold_dust_ingot.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/gold_dust_ingot.json new file mode 100644 index 000000000..063b82d84 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/gold_dust_ingot.json @@ -0,0 +1,12 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:ingots/gold" + }, + "result": { + "primary": { + "item": "appliedenergistics2:gold_dust" + } + }, + "turns": 4 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/gold_dust_ore.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/gold_dust_ore.json new file mode 100644 index 000000000..ed8d310fc --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/gold_dust_ore.json @@ -0,0 +1,17 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:ores/gold" + }, + "result": { + "primary": { + "item": "appliedenergistics2:gold_dust" + }, + "optional": [ + { + "item": "appliedenergistics2:gold_dust" + } + ] + }, + "turns": 8 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/iron_dust_ingot.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/iron_dust_ingot.json new file mode 100644 index 000000000..bcaea7f11 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/iron_dust_ingot.json @@ -0,0 +1,12 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:ingots/iron" + }, + "result": { + "primary": { + "item": "appliedenergistics2:iron_dust" + } + }, + "turns": 4 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/iron_dust_ore.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/iron_dust_ore.json new file mode 100644 index 000000000..b1f911d71 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/iron_dust_ore.json @@ -0,0 +1,17 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:ores/iron" + }, + "result": { + "primary": { + "item": "appliedenergistics2:iron_dust" + }, + "optional": [ + { + "item": "appliedenergistics2:iron_dust" + } + ] + }, + "turns": 4 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/nether_quartz_dust.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/nether_quartz_dust.json new file mode 100644 index 000000000..ad2e9196c --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/nether_quartz_dust.json @@ -0,0 +1,12 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:gems/quartz" + }, + "result": { + "primary": { + "item": "appliedenergistics2:nether_quartz_dust" + } + }, + "turns": 4 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/grinder/nether_quartz_dust_ore.json b/src/main/resources/data/appliedenergistics2/recipes/grinder/nether_quartz_dust_ore.json new file mode 100644 index 000000000..583ca4054 --- /dev/null +++ b/src/main/resources/data/appliedenergistics2/recipes/grinder/nether_quartz_dust_ore.json @@ -0,0 +1,17 @@ +{ + "type": "appliedenergistics2:grinder", + "input": { + "tag": "forge:ores/quartz" + }, + "result": { + "primary": { + "item": "appliedenergistics2:nether_quartz_dust" + }, + "optional": [ + { + "item": "appliedenergistics2:nether_quartz_dust" + } + ] + }, + "turns": 8 +} \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/misc/seeds_nether.json b/src/main/resources/data/appliedenergistics2/recipes/misc/seeds_nether.json index de232c31d..899af58c4 100644 --- a/src/main/resources/data/appliedenergistics2/recipes/misc/seeds_nether.json +++ b/src/main/resources/data/appliedenergistics2/recipes/misc/seeds_nether.json @@ -1,6 +1,6 @@ { "result": { - "item": "appliedenergistics2:nether_crystal_seed", + "item": "appliedenergistics2:nether_quartz_seed", "count": 2 }, "type": "minecraft:crafting_shapeless", diff --git a/src/main/resources/data/appliedenergistics2/recipes/network/wireless_booster.json b/src/main/resources/data/appliedenergistics2/recipes/network/wireless_booster.json index 7b218d6da..a9fcf5e24 100644 --- a/src/main/resources/data/appliedenergistics2/recipes/network/wireless_booster.json +++ b/src/main/resources/data/appliedenergistics2/recipes/network/wireless_booster.json @@ -19,7 +19,7 @@ "tag": "appliedenergistics2:dusts/fluix" }, "c": { - "tag": "appliedenergistics2:dusts/ender" + "tag": "appliedenergistics2:dusts/ender_pearl" } } } \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/smelting/bread.json b/src/main/resources/data/appliedenergistics2/recipes/smelting/bread.json index 30f35f234..b993fbd6a 100644 --- a/src/main/resources/data/appliedenergistics2/recipes/smelting/bread.json +++ b/src/main/resources/data/appliedenergistics2/recipes/smelting/bread.json @@ -1,10 +1,10 @@ { - "type": "appliedenergistics2:smelt", + "type": "minecraft:smelting", "result": { "item": "minecraft:bread" }, - "input": { + "ingredient": { "item": "appliedenergistics2:flour" }, - "xp": 0.0 + "experience": 0.0 } \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/smelting/gold_ingot.json b/src/main/resources/data/appliedenergistics2/recipes/smelting/gold_ingot.json index f9c76325b..c508e385b 100644 --- a/src/main/resources/data/appliedenergistics2/recipes/smelting/gold_ingot.json +++ b/src/main/resources/data/appliedenergistics2/recipes/smelting/gold_ingot.json @@ -1,10 +1,10 @@ { - "type": "appliedenergistics2:smelt", + "type": "minecraft:smelting", "result": { "item": "minecraft:gold_ingot" }, - "input": { + "ingredient": { "tag": "forge:dusts/gold" }, - "xp": 0.0 + "experience": 0.0 } \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/smelting/iron_ingot.json b/src/main/resources/data/appliedenergistics2/recipes/smelting/iron_ingot.json index c95ed628c..164bd47e1 100644 --- a/src/main/resources/data/appliedenergistics2/recipes/smelting/iron_ingot.json +++ b/src/main/resources/data/appliedenergistics2/recipes/smelting/iron_ingot.json @@ -1,10 +1,10 @@ { - "type": "appliedenergistics2:smelt", + "type": "minecraft:smelting", "result": { "item": "minecraft:iron_ingot" }, - "input": { + "ingredient": { "tag": "forge:dusts/iron" }, - "xp": 0.0 + "experience": 0.0 } \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/smelting/silicon.json b/src/main/resources/data/appliedenergistics2/recipes/smelting/silicon.json index aaaa5714f..4956bc506 100644 --- a/src/main/resources/data/appliedenergistics2/recipes/smelting/silicon.json +++ b/src/main/resources/data/appliedenergistics2/recipes/smelting/silicon.json @@ -1,9 +1,9 @@ { - "type": "appliedenergistics2:smelt", + "type": "minecraft:smelting", "result": { "item": "appliedenergistics2:silicon" }, - "input": [ + "ingredient": [ { "tag": "appliedenergistics2:dusts/nether_quartz" }, @@ -11,5 +11,5 @@ "tag": "appliedenergistics2:dusts/certus_quartz" } ], - "xp": 0.0 + "experience": 0.0 } \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/recipes/smelting/smooth_sky_stone_block.json b/src/main/resources/data/appliedenergistics2/recipes/smelting/smooth_sky_stone_block.json index 02dcfc91f..2e5aadc1a 100644 --- a/src/main/resources/data/appliedenergistics2/recipes/smelting/smooth_sky_stone_block.json +++ b/src/main/resources/data/appliedenergistics2/recipes/smelting/smooth_sky_stone_block.json @@ -1,10 +1,10 @@ { - "type": "appliedenergistics2:smelt", + "type": "minecraft:smelting", "result": { "item": "appliedenergistics2:smooth_sky_stone_block" }, - "input": { + "ingredient": { "item": "appliedenergistics2:sky_stone_block" }, - "xp": 0.0 + "experience": 0.0 } \ No newline at end of file diff --git a/src/main/resources/data/appliedenergistics2/tags/items/dusts/ender.json b/src/main/resources/data/appliedenergistics2/tags/items/dusts/ender.json index f72d209df..f22431a8e 100644 --- a/src/main/resources/data/appliedenergistics2/tags/items/dusts/ender.json +++ b/src/main/resources/data/appliedenergistics2/tags/items/dusts/ender.json @@ -1,3 +1,3 @@ { - "values": [] + "values": ["appliedenergistics2:ender_dust"] } \ No newline at end of file diff --git a/src/main/resources/data/forge/tags/items/dusts/gold.json b/src/main/resources/data/forge/tags/items/dusts/gold.json new file mode 100644 index 000000000..a059d79b5 --- /dev/null +++ b/src/main/resources/data/forge/tags/items/dusts/gold.json @@ -0,0 +1,5 @@ +{ + "values": [ + "appliedenergistics2:gold_dust" + ] +} \ No newline at end of file diff --git a/src/main/resources/data/forge/tags/items/dusts/iron.json b/src/main/resources/data/forge/tags/items/dusts/iron.json new file mode 100644 index 000000000..6ea444823 --- /dev/null +++ b/src/main/resources/data/forge/tags/items/dusts/iron.json @@ -0,0 +1,5 @@ +{ + "values": [ + "appliedenergistics2:iron_dust" + ] +} \ No newline at end of file diff --git a/src/main/resources/data/forge/tags/items/gems/certus_quartz.json b/src/main/resources/data/forge/tags/items/gems/certus_quartz.json new file mode 100644 index 000000000..d306de422 --- /dev/null +++ b/src/main/resources/data/forge/tags/items/gems/certus_quartz.json @@ -0,0 +1,6 @@ +{ + "values": [ + "appliedenergistics2:certus_quartz_crystal", + "appliedenergistics2:charged_certus_quartz_crystal" + ] +} \ No newline at end of file diff --git a/src/main/resources/data/forge/tags/items/ores/certus_quartz.json b/src/main/resources/data/forge/tags/items/ores/certus_quartz.json new file mode 100644 index 000000000..ce24520a5 --- /dev/null +++ b/src/main/resources/data/forge/tags/items/ores/certus_quartz.json @@ -0,0 +1,6 @@ +{ + "values": [ + "appliedenergistics2:quartz_ore", + "appliedenergistics2:charged_quartz_ore" + ] +} \ No newline at end of file