Add recipe types for faster runtime iteration. (#5312)
This commit is contained in:
parent
7c11fe1022
commit
a15c4dc9b0
15 changed files with 390 additions and 13 deletions
|
@ -18,6 +18,15 @@
|
|||
if (!this.field_70170_p.field_72995_K) {
|
||||
this.func_70893_e(true);
|
||||
int i = 1 + this.field_70146_Z.nextInt(3);
|
||||
@@ -329,7 +329,7 @@
|
||||
EnumDyeColor enumdyecolor1 = ((EntitySheep)p_175511_2_).func_175509_cj();
|
||||
this.field_90016_e.func_70299_a(0, new ItemStack(ItemDye.func_195961_a(enumdyecolor)));
|
||||
this.field_90016_e.func_70299_a(1, new ItemStack(ItemDye.func_195961_a(enumdyecolor1)));
|
||||
- ItemStack itemstack = p_175511_1_.field_70170_p.func_199532_z().func_199514_a(this.field_90016_e, ((EntitySheep)p_175511_1_).field_70170_p);
|
||||
+ ItemStack itemstack = p_175511_1_.field_70170_p.func_199532_z().getResult(this.field_90016_e, ((EntitySheep)p_175511_1_).field_70170_p, net.minecraftforge.common.crafting.VanillaRecipeTypes.CRAFTING);
|
||||
Item item = itemstack.func_77973_b();
|
||||
EnumDyeColor enumdyecolor2;
|
||||
if (item instanceof ItemDye) {
|
||||
@@ -344,4 +344,23 @@
|
||||
public float func_70047_e() {
|
||||
return 0.95F * this.field_70131_O;
|
||||
|
|
|
@ -41,3 +41,12 @@
|
|||
}
|
||||
|
||||
p_94525_2_.func_190917_f(p_94525_3_);
|
||||
@@ -576,7 +579,7 @@
|
||||
if (!p_192389_1_.field_72995_K) {
|
||||
EntityPlayerMP entityplayermp = (EntityPlayerMP)p_192389_2_;
|
||||
ItemStack itemstack = ItemStack.field_190927_a;
|
||||
- IRecipe irecipe = p_192389_1_.func_73046_m().func_199529_aN().func_199515_b(p_192389_3_, p_192389_1_);
|
||||
+ IRecipe irecipe = p_192389_1_.func_73046_m().func_199529_aN().getRecipe(p_192389_3_, p_192389_1_, net.minecraftforge.common.crafting.VanillaRecipeTypes.CRAFTING);
|
||||
if (p_192389_4_.func_201561_a(p_192389_1_, entityplayermp, irecipe) && irecipe != null) {
|
||||
itemstack = irecipe.func_77572_b(p_192389_3_);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
--- a/net/minecraft/inventory/ContainerFurnace.java
|
||||
+++ b/net/minecraft/inventory/ContainerFurnace.java
|
||||
@@ -161,8 +161,8 @@
|
||||
}
|
||||
|
||||
private boolean func_206253_a(ItemStack p_206253_1_) {
|
||||
- for(IRecipe irecipe : this.field_201773_f.func_199532_z().func_199510_b()) {
|
||||
- if (irecipe instanceof FurnaceRecipe && ((Ingredient)irecipe.func_192400_c().get(0)).test(p_206253_1_)) {
|
||||
+ for(IRecipe irecipe : this.field_201773_f.func_199532_z().getRecipes(net.minecraftforge.common.crafting.VanillaRecipeTypes.SMELTING)) {
|
||||
+ if (((Ingredient)irecipe.func_192400_c().get(0)).test(p_206253_1_)) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -12,8 +12,9 @@
|
|||
|
||||
public ItemStack func_190901_a(EntityPlayer p_190901_1_, ItemStack p_190901_2_) {
|
||||
this.func_75208_c(p_190901_2_);
|
||||
- NonNullList<ItemStack> nonnulllist = p_190901_1_.field_70170_p.func_199532_z().func_199513_c(this.field_75239_a, p_190901_1_.field_70170_p);
|
||||
+ net.minecraftforge.common.ForgeHooks.setCraftingPlayer(p_190901_1_);
|
||||
NonNullList<ItemStack> nonnulllist = p_190901_1_.field_70170_p.func_199532_z().func_199513_c(this.field_75239_a, p_190901_1_.field_70170_p);
|
||||
+ NonNullList<ItemStack> nonnulllist = p_190901_1_.field_70170_p.func_199532_z().getRemainingItems(this.field_75239_a, p_190901_1_.field_70170_p, net.minecraftforge.common.crafting.VanillaRecipeTypes.CRAFTING);
|
||||
+ net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
|
||||
|
||||
for(int i = 0; i < nonnulllist.size(); ++i) {
|
||||
|
|
|
@ -9,7 +9,15 @@
|
|||
|
||||
public class FurnaceRecipe implements IRecipe {
|
||||
private final ResourceLocation field_201832_a;
|
||||
@@ -38,7 +36,6 @@
|
||||
@@ -31,14 +29,13 @@
|
||||
}
|
||||
|
||||
public boolean func_77569_a(IInventory p_77569_1_, World p_77569_2_) {
|
||||
- return p_77569_1_ instanceof TileEntityFurnace && this.field_201834_c.test(p_77569_1_.func_70301_a(0));
|
||||
+ return this.field_201834_c.test(p_77569_1_.func_70301_a(0));
|
||||
}
|
||||
|
||||
public ItemStack func_77572_b(IInventory p_77572_1_) {
|
||||
return this.field_201835_d.func_77946_l();
|
||||
}
|
||||
|
||||
|
@ -25,15 +33,21 @@
|
|||
public String func_193358_e() {
|
||||
return this.field_201833_b;
|
||||
}
|
||||
@@ -75,6 +71,7 @@
|
||||
@@ -74,7 +70,13 @@
|
||||
return this.field_201832_a;
|
||||
}
|
||||
|
||||
+ @Override
|
||||
+ public net.minecraftforge.common.crafting.RecipeType<FurnaceRecipe> getType() {
|
||||
+ return net.minecraftforge.common.crafting.VanillaRecipeTypes.SMELTING;
|
||||
+ }
|
||||
+
|
||||
public static class Serializer implements IRecipeSerializer<FurnaceRecipe> {
|
||||
+ private static ResourceLocation NAME = new ResourceLocation("minecraft", "smelting");
|
||||
public FurnaceRecipe func_199425_a_(ResourceLocation p_199425_1_, JsonObject p_199425_2_) {
|
||||
String s = JsonUtils.func_151219_a(p_199425_2_, "group", "");
|
||||
Ingredient ingredient;
|
||||
@@ -113,8 +110,9 @@
|
||||
@@ -113,8 +115,9 @@
|
||||
p_199427_1_.func_150787_b(p_199427_2_.field_201837_f);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
-import net.minecraftforge.api.distmarker.Dist;
|
||||
-import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
|
||||
public interface IRecipe {
|
||||
-public interface IRecipe {
|
||||
+public interface IRecipe extends net.minecraftforge.common.extensions.IForgeRecipe {
|
||||
boolean func_77569_a(IInventory p_77569_1_, World p_77569_2_);
|
||||
|
||||
ItemStack func_77572_b(IInventory p_77572_1_);
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
--- a/net/minecraft/item/crafting/RecipeManager.java
|
||||
+++ b/net/minecraft/item/crafting/RecipeManager.java
|
||||
@@ -37,6 +37,8 @@
|
||||
@@ -25,7 +25,7 @@
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
-public class RecipeManager implements IResourceManagerReloadListener {
|
||||
+public class RecipeManager extends net.minecraftforge.common.extensions.ForgeRecipeManager {
|
||||
private static final Logger field_199521_c = LogManager.getLogger();
|
||||
public static final int field_199519_a = "recipes/".length();
|
||||
public static final int field_199520_b = ".json".length();
|
||||
@@ -36,6 +36,7 @@
|
||||
Gson gson = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
|
||||
this.field_199523_e = false;
|
||||
this.field_199522_d.clear();
|
||||
+ super.func_195410_a(p_195410_1_);
|
||||
|
||||
+ net.minecraftforge.common.crafting.CraftingHelper.reloadConstants(p_195410_1_);
|
||||
+
|
||||
for(ResourceLocation resourcelocation : p_195410_1_.func_199003_a("recipes", (p_199516_0_) -> {
|
||||
return p_199516_0_.endsWith(".json");
|
||||
})) {
|
||||
@@ -47,6 +49,8 @@
|
||||
@@ -47,6 +48,8 @@
|
||||
JsonObject jsonobject = (JsonObject)JsonUtils.func_188178_a(gson, IOUtils.toString(iresource.func_199027_b(), StandardCharsets.UTF_8), JsonObject.class);
|
||||
if (jsonobject == null) {
|
||||
field_199521_c.error("Couldn't load recipe {} as it's null or empty", (Object)resourcelocation1);
|
||||
|
@ -18,3 +26,40 @@
|
|||
} else {
|
||||
this.func_199509_a(RecipeSerializers.func_199572_a(resourcelocation1, jsonobject));
|
||||
}
|
||||
@@ -67,9 +70,12 @@
|
||||
throw new IllegalStateException("Duplicate recipe ignored with ID " + p_199509_1_.func_199560_c());
|
||||
} else {
|
||||
this.field_199522_d.put(p_199509_1_.func_199560_c(), p_199509_1_);
|
||||
+ if(!p_199509_1_.getType().getBaseClass().isAssignableFrom(p_199509_1_.getClass())) throw new IllegalStateException(String.format("Recipe type %s is not valid for class %s", p_199509_1_.getType().getBaseClass().getName(), p_199509_1_.getClass().getName()));
|
||||
+ ((java.util.List) getRecipes(p_199509_1_.getType())).add(p_199509_1_);
|
||||
}
|
||||
}
|
||||
|
||||
+ @Deprecated //Forge Use getResult(IInventory, World, RecipeType)
|
||||
public ItemStack func_199514_a(IInventory p_199514_1_, World p_199514_2_) {
|
||||
for(IRecipe irecipe : this.field_199522_d.values()) {
|
||||
if (irecipe.func_77569_a(p_199514_1_, p_199514_2_)) {
|
||||
@@ -81,6 +87,7 @@
|
||||
}
|
||||
|
||||
@Nullable
|
||||
+ @Deprecated //Forge: Use getRecipe(IInventory, World, RecipeType)
|
||||
public IRecipe func_199515_b(IInventory p_199515_1_, World p_199515_2_) {
|
||||
for(IRecipe irecipe : this.field_199522_d.values()) {
|
||||
if (irecipe.func_77569_a(p_199515_1_, p_199515_2_)) {
|
||||
@@ -91,6 +98,7 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
+ @Deprecated //Forge: Use getRemainingItems(IInventory, World, RecipeType)
|
||||
public NonNullList<ItemStack> func_199513_c(IInventory p_199513_1_, World p_199513_2_) {
|
||||
for(IRecipe irecipe : this.field_199522_d.values()) {
|
||||
if (irecipe.func_77569_a(p_199513_1_, p_199513_2_)) {
|
||||
@@ -123,5 +131,7 @@
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void func_199518_d() {
|
||||
this.field_199522_d.clear();
|
||||
+ this.sortedRecipes.clear();
|
||||
}
|
||||
+
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
public String func_193358_e() {
|
||||
return this.field_194137_e;
|
||||
}
|
||||
@@ -61,7 +71,6 @@
|
||||
@@ -61,13 +71,12 @@
|
||||
return this.field_77574_d;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,13 @@
|
|||
public boolean func_194133_a(int p_194133_1_, int p_194133_2_) {
|
||||
return p_194133_1_ >= this.field_77576_b && p_194133_2_ >= this.field_77577_c;
|
||||
}
|
||||
|
||||
public boolean func_77569_a(IInventory p_77569_1_, World p_77569_2_) {
|
||||
- if (!(p_77569_1_ instanceof InventoryCrafting)) {
|
||||
+ if (false) {
|
||||
return false;
|
||||
} else {
|
||||
for(int i = 0; i <= p_77569_1_.func_174922_i() - this.field_77576_b; ++i) {
|
||||
@@ -117,10 +126,20 @@
|
||||
return this.field_77576_b;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,12 @@
|
|||
public String func_193358_e() {
|
||||
return this.field_194138_c;
|
||||
}
|
||||
@@ -54,6 +53,7 @@
|
||||
@@ -50,10 +49,11 @@
|
||||
}
|
||||
|
||||
public boolean func_77569_a(IInventory p_77569_1_, World p_77569_2_) {
|
||||
- if (!(p_77569_1_ instanceof InventoryCrafting)) {
|
||||
+ if (false) {
|
||||
return false;
|
||||
} else {
|
||||
RecipeItemHelper recipeitemhelper = new RecipeItemHelper();
|
||||
|
|
|
@ -26,7 +26,14 @@
|
|||
ItemStackHelper.func_191282_a(p_189515_1_, this.field_145957_n);
|
||||
p_189515_1_.func_74777_a("RecipesUsedSize", (short)this.field_203901_m.size());
|
||||
int i = 0;
|
||||
@@ -254,6 +254,10 @@
|
||||
@@ -248,12 +248,16 @@
|
||||
if (!this.field_145850_b.field_72995_K) {
|
||||
ItemStack itemstack = this.field_145957_n.get(1);
|
||||
if (this.func_145950_i() || !itemstack.func_190926_b() && !((ItemStack)this.field_145957_n.get(0)).func_190926_b()) {
|
||||
- IRecipe irecipe = this.field_145850_b.func_199532_z().func_199515_b(this, this.field_145850_b);
|
||||
+ IRecipe irecipe = this.field_145850_b.func_199532_z().getRecipe(this, this.field_145850_b, net.minecraftforge.common.crafting.VanillaRecipeTypes.SMELTING);
|
||||
if (!this.func_145950_i() && this.func_201566_b(irecipe)) {
|
||||
this.field_145956_a = func_145952_a(itemstack);
|
||||
this.field_145963_i = this.field_145956_a;
|
||||
if (this.func_145950_i()) {
|
||||
flag1 = true;
|
||||
|
@ -37,6 +44,15 @@
|
|||
if (!itemstack.func_190926_b()) {
|
||||
Item item = itemstack.func_77973_b();
|
||||
itemstack.func_190918_g(1);
|
||||
@@ -293,7 +297,7 @@
|
||||
}
|
||||
|
||||
private int func_201562_r() {
|
||||
- FurnaceRecipe furnacerecipe = (FurnaceRecipe)this.field_145850_b.func_199532_z().func_199515_b(this, this.field_145850_b);
|
||||
+ FurnaceRecipe furnacerecipe = this.field_145850_b.func_199532_z().getRecipe(this, this.field_145850_b, net.minecraftforge.common.crafting.VanillaRecipeTypes.SMELTING);
|
||||
return furnacerecipe != null ? furnacerecipe.func_201830_h() : 200;
|
||||
}
|
||||
|
||||
@@ -308,10 +312,10 @@
|
||||
return true;
|
||||
} else if (!itemstack1.func_77969_a(itemstack)) {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
--- a/net/minecraft/world/storage/loot/functions/Smelt.java
|
||||
+++ b/net/minecraft/world/storage/loot/functions/Smelt.java
|
||||
@@ -43,8 +43,8 @@
|
||||
|
||||
@Nullable
|
||||
public static IRecipe func_202880_a(LootContext p_202880_0_, ItemStack p_202880_1_) {
|
||||
- for(IRecipe irecipe : p_202880_0_.func_202879_g().func_199532_z().func_199510_b()) {
|
||||
- if (irecipe instanceof FurnaceRecipe && ((Ingredient)irecipe.func_192400_c().get(0)).test(p_202880_1_)) {
|
||||
+ for(IRecipe irecipe : p_202880_0_.func_202879_g().func_199532_z().getRecipes(net.minecraftforge.common.crafting.VanillaRecipeTypes.SMELTING)) {
|
||||
+ if (((Ingredient)irecipe.func_192400_c().get(0)).test(p_202880_1_)) {
|
||||
return irecipe;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library 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 version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library 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 this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class RecipeType<T extends IRecipe>
|
||||
{
|
||||
private static final Map<ResourceLocation, RecipeType<?>> TYPES = new HashMap<>();
|
||||
|
||||
protected final ResourceLocation id;
|
||||
protected final Class<? extends T> baseClass;
|
||||
|
||||
private RecipeType(ResourceLocation id, Class<? extends T> baseClass) {
|
||||
this.id = id;
|
||||
this.baseClass = baseClass;
|
||||
}
|
||||
|
||||
public ResourceLocation getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The class that all recipes of this type must extend.
|
||||
*/
|
||||
public Class<? extends T> getBaseClass()
|
||||
{
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id The name of the recipe type.
|
||||
* @param baseClass The base class of all recipes using this type.
|
||||
* @return A recipe type, with the provided ID and base class, or null, if the entry exists and the base class is incorrect.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public static <T extends IRecipe> RecipeType<T> get(ResourceLocation id, Class<? extends T> baseClass)
|
||||
{
|
||||
RecipeType<?> type = TYPES.get(id);
|
||||
if(type == null)
|
||||
{
|
||||
type = new RecipeType<>(id, baseClass);
|
||||
TYPES.put(id, type);
|
||||
}
|
||||
else if(type.getBaseClass() != baseClass)
|
||||
{
|
||||
LogManager.getLogger().error("Attempted to access RecipeType {} with the wrong base class. Provided {}, expected {}.");
|
||||
return null;
|
||||
}
|
||||
return (RecipeType<T>) type;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library 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 version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library 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 this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
import net.minecraft.item.crafting.FurnaceRecipe;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public final class VanillaRecipeTypes
|
||||
{
|
||||
/**
|
||||
* Used for normal crafting.
|
||||
*/
|
||||
public static final RecipeType<IRecipe> CRAFTING = RecipeType.get(new ResourceLocation("crafting"), IRecipe.class);
|
||||
|
||||
/**
|
||||
* Used for furnace recipes.
|
||||
*/
|
||||
public static final RecipeType<FurnaceRecipe> SMELTING = RecipeType.get(new ResourceLocation("smelting"), FurnaceRecipe.class);
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library 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 version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library 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 this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.resources.IResourceManager;
|
||||
import net.minecraft.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.RecipeType;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class ForgeRecipeManager implements IResourceManagerReloadListener
|
||||
{
|
||||
protected final Map<RecipeType<? extends IRecipe>, List<? extends IRecipe>> sortedRecipes = Maps.newHashMap();
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
this.sortedRecipes.clear();
|
||||
CraftingHelper.reloadConstants(resourceManager);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends IRecipe> List<T> getRecipes(RecipeType<T> type)
|
||||
{
|
||||
return (List<T>) this.sortedRecipes.computeIfAbsent(type, t -> new ArrayList<>());
|
||||
}
|
||||
|
||||
public ItemStack getResult(IInventory input, World world, RecipeType<?> type)
|
||||
{
|
||||
for(IRecipe irecipe : getRecipes(type))
|
||||
if (irecipe.matches(input, world)) return irecipe.getCraftingResult(input);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T extends IRecipe> T getRecipe(IInventory input, World world, RecipeType<T> type)
|
||||
{
|
||||
for(T irecipe : getRecipes(type))
|
||||
if (irecipe.matches(input, world)) return irecipe;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modders should not use this if possible. In the context that this is used, you should already have the recipe. Do not run extra lookups using this method.
|
||||
*/
|
||||
public NonNullList<ItemStack> getRemainingItems(IInventory input, World world, RecipeType<?> type)
|
||||
{
|
||||
for(IRecipe irecipe : getRecipes(type))
|
||||
if (irecipe.matches(input, world)) return irecipe.getRemainingItems(input);
|
||||
|
||||
NonNullList<ItemStack> nonnulllist = NonNullList.withSize(input.getSizeInventory(), ItemStack.EMPTY);
|
||||
|
||||
for(int i = 0; i < nonnulllist.size(); ++i)
|
||||
nonnulllist.set(i, input.getStackInSlot(i));
|
||||
|
||||
return nonnulllist;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2018.
|
||||
*
|
||||
* This library 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 version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library 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 this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.common.crafting.RecipeType;
|
||||
import net.minecraftforge.common.crafting.VanillaRecipeTypes;
|
||||
|
||||
public interface IForgeRecipe {
|
||||
|
||||
/**
|
||||
* Used when sorting this recipe into it's category during load, and in the default type matcher below.
|
||||
* @return The type of this recipe.
|
||||
*/
|
||||
default RecipeType<? extends IRecipe> getType()
|
||||
{
|
||||
return VanillaRecipeTypes.CRAFTING;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue