base mod created

This commit is contained in:
Mohammad-Ali Minaie
2018-10-08 09:07:47 -04:00
parent 0a7700c356
commit b86dedad2f
7848 changed files with 584664 additions and 1 deletions

View File

@@ -0,0 +1,263 @@
package net.minecraft.item.crafting;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Iterator;
import javax.annotation.Nullable;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.RegistryNamespaced;
import net.minecraft.world.World;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class CraftingManager
{
private static final Logger LOGGER = LogManager.getLogger();
private static int nextAvailableId;
public static final RegistryNamespaced<ResourceLocation, IRecipe> REGISTRY = net.minecraftforge.registries.GameData.getWrapper(IRecipe.class);
public static boolean init()
{
try
{
register("armordye", new RecipesArmorDyes());
register("bookcloning", new RecipeBookCloning());
register("mapcloning", new RecipesMapCloning());
register("mapextending", new RecipesMapExtending());
register("fireworks", new RecipeFireworks());
register("repairitem", new RecipeRepairItem());
register("tippedarrow", new RecipeTippedArrow());
register("bannerduplicate", new RecipesBanners.RecipeDuplicatePattern());
register("banneraddpattern", new RecipesBanners.RecipeAddPattern());
register("shielddecoration", new ShieldRecipes.Decoration());
register("shulkerboxcoloring", new ShulkerBoxRecipes.ShulkerBoxColoring());
return parseJsonRecipes();
}
catch (Throwable var1)
{
return false;
}
}
private static boolean parseJsonRecipes()
{
FileSystem filesystem = null;
Gson gson = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
boolean flag1;
try
{
URL url = CraftingManager.class.getResource("/assets/.mcassetsroot");
if (url != null)
{
URI uri = url.toURI();
Path path;
if ("file".equals(uri.getScheme()))
{
path = Paths.get(CraftingManager.class.getResource("/assets/minecraft/recipes").toURI());
}
else
{
if (!"jar".equals(uri.getScheme()))
{
LOGGER.error("Unsupported scheme " + uri + " trying to list all recipes");
boolean flag2 = false;
return flag2;
}
filesystem = FileSystems.newFileSystem(uri, Collections.emptyMap());
path = filesystem.getPath("/assets/minecraft/recipes");
}
Iterator<Path> iterator = Files.walk(path).iterator();
while (iterator.hasNext())
{
Path path1 = iterator.next();
if ("json".equals(FilenameUtils.getExtension(path1.toString())))
{
Path path2 = path.relativize(path1);
String s = FilenameUtils.removeExtension(path2.toString()).replaceAll("\\\\", "/");
ResourceLocation resourcelocation = new ResourceLocation(s);
BufferedReader bufferedreader = null;
try
{
boolean flag;
try
{
bufferedreader = Files.newBufferedReader(path1);
register(s, parseRecipeJson((JsonObject)JsonUtils.fromJson(gson, bufferedreader, JsonObject.class)));
}
catch (JsonParseException jsonparseexception)
{
LOGGER.error("Parsing error loading recipe " + resourcelocation, (Throwable)jsonparseexception);
flag = false;
return flag;
}
catch (IOException ioexception)
{
LOGGER.error("Couldn't read recipe " + resourcelocation + " from " + path1, (Throwable)ioexception);
flag = false;
return flag;
}
}
finally
{
IOUtils.closeQuietly((Reader)bufferedreader);
}
}
}
return true;
}
LOGGER.error("Couldn't find .mcassetsroot");
flag1 = false;
}
catch (IOException | URISyntaxException urisyntaxexception)
{
LOGGER.error("Couldn't get a list of all recipe files", (Throwable)urisyntaxexception);
flag1 = false;
return flag1;
}
finally
{
IOUtils.closeQuietly((Closeable)filesystem);
}
return flag1;
}
private static IRecipe parseRecipeJson(JsonObject p_193376_0_)
{
String s = JsonUtils.getString(p_193376_0_, "type");
if ("crafting_shaped".equals(s))
{
return ShapedRecipes.deserialize(p_193376_0_);
}
else if ("crafting_shapeless".equals(s))
{
return ShapelessRecipes.deserialize(p_193376_0_);
}
else
{
throw new JsonSyntaxException("Invalid or unsupported recipe type '" + s + "'");
}
}
//Forge: Made private use GameData/Registry events!
private static void register(String name, IRecipe recipe)
{
register(new ResourceLocation(name), recipe);
}
//Forge: Made private use GameData/Registry events!
private static void register(ResourceLocation name, IRecipe recipe)
{
if (REGISTRY.containsKey(name))
{
throw new IllegalStateException("Duplicate recipe ignored with ID " + name);
}
else
{
REGISTRY.register(nextAvailableId++, name, recipe);
}
}
/**
* Retrieves an ItemStack that has multiple recipes for it.
*/
public static ItemStack findMatchingResult(InventoryCrafting craftMatrix, World worldIn)
{
for (IRecipe irecipe : REGISTRY)
{
if (irecipe.matches(craftMatrix, worldIn))
{
return irecipe.getCraftingResult(craftMatrix);
}
}
return ItemStack.EMPTY;
}
@Nullable
public static IRecipe findMatchingRecipe(InventoryCrafting craftMatrix, World worldIn)
{
for (IRecipe irecipe : REGISTRY)
{
if (irecipe.matches(craftMatrix, worldIn))
{
return irecipe;
}
}
return null;
}
public static NonNullList<ItemStack> getRemainingItems(InventoryCrafting craftMatrix, World worldIn)
{
for (IRecipe irecipe : REGISTRY)
{
if (irecipe.matches(craftMatrix, worldIn))
{
return irecipe.getRemainingItems(craftMatrix);
}
}
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(craftMatrix.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
nonnulllist.set(i, craftMatrix.getStackInSlot(i));
}
return nonnulllist;
}
@Nullable
public static IRecipe getRecipe(ResourceLocation name)
{
return REGISTRY.getObject(name);
}
@Deprecated //DO NOT USE THIS
public static int getIDForRecipe(IRecipe recipe)
{
return REGISTRY.getIDForObject(recipe);
}
@Deprecated //DO NOT USE THIS
@Nullable
public static IRecipe getRecipeById(int id)
{
return REGISTRY.getObjectById(id);
}
}

View File

@@ -0,0 +1,179 @@
package net.minecraft.item.crafting;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStoneBrick;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFishFood;
import net.minecraft.item.ItemStack;
public class FurnaceRecipes
{
private static final FurnaceRecipes SMELTING_BASE = new FurnaceRecipes();
/** The list of smelting results. */
private final Map<ItemStack, ItemStack> smeltingList = Maps.<ItemStack, ItemStack>newHashMap();
/** A list which contains how many experience points each recipe output will give. */
private final Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();
/**
* Returns an instance of FurnaceRecipes.
*/
public static FurnaceRecipes instance()
{
return SMELTING_BASE;
}
private FurnaceRecipes()
{
this.addSmeltingRecipeForBlock(Blocks.IRON_ORE, new ItemStack(Items.IRON_INGOT), 0.7F);
this.addSmeltingRecipeForBlock(Blocks.GOLD_ORE, new ItemStack(Items.GOLD_INGOT), 1.0F);
this.addSmeltingRecipeForBlock(Blocks.DIAMOND_ORE, new ItemStack(Items.DIAMOND), 1.0F);
this.addSmeltingRecipeForBlock(Blocks.SAND, new ItemStack(Blocks.GLASS), 0.1F);
this.addSmelting(Items.PORKCHOP, new ItemStack(Items.COOKED_PORKCHOP), 0.35F);
this.addSmelting(Items.BEEF, new ItemStack(Items.COOKED_BEEF), 0.35F);
this.addSmelting(Items.CHICKEN, new ItemStack(Items.COOKED_CHICKEN), 0.35F);
this.addSmelting(Items.RABBIT, new ItemStack(Items.COOKED_RABBIT), 0.35F);
this.addSmelting(Items.MUTTON, new ItemStack(Items.COOKED_MUTTON), 0.35F);
this.addSmeltingRecipeForBlock(Blocks.COBBLESTONE, new ItemStack(Blocks.STONE), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STONEBRICK, 1, BlockStoneBrick.DEFAULT_META), new ItemStack(Blocks.STONEBRICK, 1, BlockStoneBrick.CRACKED_META), 0.1F);
this.addSmelting(Items.CLAY_BALL, new ItemStack(Items.BRICK), 0.3F);
this.addSmeltingRecipeForBlock(Blocks.CLAY, new ItemStack(Blocks.HARDENED_CLAY), 0.35F);
this.addSmeltingRecipeForBlock(Blocks.CACTUS, new ItemStack(Items.DYE, 1, EnumDyeColor.GREEN.getDyeDamage()), 0.2F);
this.addSmeltingRecipeForBlock(Blocks.LOG, new ItemStack(Items.COAL, 1, 1), 0.15F);
this.addSmeltingRecipeForBlock(Blocks.LOG2, new ItemStack(Items.COAL, 1, 1), 0.15F);
this.addSmeltingRecipeForBlock(Blocks.EMERALD_ORE, new ItemStack(Items.EMERALD), 1.0F);
this.addSmelting(Items.POTATO, new ItemStack(Items.BAKED_POTATO), 0.35F);
this.addSmeltingRecipeForBlock(Blocks.NETHERRACK, new ItemStack(Items.NETHERBRICK), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.SPONGE, 1, 1), new ItemStack(Blocks.SPONGE, 1, 0), 0.15F);
this.addSmelting(Items.CHORUS_FRUIT, new ItemStack(Items.CHORUS_FRUIT_POPPED), 0.1F);
for (ItemFishFood.FishType itemfishfood$fishtype : ItemFishFood.FishType.values())
{
if (itemfishfood$fishtype.canCook())
{
this.addSmeltingRecipe(new ItemStack(Items.FISH, 1, itemfishfood$fishtype.getMetadata()), new ItemStack(Items.COOKED_FISH, 1, itemfishfood$fishtype.getMetadata()), 0.35F);
}
}
this.addSmeltingRecipeForBlock(Blocks.COAL_ORE, new ItemStack(Items.COAL), 0.1F);
this.addSmeltingRecipeForBlock(Blocks.REDSTONE_ORE, new ItemStack(Items.REDSTONE), 0.7F);
this.addSmeltingRecipeForBlock(Blocks.LAPIS_ORE, new ItemStack(Items.DYE, 1, EnumDyeColor.BLUE.getDyeDamage()), 0.2F);
this.addSmeltingRecipeForBlock(Blocks.QUARTZ_ORE, new ItemStack(Items.QUARTZ), 0.2F);
this.addSmelting(Items.CHAINMAIL_HELMET, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.CHAINMAIL_CHESTPLATE, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.CHAINMAIL_LEGGINGS, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.CHAINMAIL_BOOTS, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_PICKAXE, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_SHOVEL, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_AXE, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_HOE, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_SWORD, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_HELMET, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_CHESTPLATE, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_LEGGINGS, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_BOOTS, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.IRON_HORSE_ARMOR, new ItemStack(Items.IRON_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_PICKAXE, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_SHOVEL, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_AXE, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_HOE, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_SWORD, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_HELMET, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_CHESTPLATE, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_LEGGINGS, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_BOOTS, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmelting(Items.GOLDEN_HORSE_ARMOR, new ItemStack(Items.GOLD_NUGGET), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.WHITE.getMetadata()), new ItemStack(Blocks.WHITE_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.ORANGE.getMetadata()), new ItemStack(Blocks.ORANGE_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.MAGENTA.getMetadata()), new ItemStack(Blocks.MAGENTA_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.LIGHT_BLUE.getMetadata()), new ItemStack(Blocks.LIGHT_BLUE_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.YELLOW.getMetadata()), new ItemStack(Blocks.YELLOW_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.LIME.getMetadata()), new ItemStack(Blocks.LIME_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.PINK.getMetadata()), new ItemStack(Blocks.PINK_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.GRAY.getMetadata()), new ItemStack(Blocks.GRAY_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.SILVER.getMetadata()), new ItemStack(Blocks.SILVER_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.CYAN.getMetadata()), new ItemStack(Blocks.CYAN_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.PURPLE.getMetadata()), new ItemStack(Blocks.PURPLE_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.BLUE.getMetadata()), new ItemStack(Blocks.BLUE_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.BROWN.getMetadata()), new ItemStack(Blocks.BROWN_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.GREEN.getMetadata()), new ItemStack(Blocks.GREEN_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.RED.getMetadata()), new ItemStack(Blocks.RED_GLAZED_TERRACOTTA), 0.1F);
this.addSmeltingRecipe(new ItemStack(Blocks.STAINED_HARDENED_CLAY, 1, EnumDyeColor.BLACK.getMetadata()), new ItemStack(Blocks.BLACK_GLAZED_TERRACOTTA), 0.1F);
}
/**
* Adds a smelting recipe, where the input item is an instance of Block.
*/
public void addSmeltingRecipeForBlock(Block input, ItemStack stack, float experience)
{
this.addSmelting(Item.getItemFromBlock(input), stack, experience);
}
/**
* Adds a smelting recipe using an Item as the input item.
*/
public void addSmelting(Item input, ItemStack stack, float experience)
{
this.addSmeltingRecipe(new ItemStack(input, 1, 32767), stack, experience);
}
/**
* Adds a smelting recipe using an ItemStack as the input for the recipe.
*/
public void addSmeltingRecipe(ItemStack input, ItemStack stack, float experience)
{
if (getSmeltingResult(input) != ItemStack.EMPTY) { net.minecraftforge.fml.common.FMLLog.log.info("Ignored smelting recipe with conflicting input: {} = {}", input, stack); return; }
this.smeltingList.put(input, stack);
this.experienceList.put(stack, Float.valueOf(experience));
}
/**
* Returns the smelting result of an item.
*/
public ItemStack getSmeltingResult(ItemStack stack)
{
for (Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet())
{
if (this.compareItemStacks(stack, entry.getKey()))
{
return entry.getValue();
}
}
return ItemStack.EMPTY;
}
/**
* Compares two itemstacks to ensure that they are the same. This checks both the item and the metadata of the item.
*/
private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
{
return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata());
}
public Map<ItemStack, ItemStack> getSmeltingList()
{
return this.smeltingList;
}
public float getSmeltingExperience(ItemStack stack)
{
float ret = stack.getItem().getSmeltingExperience(stack);
if (ret != -1) return ret;
for (Entry<ItemStack, Float> entry : this.experienceList.entrySet())
{
if (this.compareItemStacks(stack, entry.getKey()))
{
return ((Float)entry.getValue()).floatValue();
}
}
return 0.0F;
}
}

View File

@@ -0,0 +1,46 @@
package net.minecraft.item.crafting;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public interface IRecipe extends net.minecraftforge.registries.IForgeRegistryEntry<IRecipe>
{
/**
* Used to check if a recipe matches current crafting inventory
*/
boolean matches(InventoryCrafting inv, World worldIn);
/**
* Returns an Item that is the result of this recipe
*/
ItemStack getCraftingResult(InventoryCrafting inv);
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
boolean canFit(int width, int height);
ItemStack getRecipeOutput();
default NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
return net.minecraftforge.common.ForgeHooks.defaultRecipeGetRemainingItems(inv);
}
default NonNullList<Ingredient> getIngredients()
{
return NonNullList.<Ingredient>create();
}
default boolean isDynamic()
{
return false;
}
default String getGroup()
{
return "";
}
}

View File

@@ -0,0 +1,163 @@
package net.minecraft.item.crafting;
import com.google.common.base.Predicate;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntComparators;
import it.unimi.dsi.fastutil.ints.IntList;
import javax.annotation.Nullable;
import net.minecraft.client.util.RecipeItemHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class Ingredient implements Predicate<ItemStack>
{
//Because Mojang caches things... we need to invalidate them.. so... here we go..
private static final java.util.Set<Ingredient> INSTANCES = java.util.Collections.newSetFromMap(new java.util.WeakHashMap<Ingredient, Boolean>());
public static final Ingredient EMPTY = new Ingredient(new ItemStack[0])
{
public boolean apply(@Nullable ItemStack p_apply_1_)
{
return p_apply_1_.isEmpty();
}
};
public final ItemStack[] matchingStacks;
private final ItemStack[] matchingStacksExploded;
private IntList matchingStacksPacked;
private final boolean isSimple;
protected Ingredient(int size)
{
this(new ItemStack[size]);
}
protected Ingredient(ItemStack... p_i47503_1_)
{
boolean simple = true;
this.matchingStacks = p_i47503_1_;
net.minecraft.util.NonNullList<ItemStack> lst = net.minecraft.util.NonNullList.create();
for (ItemStack s : p_i47503_1_)
{
if (s.isEmpty())
continue;
if (s.getItem().isDamageable())
simple = false;
if (s.getMetadata() == net.minecraftforge.oredict.OreDictionary.WILDCARD_VALUE)
s.getItem().getSubItems(net.minecraft.creativetab.CreativeTabs.SEARCH, lst);
else
lst.add(s);
}
this.matchingStacksExploded = lst.toArray(new ItemStack[lst.size()]);
this.isSimple = simple && this.matchingStacksExploded.length > 0;
Ingredient.INSTANCES.add(this);
}
public ItemStack[] getMatchingStacks()
{
return this.matchingStacksExploded;
}
public boolean apply(@Nullable ItemStack p_apply_1_)
{
if (p_apply_1_ == null)
{
return false;
}
else
{
for (ItemStack itemstack : this.matchingStacks)
{
if (itemstack.getItem() == p_apply_1_.getItem())
{
int i = itemstack.getMetadata();
if (i == 32767 || i == p_apply_1_.getMetadata())
{
return true;
}
}
}
return false;
}
}
public IntList getValidItemStacksPacked()
{
if (this.matchingStacksPacked == null)
{
this.matchingStacksPacked = new IntArrayList(this.matchingStacksExploded.length);
for (ItemStack itemstack : this.matchingStacksExploded)
{
this.matchingStacksPacked.add(RecipeItemHelper.pack(itemstack));
}
this.matchingStacksPacked.sort(IntComparators.NATURAL_COMPARATOR);
}
return this.matchingStacksPacked;
}
public static void invalidateAll()
{
for (Ingredient ing : INSTANCES)
if (ing != null)
ing.invalidate();
}
protected void invalidate()
{
this.matchingStacksPacked = null;
}
public static Ingredient fromItem(Item p_193367_0_)
{
return fromStacks(new ItemStack(p_193367_0_, 1, 32767));
}
public static Ingredient fromItems(Item... items)
{
ItemStack[] aitemstack = new ItemStack[items.length];
for (int i = 0; i < items.length; ++i)
{
aitemstack[i] = new ItemStack(items[i]);
}
return fromStacks(aitemstack);
}
public static Ingredient fromStacks(ItemStack... stacks)
{
if (stacks.length > 0)
{
for (ItemStack itemstack : stacks)
{
if (!itemstack.isEmpty())
{
return new Ingredient(stacks);
}
}
}
return EMPTY;
}
// Merges several vanilla Ingredients together. As a qwerk of how the json is structured, we can't tell if its a single Ingredient type or multiple so we split per item and remerge here.
//Only public for internal use, so we can access a private field in here.
public static Ingredient merge(java.util.Collection<Ingredient> parts)
{
net.minecraft.util.NonNullList<ItemStack> lst = net.minecraft.util.NonNullList.create();
for (Ingredient part : parts)
{
for (ItemStack stack : part.matchingStacks)
lst.add(stack);
}
return new Ingredient(lst.toArray(new ItemStack[lst.size()]));
}
public boolean isSimple()
{
return isSimple || this == EMPTY;
}
}

View File

@@ -0,0 +1,141 @@
package net.minecraft.item.crafting;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemWrittenBook;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class RecipeBookCloning extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
int i = 0;
ItemStack itemstack = ItemStack.EMPTY;
for (int j = 0; j < inv.getSizeInventory(); ++j)
{
ItemStack itemstack1 = inv.getStackInSlot(j);
if (!itemstack1.isEmpty())
{
if (itemstack1.getItem() == Items.WRITTEN_BOOK)
{
if (!itemstack.isEmpty())
{
return false;
}
itemstack = itemstack1;
}
else
{
if (itemstack1.getItem() != Items.WRITABLE_BOOK)
{
return false;
}
++i;
}
}
}
return !itemstack.isEmpty() && itemstack.hasTagCompound() && i > 0;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
int i = 0;
ItemStack itemstack = ItemStack.EMPTY;
for (int j = 0; j < inv.getSizeInventory(); ++j)
{
ItemStack itemstack1 = inv.getStackInSlot(j);
if (!itemstack1.isEmpty())
{
if (itemstack1.getItem() == Items.WRITTEN_BOOK)
{
if (!itemstack.isEmpty())
{
return ItemStack.EMPTY;
}
itemstack = itemstack1;
}
else
{
if (itemstack1.getItem() != Items.WRITABLE_BOOK)
{
return ItemStack.EMPTY;
}
++i;
}
}
}
if (!itemstack.isEmpty() && itemstack.hasTagCompound() && i >= 1 && ItemWrittenBook.getGeneration(itemstack) < 2)
{
ItemStack itemstack2 = new ItemStack(Items.WRITTEN_BOOK, i);
itemstack2.setTagCompound(itemstack.getTagCompound().copy());
itemstack2.getTagCompound().setInteger("generation", ItemWrittenBook.getGeneration(itemstack) + 1);
if (itemstack.hasDisplayName())
{
itemstack2.setStackDisplayName(itemstack.getDisplayName());
}
return itemstack2;
}
else
{
return ItemStack.EMPTY;
}
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (itemstack.getItem() instanceof ItemWrittenBook)
{
ItemStack itemstack1 = itemstack.copy();
itemstack1.setCount(1);
nonnulllist.set(i, itemstack1);
break;
}
}
return nonnulllist;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width >= 3 && height >= 3;
}
}

View File

@@ -0,0 +1,273 @@
package net.minecraft.item.crafting;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemDye;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class RecipeFireworks extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
private ItemStack resultItem = ItemStack.EMPTY;
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
this.resultItem = ItemStack.EMPTY;
int i = 0;
int j = 0;
int k = 0;
int l = 0;
int i1 = 0;
int j1 = 0;
for (int k1 = 0; k1 < inv.getSizeInventory(); ++k1)
{
ItemStack itemstack = inv.getStackInSlot(k1);
if (!itemstack.isEmpty())
{
if (itemstack.getItem() == Items.GUNPOWDER)
{
++j;
}
else if (itemstack.getItem() == Items.FIREWORK_CHARGE)
{
++l;
}
else if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack))
{
++k;
}
else if (itemstack.getItem() == Items.PAPER)
{
++i;
}
else if (itemstack.getItem() == Items.GLOWSTONE_DUST)
{
++i1;
}
else if (itemstack.getItem() == Items.DIAMOND)
{
++i1;
}
else if (itemstack.getItem() == Items.FIRE_CHARGE)
{
++j1;
}
else if (itemstack.getItem() == Items.FEATHER)
{
++j1;
}
else if (itemstack.getItem() == Items.GOLD_NUGGET)
{
++j1;
}
else
{
if (itemstack.getItem() != Items.SKULL)
{
return false;
}
++j1;
}
}
}
i1 = i1 + k + j1;
if (j <= 3 && i <= 1)
{
if (j >= 1 && i == 1 && i1 == 0)
{
this.resultItem = new ItemStack(Items.FIREWORKS, 3);
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
if (l > 0)
{
NBTTagList nbttaglist = new NBTTagList();
for (int k2 = 0; k2 < inv.getSizeInventory(); ++k2)
{
ItemStack itemstack3 = inv.getStackInSlot(k2);
if (itemstack3.getItem() == Items.FIREWORK_CHARGE && itemstack3.hasTagCompound() && itemstack3.getTagCompound().hasKey("Explosion", 10))
{
nbttaglist.appendTag(itemstack3.getTagCompound().getCompoundTag("Explosion"));
}
}
nbttagcompound1.setTag("Explosions", nbttaglist);
}
nbttagcompound1.setByte("Flight", (byte)j);
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
nbttagcompound3.setTag("Fireworks", nbttagcompound1);
this.resultItem.setTagCompound(nbttagcompound3);
return true;
}
else if (j == 1 && i == 0 && l == 0 && k > 0 && j1 <= 1)
{
this.resultItem = new ItemStack(Items.FIREWORK_CHARGE);
NBTTagCompound nbttagcompound = new NBTTagCompound();
NBTTagCompound nbttagcompound2 = new NBTTagCompound();
byte b0 = 0;
List<Integer> list = Lists.<Integer>newArrayList();
for (int l1 = 0; l1 < inv.getSizeInventory(); ++l1)
{
ItemStack itemstack2 = inv.getStackInSlot(l1);
if (!itemstack2.isEmpty())
{
if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack2))
{
list.add(Integer.valueOf(ItemDye.DYE_COLORS[net.minecraftforge.oredict.DyeUtils.rawDyeDamageFromStack(itemstack2) & 15]));
}
else if (itemstack2.getItem() == Items.GLOWSTONE_DUST)
{
nbttagcompound2.setBoolean("Flicker", true);
}
else if (itemstack2.getItem() == Items.DIAMOND)
{
nbttagcompound2.setBoolean("Trail", true);
}
else if (itemstack2.getItem() == Items.FIRE_CHARGE)
{
b0 = 1;
}
else if (itemstack2.getItem() == Items.FEATHER)
{
b0 = 4;
}
else if (itemstack2.getItem() == Items.GOLD_NUGGET)
{
b0 = 2;
}
else if (itemstack2.getItem() == Items.SKULL)
{
b0 = 3;
}
}
}
int[] aint1 = new int[list.size()];
for (int l2 = 0; l2 < aint1.length; ++l2)
{
aint1[l2] = ((Integer)list.get(l2)).intValue();
}
nbttagcompound2.setIntArray("Colors", aint1);
nbttagcompound2.setByte("Type", b0);
nbttagcompound.setTag("Explosion", nbttagcompound2);
this.resultItem.setTagCompound(nbttagcompound);
return true;
}
else if (j == 0 && i == 0 && l == 1 && k > 0 && k == i1)
{
List<Integer> list1 = Lists.<Integer>newArrayList();
for (int i2 = 0; i2 < inv.getSizeInventory(); ++i2)
{
ItemStack itemstack1 = inv.getStackInSlot(i2);
if (!itemstack1.isEmpty())
{
if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack1))
{
list1.add(Integer.valueOf(ItemDye.DYE_COLORS[net.minecraftforge.oredict.DyeUtils.rawDyeDamageFromStack(itemstack1) & 15]));
}
else if (itemstack1.getItem() == Items.FIREWORK_CHARGE)
{
this.resultItem = itemstack1.copy();
this.resultItem.setCount(1);
}
}
}
int[] aint = new int[list1.size()];
for (int j2 = 0; j2 < aint.length; ++j2)
{
aint[j2] = ((Integer)list1.get(j2)).intValue();
}
if (!this.resultItem.isEmpty() && this.resultItem.hasTagCompound())
{
NBTTagCompound nbttagcompound4 = this.resultItem.getTagCompound().getCompoundTag("Explosion");
if (nbttagcompound4 == null)
{
return false;
}
else
{
nbttagcompound4.setIntArray("FadeColors", aint);
return true;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
return this.resultItem.copy();
}
public ItemStack getRecipeOutput()
{
return this.resultItem;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
}
return nonnulllist;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width * height >= 1;
}
}

View File

@@ -0,0 +1,125 @@
package net.minecraft.item.crafting;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class RecipeRepairItem extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
List<ItemStack> list = Lists.<ItemStack>newArrayList();
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty())
{
list.add(itemstack);
if (list.size() > 1)
{
ItemStack itemstack1 = list.get(0);
if (itemstack.getItem() != itemstack1.getItem() || itemstack1.getCount() != 1 || itemstack.getCount() != 1 || !itemstack1.getItem().isRepairable())
{
return false;
}
}
}
}
return list.size() == 2;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
List<ItemStack> list = Lists.<ItemStack>newArrayList();
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty())
{
list.add(itemstack);
if (list.size() > 1)
{
ItemStack itemstack1 = list.get(0);
if (itemstack.getItem() != itemstack1.getItem() || itemstack1.getCount() != 1 || itemstack.getCount() != 1 || !itemstack1.getItem().isRepairable())
{
return ItemStack.EMPTY;
}
}
}
}
if (list.size() == 2)
{
ItemStack itemstack2 = list.get(0);
ItemStack itemstack3 = list.get(1);
if (itemstack2.getItem() == itemstack3.getItem() && itemstack2.getCount() == 1 && itemstack3.getCount() == 1 && itemstack2.getItem().isRepairable())
{
// FORGE: Make itemstack sensitive // Item item = itemstack2.getItem();
int j = itemstack2.getMaxDamage() - itemstack2.getItemDamage();
int k = itemstack2.getMaxDamage() - itemstack3.getItemDamage();
int l = j + k + itemstack2.getMaxDamage() * 5 / 100;
int i1 = itemstack2.getMaxDamage() - l;
if (i1 < 0)
{
i1 = 0;
}
return new ItemStack(itemstack2.getItem(), 1, i1);
}
}
return ItemStack.EMPTY;
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
}
return nonnulllist;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width * height >= 2;
}
}

View File

@@ -0,0 +1,97 @@
package net.minecraft.item.crafting;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class RecipeTippedArrow extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
if (inv.getWidth() == 3 && inv.getHeight() == 3)
{
for (int i = 0; i < inv.getWidth(); ++i)
{
for (int j = 0; j < inv.getHeight(); ++j)
{
ItemStack itemstack = inv.getStackInRowAndColumn(i, j);
if (itemstack.isEmpty())
{
return false;
}
Item item = itemstack.getItem();
if (i == 1 && j == 1)
{
if (item != Items.LINGERING_POTION)
{
return false;
}
}
else if (item != Items.ARROW)
{
return false;
}
}
}
return true;
}
else
{
return false;
}
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
ItemStack itemstack = inv.getStackInRowAndColumn(1, 1);
if (itemstack.getItem() != Items.LINGERING_POTION)
{
return ItemStack.EMPTY;
}
else
{
ItemStack itemstack1 = new ItemStack(Items.TIPPED_ARROW, 8);
PotionUtils.addPotionToItemStack(itemstack1, PotionUtils.getPotionFromItem(itemstack));
PotionUtils.appendEffects(itemstack1, PotionUtils.getFullEffectsFromItem(itemstack));
return itemstack1;
}
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
return NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width >= 2 && height >= 2;
}
}

View File

@@ -0,0 +1,168 @@
package net.minecraft.item.crafting;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class RecipesArmorDyes extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
ItemStack itemstack = ItemStack.EMPTY;
List<ItemStack> list = Lists.<ItemStack>newArrayList();
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack1 = inv.getStackInSlot(i);
if (!itemstack1.isEmpty())
{
if (itemstack1.getItem() instanceof ItemArmor)
{
ItemArmor itemarmor = (ItemArmor)itemstack1.getItem();
if (itemarmor.getArmorMaterial() != ItemArmor.ArmorMaterial.LEATHER || !itemstack.isEmpty())
{
return false;
}
itemstack = itemstack1;
}
else
{
if (!net.minecraftforge.oredict.DyeUtils.isDye(itemstack1))
{
return false;
}
list.add(itemstack1);
}
}
}
return !itemstack.isEmpty() && !list.isEmpty();
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
ItemStack itemstack = ItemStack.EMPTY;
int[] aint = new int[3];
int i = 0;
int j = 0;
ItemArmor itemarmor = null;
for (int k = 0; k < inv.getSizeInventory(); ++k)
{
ItemStack itemstack1 = inv.getStackInSlot(k);
if (!itemstack1.isEmpty())
{
if (itemstack1.getItem() instanceof ItemArmor)
{
itemarmor = (ItemArmor)itemstack1.getItem();
if (itemarmor.getArmorMaterial() != ItemArmor.ArmorMaterial.LEATHER || !itemstack.isEmpty())
{
return ItemStack.EMPTY;
}
itemstack = itemstack1.copy();
itemstack.setCount(1);
if (itemarmor.hasColor(itemstack1))
{
int l = itemarmor.getColor(itemstack);
float f = (float)(l >> 16 & 255) / 255.0F;
float f1 = (float)(l >> 8 & 255) / 255.0F;
float f2 = (float)(l & 255) / 255.0F;
i = (int)((float)i + Math.max(f, Math.max(f1, f2)) * 255.0F);
aint[0] = (int)((float)aint[0] + f * 255.0F);
aint[1] = (int)((float)aint[1] + f1 * 255.0F);
aint[2] = (int)((float)aint[2] + f2 * 255.0F);
++j;
}
}
else
{
if (!net.minecraftforge.oredict.DyeUtils.isDye(itemstack1))
{
return ItemStack.EMPTY;
}
float[] afloat = net.minecraftforge.oredict.DyeUtils.colorFromStack(itemstack1).get().getColorComponentValues();
int l1 = (int)(afloat[0] * 255.0F);
int i2 = (int)(afloat[1] * 255.0F);
int j2 = (int)(afloat[2] * 255.0F);
i += Math.max(l1, Math.max(i2, j2));
aint[0] += l1;
aint[1] += i2;
aint[2] += j2;
++j;
}
}
}
if (itemarmor == null)
{
return ItemStack.EMPTY;
}
else
{
int i1 = aint[0] / j;
int j1 = aint[1] / j;
int k1 = aint[2] / j;
float f3 = (float)i / (float)j;
float f4 = (float)Math.max(i1, Math.max(j1, k1));
i1 = (int)((float)i1 * f3 / f4);
j1 = (int)((float)j1 * f3 / f4);
k1 = (int)((float)k1 * f3 / f4);
int k2 = (i1 << 8) + j1;
k2 = (k2 << 8) + k1;
itemarmor.setColor(itemstack, k2);
return itemstack;
}
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
}
return nonnulllist;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width * height >= 2;
}
}

View File

@@ -0,0 +1,385 @@
package net.minecraft.item.crafting;
import javax.annotation.Nullable;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemBanner;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.BannerPattern;
import net.minecraft.tileentity.TileEntityBanner;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class RecipesBanners
{
public static class RecipeAddPattern extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
boolean flag = false;
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (itemstack.getItem() == Items.BANNER)
{
if (flag)
{
return false;
}
if (TileEntityBanner.getPatterns(itemstack) >= 6)
{
return false;
}
flag = true;
}
}
if (!flag)
{
return false;
}
else
{
return this.matchPatterns(inv) != null;
}
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
ItemStack itemstack = ItemStack.EMPTY;
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack1 = inv.getStackInSlot(i);
if (!itemstack1.isEmpty() && itemstack1.getItem() == Items.BANNER)
{
itemstack = itemstack1.copy();
itemstack.setCount(1);
break;
}
}
BannerPattern bannerpattern = this.matchPatterns(inv);
if (bannerpattern != null)
{
int k = 0;
for (int j = 0; j < inv.getSizeInventory(); ++j)
{
ItemStack itemstack2 = inv.getStackInSlot(j);
int color = net.minecraftforge.oredict.DyeUtils.rawDyeDamageFromStack(itemstack2);
if (color != -1)
{
k = color;
break;
}
}
NBTTagCompound nbttagcompound1 = itemstack.getOrCreateSubCompound("BlockEntityTag");
NBTTagList nbttaglist;
if (nbttagcompound1.hasKey("Patterns", 9))
{
nbttaglist = nbttagcompound1.getTagList("Patterns", 10);
}
else
{
nbttaglist = new NBTTagList();
nbttagcompound1.setTag("Patterns", nbttaglist);
}
NBTTagCompound nbttagcompound = new NBTTagCompound();
nbttagcompound.setString("Pattern", bannerpattern.getHashname());
nbttagcompound.setInteger("Color", k);
nbttaglist.appendTag(nbttagcompound);
}
return itemstack;
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
}
return nonnulllist;
}
@Nullable
private BannerPattern matchPatterns(InventoryCrafting p_190933_1_)
{
for (BannerPattern bannerpattern : BannerPattern.values())
{
if (bannerpattern.hasPattern())
{
boolean flag = true;
if (bannerpattern.hasPatternItem())
{
boolean flag1 = false;
boolean flag2 = false;
for (int i = 0; i < p_190933_1_.getSizeInventory() && flag; ++i)
{
ItemStack itemstack = p_190933_1_.getStackInSlot(i);
if (!itemstack.isEmpty() && itemstack.getItem() != Items.BANNER)
{
if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack))
{
if (flag2)
{
flag = false;
break;
}
flag2 = true;
}
else
{
if (flag1 || !itemstack.isItemEqual(bannerpattern.getPatternItem()))
{
flag = false;
break;
}
flag1 = true;
}
}
}
if (!flag1 || !flag2)
{
flag = false;
}
}
else if (p_190933_1_.getSizeInventory() == bannerpattern.getPatterns().length * bannerpattern.getPatterns()[0].length())
{
int j = -1;
for (int k = 0; k < p_190933_1_.getSizeInventory() && flag; ++k)
{
int l = k / 3;
int i1 = k % 3;
ItemStack itemstack1 = p_190933_1_.getStackInSlot(k);
if (!itemstack1.isEmpty() && itemstack1.getItem() != Items.BANNER)
{
if (!net.minecraftforge.oredict.DyeUtils.isDye(itemstack1))
{
flag = false;
break;
}
if (j != -1 && j != itemstack1.getMetadata())
{
flag = false;
break;
}
if (bannerpattern.getPatterns()[l].charAt(i1) == ' ')
{
flag = false;
break;
}
j = itemstack1.getMetadata();
}
else if (bannerpattern.getPatterns()[l].charAt(i1) != ' ')
{
flag = false;
break;
}
}
}
else
{
flag = false;
}
if (flag)
{
return bannerpattern;
}
}
}
return null;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width >= 3 && height >= 3;
}
}
public static class RecipeDuplicatePattern extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
ItemStack itemstack = ItemStack.EMPTY;
ItemStack itemstack1 = ItemStack.EMPTY;
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack2 = inv.getStackInSlot(i);
if (!itemstack2.isEmpty())
{
if (itemstack2.getItem() != Items.BANNER)
{
return false;
}
if (!itemstack.isEmpty() && !itemstack1.isEmpty())
{
return false;
}
EnumDyeColor enumdyecolor = ItemBanner.getBaseColor(itemstack2);
boolean flag = TileEntityBanner.getPatterns(itemstack2) > 0;
if (!itemstack.isEmpty())
{
if (flag)
{
return false;
}
if (enumdyecolor != ItemBanner.getBaseColor(itemstack))
{
return false;
}
itemstack1 = itemstack2;
}
else if (!itemstack1.isEmpty())
{
if (!flag)
{
return false;
}
if (enumdyecolor != ItemBanner.getBaseColor(itemstack1))
{
return false;
}
itemstack = itemstack2;
}
else if (flag)
{
itemstack = itemstack2;
}
else
{
itemstack1 = itemstack2;
}
}
}
return !itemstack.isEmpty() && !itemstack1.isEmpty();
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty() && TileEntityBanner.getPatterns(itemstack) > 0)
{
ItemStack itemstack1 = itemstack.copy();
itemstack1.setCount(1);
return itemstack1;
}
}
return ItemStack.EMPTY;
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty())
{
if (itemstack.getItem().hasContainerItem(itemstack))
{
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
}
else if (itemstack.hasTagCompound() && TileEntityBanner.getPatterns(itemstack) > 0)
{
ItemStack itemstack1 = itemstack.copy();
itemstack1.setCount(1);
nonnulllist.set(i, itemstack1);
}
}
}
return nonnulllist;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width * height >= 2;
}
}
}

View File

@@ -0,0 +1,136 @@
package net.minecraft.item.crafting;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class RecipesMapCloning extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
int i = 0;
ItemStack itemstack = ItemStack.EMPTY;
for (int j = 0; j < inv.getSizeInventory(); ++j)
{
ItemStack itemstack1 = inv.getStackInSlot(j);
if (!itemstack1.isEmpty())
{
if (itemstack1.getItem() == Items.FILLED_MAP)
{
if (!itemstack.isEmpty())
{
return false;
}
itemstack = itemstack1;
}
else
{
if (itemstack1.getItem() != Items.MAP)
{
return false;
}
++i;
}
}
}
return !itemstack.isEmpty() && i > 0;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
int i = 0;
ItemStack itemstack = ItemStack.EMPTY;
for (int j = 0; j < inv.getSizeInventory(); ++j)
{
ItemStack itemstack1 = inv.getStackInSlot(j);
if (!itemstack1.isEmpty())
{
if (itemstack1.getItem() == Items.FILLED_MAP)
{
if (!itemstack.isEmpty())
{
return ItemStack.EMPTY;
}
itemstack = itemstack1;
}
else
{
if (itemstack1.getItem() != Items.MAP)
{
return ItemStack.EMPTY;
}
++i;
}
}
}
if (!itemstack.isEmpty() && i >= 1)
{
ItemStack itemstack2 = new ItemStack(Items.FILLED_MAP, i + 1, itemstack.getMetadata());
if (itemstack.hasDisplayName())
{
itemstack2.setStackDisplayName(itemstack.getDisplayName());
}
if (itemstack.hasTagCompound())
{
itemstack2.setTagCompound(itemstack.getTagCompound());
}
return itemstack2;
}
else
{
return ItemStack.EMPTY;
}
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
}
return nonnulllist;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width >= 3 && height >= 3;
}
}

View File

@@ -0,0 +1,115 @@
package net.minecraft.item.crafting;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraft.world.storage.MapData;
import net.minecraft.world.storage.MapDecoration;
public class RecipesMapExtending extends ShapedRecipes
{
public RecipesMapExtending()
{
super("", 3, 3, NonNullList.from(Ingredient.EMPTY, Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItem(Items.FILLED_MAP), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER), Ingredient.fromItems(Items.PAPER)), new ItemStack(Items.MAP));
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
if (!super.matches(inv, worldIn))
{
return false;
}
else
{
ItemStack itemstack = ItemStack.EMPTY;
for (int i = 0; i < inv.getSizeInventory() && itemstack.isEmpty(); ++i)
{
ItemStack itemstack1 = inv.getStackInSlot(i);
if (itemstack1.getItem() == Items.FILLED_MAP)
{
itemstack = itemstack1;
}
}
if (itemstack.isEmpty())
{
return false;
}
else
{
MapData mapdata = Items.FILLED_MAP.getMapData(itemstack, worldIn);
if (mapdata == null)
{
return false;
}
else if (this.isExplorationMap(mapdata))
{
return false;
}
else
{
return mapdata.scale < 4;
}
}
}
}
private boolean isExplorationMap(MapData p_190934_1_)
{
if (p_190934_1_.mapDecorations != null)
{
for (MapDecoration mapdecoration : p_190934_1_.mapDecorations.values())
{
if (mapdecoration.getType() == MapDecoration.Type.MANSION || mapdecoration.getType() == MapDecoration.Type.MONUMENT)
{
return true;
}
}
}
return false;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
ItemStack itemstack = ItemStack.EMPTY;
for (int i = 0; i < inv.getSizeInventory() && itemstack.isEmpty(); ++i)
{
ItemStack itemstack1 = inv.getStackInSlot(i);
if (itemstack1.getItem() == Items.FILLED_MAP)
{
itemstack = itemstack1;
}
}
itemstack = itemstack.copy();
itemstack.setCount(1);
if (itemstack.getTagCompound() == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
itemstack.getTagCompound().setInteger("map_scale_direction", 1);
return itemstack;
}
public boolean isDynamic()
{
return true;
}
}

View File

@@ -0,0 +1,403 @@
package net.minecraft.item.crafting;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSyntaxException;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nullable;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public class ShapedRecipes extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements net.minecraftforge.common.crafting.IShapedRecipe
{
/** How many horizontal slots this recipe is wide. */
public final int recipeWidth;
/** How many vertical slots this recipe uses. */
public final int recipeHeight;
/** Is a array of ItemStack that composes the recipe. */
public final NonNullList<Ingredient> recipeItems;
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
private final String group;
public ShapedRecipes(String group, int width, int height, NonNullList<Ingredient> ingredients, ItemStack result)
{
this.group = group;
this.recipeWidth = width;
this.recipeHeight = height;
this.recipeItems = ingredients;
this.recipeOutput = result;
}
public String getGroup()
{
return this.group;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
}
return nonnulllist;
}
public NonNullList<Ingredient> getIngredients()
{
return this.recipeItems;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width >= this.recipeWidth && height >= this.recipeHeight;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
for (int i = 0; i <= inv.getWidth() - this.recipeWidth; ++i)
{
for (int j = 0; j <= inv.getHeight() - this.recipeHeight; ++j)
{
if (this.checkMatch(inv, i, j, true))
{
return true;
}
if (this.checkMatch(inv, i, j, false))
{
return true;
}
}
}
return false;
}
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting p_77573_1_, int p_77573_2_, int p_77573_3_, boolean p_77573_4_)
{
for (int i = 0; i < p_77573_1_.getWidth(); ++i)
{
for (int j = 0; j < p_77573_1_.getHeight(); ++j)
{
int k = i - p_77573_2_;
int l = j - p_77573_3_;
Ingredient ingredient = Ingredient.EMPTY;
if (k >= 0 && l >= 0 && k < this.recipeWidth && l < this.recipeHeight)
{
if (p_77573_4_)
{
ingredient = this.recipeItems.get(this.recipeWidth - k - 1 + l * this.recipeWidth);
}
else
{
ingredient = this.recipeItems.get(k + l * this.recipeWidth);
}
}
if (!ingredient.apply(p_77573_1_.getStackInRowAndColumn(i, j)))
{
return false;
}
}
}
return true;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
return this.getRecipeOutput().copy();
}
public int getWidth()
{
return this.recipeWidth;
}
public int getHeight()
{
return this.recipeHeight;
}
public static ShapedRecipes deserialize(JsonObject p_193362_0_)
{
String s = JsonUtils.getString(p_193362_0_, "group", "");
Map<String, Ingredient> map = deserializeKey(JsonUtils.getJsonObject(p_193362_0_, "key"));
String[] astring = shrink(patternFromJson(JsonUtils.getJsonArray(p_193362_0_, "pattern")));
int i = astring[0].length();
int j = astring.length;
NonNullList<Ingredient> nonnulllist = deserializeIngredients(astring, map, i, j);
ItemStack itemstack = deserializeItem(JsonUtils.getJsonObject(p_193362_0_, "result"), true);
return new ShapedRecipes(s, i, j, nonnulllist, itemstack);
}
private static NonNullList<Ingredient> deserializeIngredients(String[] p_192402_0_, Map<String, Ingredient> p_192402_1_, int p_192402_2_, int p_192402_3_)
{
NonNullList<Ingredient> nonnulllist = NonNullList.<Ingredient>withSize(p_192402_2_ * p_192402_3_, Ingredient.EMPTY);
Set<String> set = Sets.newHashSet(p_192402_1_.keySet());
set.remove(" ");
for (int i = 0; i < p_192402_0_.length; ++i)
{
for (int j = 0; j < p_192402_0_[i].length(); ++j)
{
String s = p_192402_0_[i].substring(j, j + 1);
Ingredient ingredient = p_192402_1_.get(s);
if (ingredient == null)
{
throw new JsonSyntaxException("Pattern references symbol '" + s + "' but it's not defined in the key");
}
set.remove(s);
nonnulllist.set(j + p_192402_2_ * i, ingredient);
}
}
if (!set.isEmpty())
{
throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + set);
}
else
{
return nonnulllist;
}
}
@VisibleForTesting
static String[] shrink(String... p_194134_0_)
{
int i = Integer.MAX_VALUE;
int j = 0;
int k = 0;
int l = 0;
for (int i1 = 0; i1 < p_194134_0_.length; ++i1)
{
String s = p_194134_0_[i1];
i = Math.min(i, firstNonSpace(s));
int j1 = lastNonSpace(s);
j = Math.max(j, j1);
if (j1 < 0)
{
if (k == i1)
{
++k;
}
++l;
}
else
{
l = 0;
}
}
if (p_194134_0_.length == l)
{
return new String[0];
}
else
{
String[] astring = new String[p_194134_0_.length - l - k];
for (int k1 = 0; k1 < astring.length; ++k1)
{
astring[k1] = p_194134_0_[k1 + k].substring(i, j + 1);
}
return astring;
}
}
private static int firstNonSpace(String str)
{
int i;
for (i = 0; i < str.length() && str.charAt(i) == ' '; ++i)
{
;
}
return i;
}
private static int lastNonSpace(String str)
{
int i;
for (i = str.length() - 1; i >= 0 && str.charAt(i) == ' '; --i)
{
;
}
return i;
}
private static String[] patternFromJson(JsonArray p_192407_0_)
{
String[] astring = new String[p_192407_0_.size()];
if (astring.length > 3)
{
throw new JsonSyntaxException("Invalid pattern: too many rows, 3 is maximum");
}
else if (astring.length == 0)
{
throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
}
else
{
for (int i = 0; i < astring.length; ++i)
{
String s = JsonUtils.getString(p_192407_0_.get(i), "pattern[" + i + "]");
if (s.length() > 3)
{
throw new JsonSyntaxException("Invalid pattern: too many columns, 3 is maximum");
}
if (i > 0 && astring[0].length() != s.length())
{
throw new JsonSyntaxException("Invalid pattern: each row must be the same width");
}
astring[i] = s;
}
return astring;
}
}
private static Map<String, Ingredient> deserializeKey(JsonObject p_192408_0_)
{
Map<String, Ingredient> map = Maps.<String, Ingredient>newHashMap();
for (Entry<String, JsonElement> entry : p_192408_0_.entrySet())
{
if (((String)entry.getKey()).length() != 1)
{
throw new JsonSyntaxException("Invalid key entry: '" + (String)entry.getKey() + "' is an invalid symbol (must be 1 character only).");
}
if (" ".equals(entry.getKey()))
{
throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");
}
map.put(entry.getKey(), deserializeIngredient(entry.getValue()));
}
map.put(" ", Ingredient.EMPTY);
return map;
}
public static Ingredient deserializeIngredient(@Nullable JsonElement p_193361_0_)
{
if (p_193361_0_ != null && !p_193361_0_.isJsonNull())
{
if (p_193361_0_.isJsonObject())
{
return Ingredient.fromStacks(deserializeItem(p_193361_0_.getAsJsonObject(), false));
}
else if (!p_193361_0_.isJsonArray())
{
throw new JsonSyntaxException("Expected item to be object or array of objects");
}
else
{
JsonArray jsonarray = p_193361_0_.getAsJsonArray();
if (jsonarray.size() == 0)
{
throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
}
else
{
ItemStack[] aitemstack = new ItemStack[jsonarray.size()];
for (int i = 0; i < jsonarray.size(); ++i)
{
aitemstack[i] = deserializeItem(JsonUtils.getJsonObject(jsonarray.get(i), "item"), false);
}
return Ingredient.fromStacks(aitemstack);
}
}
}
else
{
throw new JsonSyntaxException("Item cannot be null");
}
}
public static ItemStack deserializeItem(JsonObject p_192405_0_, boolean useCount)
{
String s = JsonUtils.getString(p_192405_0_, "item");
Item item = Item.REGISTRY.getObject(new ResourceLocation(s));
if (item == null)
{
throw new JsonSyntaxException("Unknown item '" + s + "'");
}
else if (item.getHasSubtypes() && !p_192405_0_.has("data"))
{
throw new JsonParseException("Missing data for item '" + s + "'");
}
else
{
int i = JsonUtils.getInt(p_192405_0_, "data", 0);
int j = useCount ? JsonUtils.getInt(p_192405_0_, "count", 1) : 1;
return new ItemStack(item, j, i);
}
}
//================================================ FORGE START ================================================
@Override
public int getRecipeWidth()
{
return this.getWidth();
}
@Override
public int getRecipeHeight()
{
return this.getHeight();
}
}

View File

@@ -0,0 +1,150 @@
package net.minecraft.item.crafting;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class ShapelessRecipes extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
/** Is a List of ItemStack that composes the recipe. */
public final NonNullList<Ingredient> recipeItems;
private final String group;
private final boolean isSimple;
public ShapelessRecipes(String group, ItemStack output, NonNullList<Ingredient> ingredients)
{
this.group = group;
this.recipeOutput = output;
this.recipeItems = ingredients;
boolean simple = true;
for (Ingredient i : ingredients)
simple &= i.isSimple();
this.isSimple = simple;
}
public String getGroup()
{
return this.group;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
public NonNullList<Ingredient> getIngredients()
{
return this.recipeItems;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
}
return nonnulllist;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
int ingredientCount = 0;
net.minecraft.client.util.RecipeItemHelper recipeItemHelper = new net.minecraft.client.util.RecipeItemHelper();
List<ItemStack> inputs = Lists.newArrayList();
for (int i = 0; i < inv.getHeight(); ++i)
{
for (int j = 0; j < inv.getWidth(); ++j)
{
ItemStack itemstack = inv.getStackInRowAndColumn(j, i);
if (!itemstack.isEmpty())
{
++ingredientCount;
if (this.isSimple)
recipeItemHelper.accountStack(itemstack, 1);
else
inputs.add(itemstack);
}
}
}
if (ingredientCount != this.recipeItems.size())
return false;
if (this.isSimple)
return recipeItemHelper.canCraft(this, null);
return net.minecraftforge.common.util.RecipeMatcher.findMatches(inputs, this.recipeItems) != null;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
return this.recipeOutput.copy();
}
public static ShapelessRecipes deserialize(JsonObject json)
{
String s = JsonUtils.getString(json, "group", "");
NonNullList<Ingredient> nonnulllist = deserializeIngredients(JsonUtils.getJsonArray(json, "ingredients"));
if (nonnulllist.isEmpty())
{
throw new JsonParseException("No ingredients for shapeless recipe");
}
else if (nonnulllist.size() > 9)
{
throw new JsonParseException("Too many ingredients for shapeless recipe");
}
else
{
ItemStack itemstack = ShapedRecipes.deserializeItem(JsonUtils.getJsonObject(json, "result"), true);
return new ShapelessRecipes(s, itemstack, nonnulllist);
}
}
private static NonNullList<Ingredient> deserializeIngredients(JsonArray array)
{
NonNullList<Ingredient> nonnulllist = NonNullList.<Ingredient>create();
for (int i = 0; i < array.size(); ++i)
{
Ingredient ingredient = ShapedRecipes.deserializeIngredient(array.get(i));
if (ingredient != Ingredient.EMPTY)
{
nonnulllist.add(ingredient);
}
}
return nonnulllist;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width * height >= this.recipeItems.size();
}
}

View File

@@ -0,0 +1,143 @@
package net.minecraft.item.crafting;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class ShieldRecipes
{
public static class Decoration extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
ItemStack itemstack = ItemStack.EMPTY;
ItemStack itemstack1 = ItemStack.EMPTY;
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack2 = inv.getStackInSlot(i);
if (!itemstack2.isEmpty())
{
if (itemstack2.getItem() == Items.BANNER)
{
if (!itemstack1.isEmpty())
{
return false;
}
itemstack1 = itemstack2;
}
else
{
if (itemstack2.getItem() != Items.SHIELD)
{
return false;
}
if (!itemstack.isEmpty())
{
return false;
}
if (itemstack2.getSubCompound("BlockEntityTag") != null)
{
return false;
}
itemstack = itemstack2;
}
}
}
if (!itemstack.isEmpty() && !itemstack1.isEmpty())
{
return true;
}
else
{
return false;
}
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
ItemStack itemstack = ItemStack.EMPTY;
ItemStack itemstack1 = ItemStack.EMPTY;
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack2 = inv.getStackInSlot(i);
if (!itemstack2.isEmpty())
{
if (itemstack2.getItem() == Items.BANNER)
{
itemstack = itemstack2;
}
else if (itemstack2.getItem() == Items.SHIELD)
{
itemstack1 = itemstack2.copy();
}
}
}
if (itemstack1.isEmpty())
{
return itemstack1;
}
else
{
NBTTagCompound nbttagcompound = itemstack.getSubCompound("BlockEntityTag");
NBTTagCompound nbttagcompound1 = nbttagcompound == null ? new NBTTagCompound() : nbttagcompound.copy();
nbttagcompound1.setInteger("Base", itemstack.getMetadata() & 15);
itemstack1.setTagInfo("BlockEntityTag", nbttagcompound1);
return itemstack1;
}
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (itemstack.getItem().hasContainerItem())
{
nonnulllist.set(i, new ItemStack(itemstack.getItem().getContainerItem()));
}
}
return nonnulllist;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width * height >= 2;
}
}
}

View File

@@ -0,0 +1,124 @@
package net.minecraft.item.crafting;
import net.minecraft.block.Block;
import net.minecraft.block.BlockShulkerBox;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
public class ShulkerBoxRecipes
{
public static class ShulkerBoxColoring extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting inv, World worldIn)
{
int i = 0;
int j = 0;
for (int k = 0; k < inv.getSizeInventory(); ++k)
{
ItemStack itemstack = inv.getStackInSlot(k);
if (!itemstack.isEmpty())
{
if (Block.getBlockFromItem(itemstack.getItem()) instanceof BlockShulkerBox)
{
++i;
}
else
{
if (!net.minecraftforge.oredict.DyeUtils.isDye(itemstack))
{
return false;
}
++j;
}
if (j > 1 || i > 1)
{
return false;
}
}
}
return i == 1 && j == 1;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting inv)
{
ItemStack itemstack = ItemStack.EMPTY;
ItemStack itemstack1 = ItemStack.EMPTY;
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack2 = inv.getStackInSlot(i);
if (!itemstack2.isEmpty())
{
if (Block.getBlockFromItem(itemstack2.getItem()) instanceof BlockShulkerBox)
{
itemstack = itemstack2;
}
else if (net.minecraftforge.oredict.DyeUtils.isDye(itemstack2))
{
itemstack1 = itemstack2;
}
}
}
ItemStack itemstack3 = BlockShulkerBox.getColoredItemStack(net.minecraftforge.oredict.DyeUtils.colorFromStack(itemstack1).get());
if (itemstack.hasTagCompound())
{
itemstack3.setTagCompound(itemstack.getTagCompound().copy());
}
return itemstack3;
}
public ItemStack getRecipeOutput()
{
return ItemStack.EMPTY;
}
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (itemstack.getItem().hasContainerItem())
{
nonnulllist.set(i, new ItemStack(itemstack.getItem().getContainerItem()));
}
}
return nonnulllist;
}
public boolean isDynamic()
{
return true;
}
/**
* Used to determine if this recipe can fit in a grid of the given width/height
*/
public boolean canFit(int width, int height)
{
return width * height >= 2;
}
}
}

View File

@@ -0,0 +1,7 @@
// Auto generated package-info by MCP
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package net.minecraft.item.crafting;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;