Recipe work. No longer a registry. OreDictionary related code removed in favor of Tags. Started moving some OreDict items to tags.

Added code to RuntimeEnumExtender to return existing enum values with the same name if they exist instead of creating more.
This commit is contained in:
LexManos committed 2018-09-16 04:20:28 -07:00
1 parent e3a931bf96
commit c77d00efe4
49 files changed
+893 -786

No files matched your search

@@ -22,8 +22,7 @@ package net.minecraftforge.common;
import net.minecraft.block.state.IBlockState;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraft.world.IWorldReader;
public enum EnumPlantType
{
@@ -38,22 +37,15 @@ public enum EnumPlantType
/**
* Getting a custom {@link EnumPlantType}, or an existing one if it has the same name as that one. Your plant should implement {@link IPlantable}
* and return this custom type in {@link IPlantable#getPlantType(IBlockAccess, BlockPos)}.
*
* <p>If your new plant grows on blocks like any one of them above, never create a new {@link EnumPlantType}.
* This enumeration is only functioning in
* {@link net.minecraft.block.Block#canSustainPlant(IBlockState, IBlockAccess, BlockPos, EnumFacing, IPlantable)},
*
* <p>If your new plant grows on blocks like any one of them above, never create a new {@link EnumPlantType}.
* This enumeration is only functioning in
* {@link net.minecraft.block.Block#canSustainPlant(IBlockState, IWorldReader, BlockPos, EnumFacing, IPlantable)},
* which you are supposed to override this function in your new block and create a new plant type to grow on that block.
*
*
* <p>You can create an instance of your plant type in your API and let your/others mods access it. It will be faster than calling this method.
* @param name the name of the type of plant, you had better follow the style above
* @return the acquired {@link EnumPlantType}, a new one if not found.
*/
public static EnumPlantType getPlantType(String name)
{
for (EnumPlantType t : values())
{
if (t.name().equalsIgnoreCase(name)) return t;
}
return EnumHelper.addEnum(EnumPlantType.class, name, new Class[0], new Object[0]);
}
public static EnumPlantType create(String name, int test, long bar, String foo){ return null; }
}
@@ -91,6 +91,8 @@ import net.minecraft.network.play.server.SPacketRecipeBook.State;
import net.minecraft.potion.PotionType;
import net.minecraft.potion.PotionUtils;
import net.minecraft.stats.StatList;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityNote;
import net.minecraft.util.DamageSource;
@@ -870,9 +872,9 @@ public class ForgeHooks
public static EnumActionResult onPlaceItemIntoWorld(@Nonnull ItemUseContext context)
{
ItemStack itemstack = context.func_195996_i();
World world = context.func_195991_k();
ItemStack itemstack = context.func_195996_i();
World world = context.func_195991_k();
// handle all placement events here
int meta = itemstack.getItemDamage();
int size = itemstack.getCount();
@@ -912,10 +914,10 @@ public class ForgeHooks
{
itemstack.setTagCompound(nbt);
}
EntityPlayer player = context.func_195999_j();
EnumFacing side = context.func_196000_l();
if (blockSnapshots.size() > 1)
{
placeEvent = ForgeEventFactory.onPlayerMultiBlockPlace(player, blockSnapshots, side, hand);
@@ -997,23 +999,6 @@ public class ForgeHooks
return true;
}
/**
* Default implementation of IRecipe.func_179532_b {getRemainingItems} because
* this is just copy pasted over a lot of recipes.
*
* @param inv Crafting inventory
* @return Crafting inventory contents after the recipe.
*/
public static NonNullList<ItemStack> defaultRecipeGetRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> ret = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < ret.size(); i++)
{
ret.set(i, getContainerItem(inv.getStackInSlot(i)));
}
return ret;
}
private static ThreadLocal<EntityPlayer> craftingPlayer = new ThreadLocal<EntityPlayer>();
public static void setCraftingPlayer(EntityPlayer player)
{
@@ -1209,7 +1194,7 @@ public class ForgeHooks
{
this.name = name;
this.custom = custom;
this.vanilla = "minecraft".equals(this.name.getResourceDomain());
this.vanilla = "minecraft".equals(this.name.getNamespace());
}
private void resetPoolCtx()
@@ -1422,7 +1407,7 @@ public class ForgeHooks
{
Item item = itemStack.getItem();
ResourceLocation registryName = item.getRegistryName();
String modId = registryName == null ? null : registryName.getResourceDomain();
String modId = registryName == null ? null : registryName.getNamespace();
if ("minecraft".equals(modId))
{
if (item instanceof ItemEnchantedBook)
@@ -1437,7 +1422,7 @@ public class ForgeHooks
ResourceLocation resourceLocation = ForgeRegistries.ENCHANTMENTS.getKey(enchantment);
if (resourceLocation != null)
{
return resourceLocation.getResourceDomain();
return resourceLocation.getNamespace();
}
}
}
@@ -1448,7 +1433,7 @@ public class ForgeHooks
ResourceLocation resourceLocation = ForgeRegistries.POTION_TYPES.getKey(potionType);
if (resourceLocation != null)
{
return resourceLocation.getResourceDomain();
return resourceLocation.getNamespace();
}
}
else if (item instanceof ItemMonsterPlacer)
@@ -1456,7 +1441,7 @@ public class ForgeHooks
ResourceLocation resourceLocation = ItemMonsterPlacer.getNamedIdFrom(itemStack);
if (resourceLocation != null)
{
return resourceLocation.getResourceDomain();
return resourceLocation.getNamespace();
}
}
}
@@ -1474,5 +1459,4 @@ public class ForgeHooks
}
return false;
}
}
@@ -23,6 +23,7 @@ import java.nio.file.Path;
import net.minecraftforge.fml.AdvancedLogMessageAdapter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter;
@@ -40,10 +41,13 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
private static final Logger LOGGER = LogManager.getLogger();
private final Type STRING = Type.getType(String.class);
private final Type ENUM = Type.getType(Enum.class);
private final Type ARRAY_UTILS = Type.getType("Lorg/apache/commons/lang3/ArrayUtils;"); //Don't directly reference this to prevent class loading.
private final String ADD_DESC = Type.getMethodDescriptor(Type.getType(Object[].class), Type.getType(Object[].class), Type.getType(Object.class));
private final Type ENUM_HELPER = Type.getType("Lnet/minecraftforge/common/util/EnumHelper;"); //Again, not direct reference to prevent class loading.
private final String CLEAN_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Class.class));
private final String NAME_DESC = Type.getMethodDescriptor(STRING);
private final String EQUALS_DESC = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, STRING);
@Override
public String name() {
@@ -110,30 +114,76 @@ public class RuntimeEnumExtender implements ILaunchPluginService {
mtd.instructions.clear();
InstructionAdapter ins = new InstructionAdapter(mtd);
//ret = new ThisType(name, VALUES.length + 1, args..)
ins.anew(classType);
ins.dup();
ins.load(0, STRING);
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.arraylength();
ins.iconst(1);
ins.add(Type.INT_TYPE);
for (int x = 1; x < args.length; x++)
ins.load(x, args[x]);
ins.invokespecial(classType.getInternalName(), "<init>", desc, false);
ins.store(1, classType);
// VALUES = ArrayUtils.add(VALUES, ret)
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.load(1, classType);
ins.invokestatic(ARRAY_UTILS.getInternalName(), "add", ADD_DESC, false);
ins.checkcast(Type.getType(values.desc));
ins.putstatic(classType.getInternalName(), values.name, values.desc);
//EnumHelper.cleanEnumCache(ThisType.class)
ins.visitLdcInsn(classType);
ins.invokestatic(ENUM_HELPER.getInternalName(), "cleanEnumCache", CLEAN_DESC, false);
//return ret
ins.load(1, classType);
ins.areturn(classType);
int vars = 0;
for (Type arg : args)
vars += arg.getSize();
{
vars += 1; //int x
Label for_start = new Label();
Label for_condition = new Label();
Label for_inc = new Label();
ins.iconst(0);
ins.store(vars, Type.INT_TYPE);
ins.goTo(for_condition);
//if (!VALUES[x].name().equalsIgnoreCase(name)) goto for_inc
ins.mark(for_start);
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.load(vars, Type.INT_TYPE);
ins.aload(array);
ins.invokevirtual(ENUM.getInternalName(), "name", NAME_DESC, false);
ins.load(0, STRING);
ins.invokevirtual(STRING.getInternalName(), "equalsIgnoreCase", EQUALS_DESC, false);
ins.ifeq(for_inc);
//return VALUES[x];
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.load(vars, Type.INT_TYPE);
ins.aload(array);
ins.areturn(classType);
//x++
ins.mark(for_inc);
ins.iinc(vars, 1);
//if (x < VALUES.length) goto for_start
ins.mark(for_condition);
ins.load(vars, Type.INT_TYPE);
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.arraylength();
ins.ificmplt(for_start);
}
{
vars += 1; //enum ret;
//ret = new ThisType(name, VALUES.length + 1, args..)
ins.anew(classType);
ins.dup();
ins.load(0, STRING);
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.arraylength();
ins.iconst(1);
ins.add(Type.INT_TYPE);
int idx = 1;
for (int x = 1; x < args.length; x++)
{
ins.load(idx, args[x]);
idx += args[x].getSize();
}
ins.invokespecial(classType.getInternalName(), "<init>", desc, false);
ins.store(vars, classType);
// VALUES = ArrayUtils.add(VALUES, ret)
ins.getstatic(classType.getInternalName(), values.name, values.desc);
ins.load(vars, classType);
ins.invokestatic(ARRAY_UTILS.getInternalName(), "add", ADD_DESC, false);
ins.checkcast(array);
ins.putstatic(classType.getInternalName(), values.name, values.desc);
//EnumHelper.cleanEnumCache(ThisType.class)
ins.visitLdcInsn(classType);
ins.invokestatic(ENUM_HELPER.getInternalName(), "cleanEnumCache", CLEAN_DESC, false);
//return ret
ins.load(vars, classType);
ins.areturn(classType);
}
});
return classNode;
}
@@ -23,8 +23,7 @@ import java.util.BitSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import com.google.common.base.Predicate;
import java.util.function.Predicate;
public class RecipeMatcher
{
@@ -61,7 +60,7 @@ public class RecipeMatcher
if (data.get(y))
continue;
if (test.apply(inputs.get(y)))
if (test.test(inputs.get(y)))
{
data.set(offset + y);
matched++;
@@ -1,126 +0,0 @@
/*
* 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.oredict;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.apache.commons.lang3.ArrayUtils;
import java.util.Arrays;
import java.util.Optional;
import java.util.OptionalInt;
/**
* Utility class for working with ore dictionary dyes.
*/
public class DyeUtils
{
/*
private static final String[] dyeOredicts = new String[]
{
"dyeWhite",
"dyeOrange",
"dyeMagenta",
"dyeLightBlue",
"dyeYellow",
"dyeLime",
"dyePink",
"dyeGray",
"dyeLightGray",
"dyeCyan",
"dyePurple",
"dyeBlue",
"dyeBrown",
"dyeGreen",
"dyeRed",
"dyeBlack"
};
/**
* Check if an item stack is a dye.
* @param stack the item stack
* @return whether the stack is a dye
* /
public static boolean isDye(ItemStack stack)
{
return metaFromStack(stack).isPresent();
}
/**
* Get the dye metadata from the stack, which can be passed into {@link EnumDyeColor#byMetadata(int)}.
* @param stack the item stack
* @return an {@link OptionalInt} holding the dye metadata for a dye, or an empty {@link OptionalInt} otherwise
* /
public static OptionalInt metaFromStack(ItemStack stack)
{
if (stack.isEmpty()) return OptionalInt.empty();
return Arrays.stream(OreDictionary.getOreIDs(stack))
.mapToObj(OreDictionary::getOreName)
.mapToInt(name -> ArrayUtils.indexOf(dyeOredicts, name))
.filter(id -> id >= 0)
.findFirst();
}
/**
* Similar to {@link #metaFromStack(ItemStack)}, except that it returns the raw integer (with a {@code -1} sentinel);
* this follows vanilla conventions.
* @param stack the item stack
* @return the dye metadata for a dye, or {@code -1} otherwise
* /
public static int rawMetaFromStack(ItemStack stack)
{
return metaFromStack(stack).orElse(-1);
}
/**
* Get the dye damage from the stack, which can be passed into {@link EnumDyeColor#byDyeDamage(int)}.
* @param stack the item stack
* @return an {@link OptionalInt} holding the dye damage for a dye, or an empty {@link OptionalInt} otherwise
* /
public static OptionalInt dyeDamageFromStack(ItemStack stack)
{
final OptionalInt meta = metaFromStack(stack);
return meta.isPresent() ? OptionalInt.of(0xF - meta.getAsInt()) : OptionalInt.empty();
}
/**
* Similar to {@link #dyeDamageFromStack(ItemStack)}, except that it returns the raw integer (with a {@code -1} sentinel);
* this follows vanilla conventions.
* @param stack the item stack
* @return the dye damage for a dye, or {@code -1} otherwise
* /
public static int rawDyeDamageFromStack(ItemStack stack)
{
return dyeDamageFromStack(stack).orElse(-1);
}
/**
* Get a dye's color.
* @param stack the item stack
* @return an {@link Optional} holding the dye color if present, or an empty {@link Optional} otherwise
* /
public static Optional<EnumDyeColor> colorFromStack(ItemStack stack)
{
final OptionalInt meta = metaFromStack(stack);
return meta.isPresent() ? Optional.of(EnumDyeColor.byMetadata(meta.getAsInt())) : Optional.empty();
}
*/
}
@@ -174,20 +174,6 @@ public class OreDictionary
registerOre("feather", Items.FEATHER);
registerOre("egg", Items.EGG);
// records
registerOre("record", Items.RECORD_13);
registerOre("record", Items.RECORD_CAT);
registerOre("record", Items.RECORD_BLOCKS);
registerOre("record", Items.RECORD_CHIRP);
registerOre("record", Items.RECORD_FAR);
registerOre("record", Items.RECORD_MALL);
registerOre("record", Items.RECORD_MELLOHI);
registerOre("record", Items.RECORD_STAL);
registerOre("record", Items.RECORD_STRAD);
registerOre("record", Items.RECORD_WARD);
registerOre("record", Items.RECORD_11);
registerOre("record", Items.RECORD_WAIT);
// blocks
registerOre("dirt", Blocks.DIRT);
registerOre("grass", Blocks.GRASS);
@@ -1,126 +0,0 @@
/*
* 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.oredict;
/*
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntComparators;
import it.unimi.dsi.fastutil.ints.IntList;
import net.minecraft.client.util.RecipeItemHelper;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
*/
public class OreIngredient //extends Ingredient
{
/*
private NonNullList<ItemStack> ores;
private IntList itemIds = null;
private ItemStack[] array = null;
private int lastSizeA = -1, lastSizeL = -1;
public OreIngredient(String ore)
{
super(0);
ores = OreDictionary.getOres(ore);
}
@Override
@Nonnull
public ItemStack[] getMatchingStacks()
{
if (array == null || this.lastSizeA != ores.size())
{
NonNullList<ItemStack> lst = NonNullList.create();
for (ItemStack itemstack : this.ores)
{
if (itemstack.getMetadata() == OreDictionary.WILDCARD_VALUE)
itemstack.getItem().getSubItems(CreativeTabs.SEARCH, lst);
else
lst.add(itemstack);
}
this.array = lst.toArray(new ItemStack[lst.size()]);
this.lastSizeA = ores.size();
}
return this.array;
}
@Override
@Nonnull
public IntList getValidItemStacksPacked()
{
if (this.itemIds == null || this.lastSizeL != ores.size())
{
this.itemIds = new IntArrayList(this.ores.size());
for (ItemStack itemstack : this.ores)
{
if (itemstack.getMetadata() == OreDictionary.WILDCARD_VALUE)
{
NonNullList<ItemStack> lst = NonNullList.create();
itemstack.getItem().getSubItems(CreativeTabs.SEARCH, lst);
for (ItemStack item : lst)
this.itemIds.add(RecipeItemHelper.pack(item));
}
else
{
this.itemIds.add(RecipeItemHelper.pack(itemstack));
}
}
this.itemIds.sort(IntComparators.NATURAL_COMPARATOR);
this.lastSizeL = ores.size();
}
return this.itemIds;
}
@Override
public boolean apply(@Nullable ItemStack input)
{
if (input == null)
return false;
for (ItemStack target : this.ores)
if (OreDictionary.itemMatches(target, input, false))
return true;
return false;
}
@Override
protected void invalidate()
{
this.itemIds = null;
this.array = null;
}
@Override
public boolean isSimple()
{
return true;
}
*/
}
@@ -1,259 +0,0 @@
/*
* 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.oredict;
import net.minecraft.block.Block;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
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;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer;
import net.minecraftforge.common.crafting.IShapedRecipe;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.common.crafting.JsonContext;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
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.JsonSyntaxException;
public class ShapedOreRecipe //extends IForgeRegistryEntry.Impl<IRecipe> implements IShapedRecipe
{
/*
@Deprecated
public static final int MAX_CRAFT_GRID_WIDTH = 3;
@Deprecated
public static final int MAX_CRAFT_GRID_HEIGHT = 3;
@Nonnull
protected ItemStack output = ItemStack.EMPTY;
protected NonNullList<Ingredient> input = null;
protected int width = 0;
protected int height = 0;
protected boolean mirrored = true;
protected ResourceLocation group;
public ShapedOreRecipe(ResourceLocation group, Block result, Object... recipe){ this(group, new ItemStack(result), recipe); }
public ShapedOreRecipe(ResourceLocation group, Item result, Object... recipe){ this(group, new ItemStack(result), recipe); }
public ShapedOreRecipe(ResourceLocation group, @Nonnull ItemStack result, Object... recipe) { this(group, result, CraftingHelper.parseShaped(recipe)); }
public ShapedOreRecipe(ResourceLocation group, @Nonnull ItemStack result, ShapedPrimer primer)
{
this.group = group;
output = result.copy();
this.width = primer.width;
this.height = primer.height;
this.input = primer.input;
this.mirrored = primer.mirrored;
}
@Override
@Nonnull
public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1){ return output.copy(); }
@Override
@Nonnull
public ItemStack getRecipeOutput(){ return output; }
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World world)
{
for (int x = 0; x <= inv.getWidth() - width; x++)
{
for (int y = 0; y <= inv.getHeight() - height; ++y)
{
if (checkMatch(inv, x, y, false))
{
return true;
}
if (mirrored && checkMatch(inv, x, y, true))
{
return true;
}
}
}
return false;
}
/**
* Based on {@link net.minecraft.item.crafting.ShapedRecipes#checkMatch(InventoryCrafting, int, int, boolean)}
* /
protected boolean checkMatch(InventoryCrafting inv, int startX, int startY, boolean mirror)
{
for (int x = 0; x < inv.getWidth(); x++)
{
for (int y = 0; y < inv.getHeight(); y++)
{
int subX = x - startX;
int subY = y - startY;
Ingredient target = Ingredient.EMPTY;
if (subX >= 0 && subY >= 0 && subX < width && subY < height)
{
if (mirror)
{
target = input.get(width - subX - 1 + subY * width);
}
else
{
target = input.get(subX + subY * width);
}
}
if (!target.apply(inv.getStackInRowAndColumn(x, y)))
{
return false;
}
}
}
return true;
}
public ShapedOreRecipe setMirrored(boolean mirror)
{
mirrored = mirror;
return this;
}
@Override
@Nonnull
public NonNullList<Ingredient> getIngredients()
{
return this.input;
}
@Deprecated //Use IShapedRecipe.getRecipeWidth
public int getWidth()
{
return width;
}
@Override
public int getRecipeWidth()
{
return this.getWidth();
}
@Deprecated //Use IShapedRecipe.getRecipeHeight
public int getHeight()
{
return height;
}
@Override
public int getRecipeHeight()
{
return this.getHeight();
}
@Override
@Nonnull
public String getGroup()
{
return this.group == null ? "" : this.group.toString();
}
@Override
public boolean canFit(int p_194133_1_, int p_194133_2_)
{
return p_194133_1_ >= this.width && p_194133_2_ >= this.height;
}
public static ShapedOreRecipe factory(JsonContext context, JsonObject json)
{
String group = JsonUtils.getString(json, "group", "");
//if (!group.isEmpty() && group.indexOf(':') == -1)
// group = context.getModId() + ":" + group;
Map<Character, Ingredient> ingMap = Maps.newHashMap();
for (Entry<String, JsonElement> entry : JsonUtils.getJsonObject(json, "key").entrySet())
{
if (entry.getKey().length() != 1)
throw new JsonSyntaxException("Invalid key entry: '" + 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.");
ingMap.put(entry.getKey().toCharArray()[0], CraftingHelper.getIngredient(entry.getValue(), context));
}
ingMap.put(' ', Ingredient.EMPTY);
JsonArray patternJ = JsonUtils.getJsonArray(json, "pattern");
if (patternJ.size() == 0)
throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
String[] pattern = new String[patternJ.size()];
for (int x = 0; x < pattern.length; ++x)
{
String line = JsonUtils.getString(patternJ.get(x), "pattern[" + x + "]");
if (x > 0 && pattern[0].length() != line.length())
throw new JsonSyntaxException("Invalid pattern: each row must be the same width");
pattern[x] = line;
}
ShapedPrimer primer = new ShapedPrimer();
primer.width = pattern[0].length();
primer.height = pattern.length;
primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true);
primer.input = NonNullList.withSize(primer.width * primer.height, Ingredient.EMPTY);
Set<Character> keys = Sets.newHashSet(ingMap.keySet());
keys.remove(' ');
int x = 0;
for (String line : pattern)
{
for (char chr : line.toCharArray())
{
Ingredient ing = ingMap.get(chr);
if (ing == null)
throw new JsonSyntaxException("Pattern references symbol '" + chr + "' but it's not defined in the key");
primer.input.set(x++, ing);
keys.remove(chr);
}
}
if (!keys.isEmpty())
throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + keys);
ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
return new ShapedOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), result, primer);
}
*/
}
@@ -1,161 +0,0 @@
/*
* 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.oredict;
/*
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.util.RecipeItemHelper;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
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;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.common.util.RecipeMatcher;
import net.minecraftforge.registries.IForgeRegistryEntry;
import javax.annotation.Nonnull;
import com.google.common.collect.Lists;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
*/
public class ShapelessOreRecipe {} /*extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
@Nonnull
protected ItemStack output = ItemStack.EMPTY;
protected NonNullList<Ingredient> input = NonNullList.create();
protected ResourceLocation group;
protected boolean isSimple = true;
public ShapelessOreRecipe(ResourceLocation group, Block result, Object... recipe){ this(group, new ItemStack(result), recipe); }
public ShapelessOreRecipe(ResourceLocation group, Item result, Object... recipe){ this(group, new ItemStack(result), recipe); }
public ShapelessOreRecipe(ResourceLocation group, NonNullList<Ingredient> input, @Nonnull ItemStack result)
{
this.group = group;
output = result.copy();
this.input = input;
for (Ingredient i : input)
this.isSimple &= i.isSimple();
}
public ShapelessOreRecipe(ResourceLocation group, @Nonnull ItemStack result, Object... recipe)
{
this.group = group;
output = result.copy();
for (Object in : recipe)
{
Ingredient ing = CraftingHelper.getIngredient(in);
if (ing != null)
{
input.add(ing);
this.isSimple &= ing.isSimple();
}
else
{
String ret = "Invalid shapeless ore recipe: ";
for (Object tmp : recipe)
{
ret += tmp + ", ";
}
ret += output;
throw new RuntimeException(ret);
}
}
}
@Override
@Nonnull
public ItemStack getRecipeOutput(){ return output; }
@Override
@Nonnull
public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1){ return output.copy(); }
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World world)
{
int ingredientCount = 0;
RecipeItemHelper recipeItemHelper = new RecipeItemHelper();
List<ItemStack> items = Lists.newArrayList();
for (int i = 0; i < inv.getSizeInventory(); ++i)
{
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty())
{
++ingredientCount;
if (this.isSimple)
recipeItemHelper.accountStack(itemstack, 1);
else
items.add(itemstack);
}
}
if (ingredientCount != this.input.size())
return false;
if (this.isSimple)
return recipeItemHelper.canCraft(this, null);
return RecipeMatcher.findMatches(items, this.input) != null;
}
@Override
@Nonnull
public NonNullList<Ingredient> getIngredients()
{
return this.input;
}
@Override
@Nonnull
public String getGroup()
{
return this.group == null ? "" : this.group.toString();
}
@Override
public boolean canFit(int p_194133_1_, int p_194133_2_)
{
return p_194133_1_ * p_194133_2_ >= this.input.size();
}
public static ShapelessOreRecipe factory(JsonContext context, JsonObject json)
{
String group = JsonUtils.getString(json, "group", "");
NonNullList<Ingredient> ings = NonNullList.create();
for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients"))
ings.add(CraftingHelper.getIngredient(ele, context));
if (ings.isEmpty())
throw new JsonParseException("No ingredients for shapeless recipe");
ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
return new ShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), ings, itemstack);
}
}
*/
@@ -54,8 +54,6 @@ public class ForgeRegistries
public static final IForgeRegistry<VillagerProfession> VILLAGER_PROFESSIONS = RegistryManager.ACTIVE.getRegistry(VillagerProfession.class);
public static final IForgeRegistry<EntityType<?>> ENTITIES = RegistryManager.ACTIVE.getRegistry(EntityType.class);
public static final IForgeRegistry<TileEntityType<?>> TILE_ENTITIES = RegistryManager.ACTIVE.getRegistry(TileEntityType.class);
public static final IForgeRegistry<IRecipe> RECIPES = RegistryManager.ACTIVE.getRegistry(IRecipe.class);
/**
* This function is just to make sure static inializers in other classes have run and setup their registries before we query them.
*/
@@ -89,7 +89,6 @@ public class GameData
public static final ResourceLocation ENCHANTMENTS = new ResourceLocation("minecraft:enchantments");
public static final ResourceLocation ENTITIES = new ResourceLocation("minecraft:entities");
public static final ResourceLocation TILEENTITIES = new ResourceLocation("minecraft:tileentities");
public static final ResourceLocation RECIPES = new ResourceLocation("minecraft:recipes");
public static final ResourceLocation PROFESSIONS = new ResourceLocation("minecraft:villagerprofessions");
private static final int MAX_BLOCK_ID = 4095;
private static final int MIN_ITEM_ID = MAX_BLOCK_ID + 1;
@@ -101,7 +100,6 @@ public class GameData
private static final int MAX_ENCHANTMENT_ID = Short.MAX_VALUE - 1; // Short - serialized as a short in ItemStack NBTs.
private static final int MAX_ENTITY_ID = Integer.MAX_VALUE >> 5; // Varint (SPacketSpawnMob)
private static final int MAX_TILE_ENTITY_ID = Integer.MAX_VALUE; //Doesnt seem to be serialized anywhere, so no max.
private static final int MAX_RECIPE_ID = Integer.MAX_VALUE >> 5; // Varint CPacketRecipeInfo/SPacketRecipeBook
private static final int MAX_PROFESSION_ID = 1024; //TODO: Is this serialized anywhere anymore?
private static final ResourceLocation BLOCK_TO_ITEM = new ResourceLocation("minecraft:blocktoitemmap");
@@ -132,7 +130,6 @@ public class GameData
makeRegistry(SOUNDEVENTS, SoundEvent.class, MAX_SOUND_ID).create();
makeRegistry(POTIONTYPES, PotionType.class, MAX_POTIONTYPE_ID, new ResourceLocation("empty")).create();
makeRegistry(ENCHANTMENTS, Enchantment.class, MAX_ENCHANTMENT_ID).create();
// makeRegistry(RECIPES, IRecipe.class, MAX_RECIPE_ID).disableSaving().allowModification().addCallback(RecipeCallbacks.INSTANCE).create();
makeRegistry(PROFESSIONS, VillagerProfession.class, MAX_PROFESSION_ID).create();
// TODO do we need the callback and the static field anymore?
makeRegistry(ENTITIES, EntityType.class, MAX_ENTITY_ID).create();