Created
January 26, 2022 22:34
-
-
Save Lanse505/3df5f8761dff5b23fe8fb9dac6f85e05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This file is part of Applied Energistics 2. | |
* Copyright (c) 2021, TeamAppliedEnergistics, 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 <http://www.gnu.org/licenses/lgpl>. | |
*/ | |
package appeng.recipes.handlers; | |
import net.minecraft.core.NonNullList; | |
import net.minecraft.resources.ResourceLocation; | |
import net.minecraft.world.Container; | |
import net.minecraft.world.item.ItemStack; | |
import net.minecraft.world.item.crafting.Ingredient; | |
import net.minecraft.world.item.crafting.Recipe; | |
import net.minecraft.world.item.crafting.RecipeSerializer; | |
import net.minecraft.world.item.crafting.RecipeType; | |
import net.minecraft.world.level.Level; | |
import appeng.core.AppEng; | |
public class InscriberRecipe implements Recipe<Container> { | |
public static final ResourceLocation TYPE_ID = AppEng.makeId("inscriber"); | |
public static final RecipeType<InscriberRecipe> TYPE = RecipeType.register(TYPE_ID.toString()); | |
private final ResourceLocation id; | |
private final Ingredient middleInput; | |
private final Ingredient topOptional; | |
private final Ingredient bottomOptional; | |
private final ItemStack output; | |
private final InscriberProcessType processType; | |
public InscriberRecipe(ResourceLocation id, Ingredient middleInput, ItemStack output, | |
Ingredient topOptional, Ingredient bottomOptional, InscriberProcessType processType) { | |
this.id = id; | |
this.middleInput = middleInput; | |
this.output = output; | |
this.topOptional = topOptional; | |
this.bottomOptional = bottomOptional; | |
this.processType = processType; | |
} | |
@Override | |
public boolean matches(Container inv, Level level) { | |
return false; | |
} | |
@Override | |
public ItemStack assemble(Container inv) { | |
return this.output.copy(); | |
} | |
@Override | |
public boolean canCraftInDimensions(int width, int height) { | |
return true; | |
} | |
@Override | |
public ItemStack getResultItem() { | |
return output; | |
} | |
@Override | |
public ResourceLocation getId() { | |
return id; | |
} | |
@Override | |
public RecipeSerializer<?> getSerializer() { | |
return InscriberRecipeSerializer.INSTANCE; | |
} | |
@Override | |
public RecipeType<?> getType() { | |
return TYPE; | |
} | |
@Override | |
public NonNullList<Ingredient> getIngredients() { | |
NonNullList<Ingredient> nonnulllist = NonNullList.create(); | |
nonnulllist.add(this.topOptional); | |
nonnulllist.add(this.middleInput); | |
nonnulllist.add(this.bottomOptional); | |
return nonnulllist; | |
} | |
public Ingredient getMiddleInput() { | |
return middleInput; | |
} | |
public Ingredient getTopOptional() { | |
return topOptional; | |
} | |
public Ingredient getBottomOptional() { | |
return bottomOptional; | |
} | |
public InscriberProcessType getProcessType() { | |
return processType; | |
} | |
@Override | |
public boolean isSpecial() { | |
return true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lanse505.projecteextended.appliedenergistics2; | |
import appeng.recipes.handlers.InscriberRecipe; | |
import lanse505.projecteextended.IngredientHelper; | |
import moze_intel.projecte.api.mapper.collector.IMappingCollector; | |
import moze_intel.projecte.api.mapper.recipe.INSSFakeGroupManager; | |
import moze_intel.projecte.api.mapper.recipe.IRecipeTypeMapper; | |
import moze_intel.projecte.api.mapper.recipe.RecipeTypeMapper; | |
import moze_intel.projecte.api.nss.NSSItem; | |
import moze_intel.projecte.api.nss.NormalizedSimpleStack; | |
import net.minecraft.world.item.ItemStack; | |
import net.minecraft.world.item.crafting.Recipe; | |
import net.minecraft.world.item.crafting.RecipeType; | |
@RecipeTypeMapper | |
public class InscriberRecipeMapper implements IRecipeTypeMapper { | |
@Override | |
public String getName() { | |
return "InscriberRecipe"; | |
} | |
@Override | |
public String getDescription() { | |
return "Maps Inscriber recipes"; | |
} | |
@Override | |
public boolean canHandle(RecipeType<?> recipeType) { | |
return recipeType == InscriberRecipe.TYPE; | |
} | |
@Override | |
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, Recipe<?> recipe, INSSFakeGroupManager inssFakeGroupManager) { | |
if (!(recipe instanceof InscriberRecipe inscriber)) { | |
return false; | |
} | |
boolean handled = false; | |
ItemStack[] top = inscriber.getTopOptional().getItems(); | |
ItemStack[] middle = inscriber.getMiddleInput().getItems(); | |
ItemStack[] bottom = inscriber.getBottomOptional().getItems(); | |
ItemStack output = inscriber.getResultItem(); | |
for (ItemStack topStack : top) { | |
for (ItemStack centerStack : middle) { | |
for (ItemStack bottomStack : bottom) { | |
NormalizedSimpleStack nssTop = NSSItem.createItem(topStack); | |
NormalizedSimpleStack nssCenter = NSSItem.createItem(centerStack); | |
NormalizedSimpleStack nssBottom = NSSItem.createItem(bottomStack); | |
if (!output.isEmpty()) { | |
IngredientHelper helper = new IngredientHelper(mapper); | |
helper.put(nssTop, top.length); | |
helper.put(nssCenter, middle.length); | |
helper.put(nssBottom, bottom.length); | |
if (helper.addAsConversion(output)) { | |
handled = true; | |
} | |
} | |
} | |
} | |
} | |
return handled; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lanse505.projecteextended; | |
import moze_intel.projecte.api.mapper.collector.IMappingCollector; | |
import moze_intel.projecte.api.nss.NSSFluid; | |
import moze_intel.projecte.api.nss.NSSItem; | |
import moze_intel.projecte.api.nss.NormalizedSimpleStack; | |
import net.minecraft.world.item.ItemStack; | |
import net.minecraftforge.fluids.FluidStack; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class IngredientHelper { | |
private final IMappingCollector<NormalizedSimpleStack, Long> mapper; | |
private Map<NormalizedSimpleStack, Integer> ingredientMap = new HashMap<>(); | |
/** | |
* Gets set to false if we have a recipe that is more than we can handle | |
*/ | |
private boolean isValid = true; | |
public IngredientHelper(IMappingCollector<NormalizedSimpleStack, Long> mapper) { | |
this.mapper = mapper; | |
} | |
public void resetHelper() { | |
isValid = true; | |
ingredientMap = new HashMap<>(); | |
} | |
public void put(NormalizedSimpleStack stack, int amount) { | |
if (isValid) { | |
if (ingredientMap.containsKey(stack)) { | |
long newAmount = ingredientMap.get(stack) + (long) amount; | |
if (newAmount > Integer.MAX_VALUE || newAmount < Integer.MIN_VALUE) { | |
isValid = false; | |
} else { | |
ingredientMap.put(stack, (int) newAmount); | |
} | |
} else { | |
ingredientMap.put(stack, amount); | |
} | |
} | |
} | |
public void put(NormalizedSimpleStack stack, long amount) { | |
if (amount > Integer.MAX_VALUE || amount < Integer.MIN_VALUE) { | |
isValid = false; | |
} else { | |
put(stack, (int) amount); | |
} | |
} | |
public void put(FluidStack stack) { | |
put(NSSFluid.createFluid(stack), stack.getAmount()); | |
} | |
public void put(ItemStack stack) { | |
put(NSSItem.createItem(stack), stack.getCount()); | |
} | |
public boolean addAsConversion(NormalizedSimpleStack output, int outputAmount) { | |
if (isValid) { | |
mapper.addConversion(outputAmount, output, ingredientMap); | |
return true; | |
} | |
return false; | |
} | |
public boolean addAsConversion(NormalizedSimpleStack output, long outputAmount) { | |
if (outputAmount > Integer.MAX_VALUE) { | |
return false; | |
} | |
return addAsConversion(output, (int) outputAmount); | |
} | |
public boolean addAsConversion(FluidStack stack) { | |
return addAsConversion(NSSFluid.createFluid(stack), stack.getAmount()); | |
} | |
public boolean addAsConversion(ItemStack stack) { | |
return addAsConversion(NSSItem.createItem(stack), stack.getCount()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment