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++;