From 8c29eeecdca8fc34f10a0298ce02b10372e8307a Mon Sep 17 00:00:00 2001 From: TheAirBlow Date: Mon, 26 Dec 2022 17:03:49 +0500 Subject: [PATCH] Add support for RecipeStages and ItemStages (#198) * RecipeStages info in README * Add support for RecipeStages * Add support for ItemStages --- README.md | 15 +++--- build.gradle | 1 + gradle/scripts/dependencies.gradle | 3 ++ .../container/slot/SlotCraftingTerm.java | 54 +++++++++++++++++-- src/main/java/appeng/core/AppEng.java | 2 +- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6411463f7..341f0333e 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,21 @@ This is a fork of AE2 i made for trying to solve issues for the [Omnifactory](https://www.curseforge.com/minecraft/modpacks/omnifactory) modpack. -See https://github.com/PrototypeTrousers/Applied-Energistics-2/tree/AE2-Omnifactory branch for commits -and -https://github.com/PrototypeTrousers/Applied-Energistics-2/releases for the compiled jars. +See [AE2-Omnifactory](https://github.com/PrototypeTrousers/Applied-Energistics-2/tree/AE2-Omnifactory) branch for commits and [Releases](https://github.com/PrototypeTrousers/Applied-Energistics-2/releases) for the compiled jars. # Applied Energistics 2 (PrototypeTrousers fork for Omnifactory) ## About +A Mod about Matter, Energy and using them to conquer the world. -A Mod about Matter, Energy and using them to conquer the world.. +## RecipeStages +You need to add the following into a CraftTweaker script: +``` +mods.recipestages.Recipes.setPackageStage("appeng", allStages); +``` + +The second argument allows you to customize which stages exactly you want to be craftable with AE2. Idk why would you like to restrict any, but you can. ## License - * Applied Energistics 2 API - (c) 2013 - 2018 AlgorithmX2 et al - [![License](https://img.shields.io/badge/License-MIT-red.svg?style=flat-square)](http://opensource.org/licenses/MIT) @@ -25,7 +29,6 @@ A Mod about Matter, Energy and using them to conquer the world.. - [![License](https://img.shields.io/badge/License-No%20Restriction-green.svg?style=flat-square)](https://creativecommons.org/publicdomain/zero/1.0/) ## Credits - Thanks to * Notch et al for Minecraft diff --git a/build.gradle b/build.gradle index 170f51e73..35fec2527 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,7 @@ buildscript { mavenLocal() jcenter() mavenCentral() + maven { name = "forge" url = "http://files.minecraftforge.net/maven" diff --git a/gradle/scripts/dependencies.gradle b/gradle/scripts/dependencies.gradle index c2e044283..a68a2c5ed 100644 --- a/gradle/scripts/dependencies.gradle +++ b/gradle/scripts/dependencies.gradle @@ -99,6 +99,9 @@ dependencies { //Code chicken lib, GTCE dependency deobfCompile "curse.maven:CCL-242818:2779848" + compileOnly "curse.maven:recipe-stages-280554:3405072" + compileOnly "curse.maven:item-stages-280316:2696769" + compileOnly "curse.maven:game-stages-268655:2951844" compileOnly "net.darkhax.tesla:Tesla-1.12.2:${tesla_version}" compileOnly "net.industrial-craft:industrialcraft-2:${ic2_version}:api" compileOnly "mcjty.theoneprobe:TheOneProbe-1.12:${top_version}:api" diff --git a/src/main/java/appeng/container/slot/SlotCraftingTerm.java b/src/main/java/appeng/container/slot/SlotCraftingTerm.java index 93e0b8f5b..2294ff058 100644 --- a/src/main/java/appeng/container/slot/SlotCraftingTerm.java +++ b/src/main/java/appeng/container/slot/SlotCraftingTerm.java @@ -40,6 +40,11 @@ import appeng.util.inv.AdaptorItemHandler; import appeng.util.inv.WrapperCursorItemHandler; import appeng.util.inv.WrapperInvItemHandler; import appeng.util.item.AEItemStack; +import com.blamejared.recipestages.RecipeStages; +import com.blamejared.recipestages.recipes.RecipeStage; +import net.darkhax.gamestages.GameStageHelper; +import net.darkhax.itemstages.ItemStages; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; @@ -49,8 +54,10 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.fml.common.Loader; import net.minecraftforge.items.IItemHandler; +import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -90,6 +97,23 @@ public class SlotCraftingTerm extends AppEngCraftingSlot { return is; } + // Don't render the item client-side if the item stage for it is not unlocked yet + @Override + public ItemStack getStack() { + if (Platform.isClient() && Loader.isModLoaded("itemstages")) { + final ItemStack item = super.getStack(); + final String itemsStage = ItemStages.getStage(item); + final String enchantStage = ItemStages.getEnchantStage(item); + final EntityPlayer player = Minecraft.getMinecraft().player; + + if ((itemsStage != null && !GameStageHelper.hasStage(player, itemsStage)) + || (enchantStage != null && !GameStageHelper.hasStage(player, enchantStage))) + return ItemStack.EMPTY; + } + + return super.getStack(); + } + public void doClick(final InventoryAction action, final EntityPlayer who) { if (this.getStack().isEmpty()) { return; @@ -144,17 +168,39 @@ public class SlotCraftingTerm extends AppEngCraftingSlot { } // TODO: This is really hacky and NEEDS to be solved with a full container/gui refactoring. - protected IRecipe findRecipe(InventoryCrafting ic, World world) { + protected IRecipe findRecipe(InventoryCrafting ic, World world, EntityPlayer player) { if (this.container instanceof ContainerCraftingTerm) { final ContainerCraftingTerm containerTerminal = (ContainerCraftingTerm) this.container; final IRecipe recipe = containerTerminal.getCurrentRecipe(); if (recipe != null && recipe.matches(ic, world)) { - return containerTerminal.getCurrentRecipe(); + return handleRecipe(ic, containerTerminal.getCurrentRecipe(), player); } } - return CraftingManager.findMatchingRecipe(ic, world); + return handleRecipe(ic, CraftingManager.findMatchingRecipe(ic, world), player); + } + + // Returns null in case this recipe is not yet unlocked + private IRecipe handleRecipe(InventoryCrafting ic, IRecipe recipe, EntityPlayer player) { + if (Loader.isModLoaded("recipestages")) { + if (recipe instanceof RecipeStage) { + final RecipeStage staged = (RecipeStage) recipe; + if (!staged.isGoodForCrafting(ic)) + return null; + } + } + + if (Loader.isModLoaded("itemstages")) { + final String itemsStage = ItemStages.getStage(recipe.getRecipeOutput()); + final String enchantStage = ItemStages.getEnchantStage(recipe.getRecipeOutput()); + + if ((itemsStage != null && !GameStageHelper.hasStage(player, itemsStage)) + || (enchantStage != null && !GameStageHelper.hasStage(player, enchantStage))) + return null; + } + + return recipe; } // TODO: This is really hacky and NEEDS to be solved with a full container/gui refactoring. @@ -192,7 +238,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot { ic.setInventorySlotContents(x, this.getPattern().getStackInSlot(x)); } - final IRecipe r = this.findRecipe(ic, p.world); + final IRecipe r = this.findRecipe(ic, p.world, p); if (r == null) { final Item target = request.getItem(); diff --git a/src/main/java/appeng/core/AppEng.java b/src/main/java/appeng/core/AppEng.java index 5c847260e..7cc7ab176 100644 --- a/src/main/java/appeng/core/AppEng.java +++ b/src/main/java/appeng/core/AppEng.java @@ -72,7 +72,7 @@ public final class AppEng { private static final String FORGE_CURRENT_VERSION = ForgeVersion.majorVersion + "." + ForgeVersion.minorVersion + "." + ForgeVersion.revisionVersion + "." + ForgeVersion.buildVersion; private static final String FORGE_MAX_VERSION = (ForgeVersion.majorVersion + 1) + ".0.0.0"; - public static final String MOD_DEPENDENCIES = "required-after:forge@[" + FORGE_CURRENT_VERSION + "," + FORGE_MAX_VERSION + ");after:ctm@[" + CTM.VERSION + ",);"; + public static final String MOD_DEPENDENCIES = "required-after:forge@[" + FORGE_CURRENT_VERSION + "," + FORGE_MAX_VERSION + ");after:ctm@[" + CTM.VERSION + ",);after:itemstages;after:recipestages"; @Nonnull private static final AppEng INSTANCE = new AppEng();