mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 00:07:45 +00:00
Fix enum helpers for EnumRarity {moved to Commn and changed paramter} and EnumCreatureType {new parameter} and added junit test for them. Closes #1009
This commit is contained in:
1 parent
0a56e19d47
commit
0737601dbf
3 files changed
+70
-11
No files matched your search
@@ -13,8 +13,7 @@ public class EnumHelperClient extends EnumHelper
|
||||
{
|
||||
{GameType.class, int.class, String.class},
|
||||
{Options.class, String.class, boolean.class, boolean.class},
|
||||
{EnumOS.class},
|
||||
{EnumRarity.class, int.class, String.class}
|
||||
{EnumOS.class}
|
||||
};
|
||||
|
||||
public static GameType addGameType(String name, int id, String displayName)
|
||||
@@ -31,11 +30,6 @@ public class EnumHelperClient extends EnumHelper
|
||||
{
|
||||
return addEnum(EnumOS.class, name);
|
||||
}
|
||||
|
||||
public static EnumRarity addRarity(String name, int color, String displayName)
|
||||
{
|
||||
return addEnum(EnumRarity.class, name, color, displayName);
|
||||
}
|
||||
|
||||
public static <T extends Enum<? >> T addEnum(Class<T> enumType, String enumName, Object... paramValues)
|
||||
{
|
||||
|
||||
@@ -13,8 +13,10 @@ import net.minecraft.entity.EnumCreatureType;
|
||||
import net.minecraft.entity.item.EntityPainting.EnumArt;
|
||||
import net.minecraft.entity.player.EntityPlayer.EnumStatus;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.Item.ToolMaterial;
|
||||
import net.minecraft.item.ItemArmor.ArmorMaterial;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
|
||||
import net.minecraft.world.EnumSkyBlock;
|
||||
import net.minecraft.world.gen.structure.StructureStrongholdPieces.Stronghold.Door;
|
||||
@@ -37,7 +39,7 @@ public class EnumHelper
|
||||
{ArmorMaterial.class, int.class, int[].class, int.class},
|
||||
{EnumArt.class, String.class, int.class, int.class, int.class, int.class},
|
||||
{EnumCreatureAttribute.class},
|
||||
{EnumCreatureType.class, Class.class, int.class, Material.class, boolean.class},
|
||||
{EnumCreatureType.class, Class.class, int.class, Material.class, boolean.class, boolean.class},
|
||||
{Door.class},
|
||||
{EnumEnchantmentType.class},
|
||||
{EnumEntitySize.class},
|
||||
@@ -45,7 +47,8 @@ public class EnumHelper
|
||||
{MovingObjectType.class},
|
||||
{EnumSkyBlock.class, int.class},
|
||||
{EnumStatus.class},
|
||||
{ToolMaterial.class, int.class, int.class, float.class, float.class, int.class}
|
||||
{ToolMaterial.class, int.class, int.class, float.class, float.class, int.class},
|
||||
{EnumRarity.class, EnumChatFormatting.class, String.class}
|
||||
};
|
||||
|
||||
public static EnumAction addAction(String name)
|
||||
@@ -65,9 +68,9 @@ public class EnumHelper
|
||||
return addEnum(EnumCreatureAttribute.class, name);
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static EnumCreatureType addCreatureType(String name, Class typeClass, int maxNumber, Material material, boolean peaceful)
|
||||
public static EnumCreatureType addCreatureType(String name, Class typeClass, int maxNumber, Material material, boolean peaceful, boolean animal)
|
||||
{
|
||||
return addEnum(EnumCreatureType.class, name, typeClass, maxNumber, material, peaceful);
|
||||
return addEnum(EnumCreatureType.class, name, typeClass, maxNumber, material, peaceful, animal);
|
||||
}
|
||||
public static Door addDoor(String name)
|
||||
{
|
||||
@@ -101,6 +104,10 @@ public class EnumHelper
|
||||
{
|
||||
return addEnum(ToolMaterial.class, name, harvestLevel, maxUses, efficiency, damage, enchantability);
|
||||
}
|
||||
public static EnumRarity addRarity(String name, EnumChatFormatting color, String displayName)
|
||||
{
|
||||
return addEnum(EnumRarity.class, name, color, displayName);
|
||||
}
|
||||
|
||||
private static void setup()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package net.minecraftforge.test;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.client.EnumHelperClient;
|
||||
import net.minecraftforge.common.util.EnumHelper;
|
||||
|
||||
import org.apache.logging.log4j.core.helpers.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class EnumHelperTest
|
||||
{
|
||||
private boolean failed = false;
|
||||
|
||||
@Test
|
||||
public void test()
|
||||
{
|
||||
System.out.println("Testing EnumHelper:");
|
||||
Object[][] types = (Object[][])ReflectionHelper.getPrivateValue(EnumHelper.class, null, "commonTypes");
|
||||
for (Object[] o : types)
|
||||
testType(o);
|
||||
|
||||
System.out.println("Testing EnumHelperClient:");
|
||||
types = (Object[][])ReflectionHelper.getPrivateValue(EnumHelperClient.class, null, "clentTypes");
|
||||
for (Object[] o : types)
|
||||
testType(o);
|
||||
|
||||
if (failed)
|
||||
throw new RuntimeException("Enum Helper test failed!");
|
||||
}
|
||||
private void testType(Object[] info)
|
||||
{
|
||||
Class<?> cls = (Class)info[0];
|
||||
Class<?>[] parameterTypes = new Class[info.length + 2 - 1];
|
||||
parameterTypes[0] = String.class;
|
||||
parameterTypes[1] = int.class;
|
||||
System.arraycopy(info, 1, parameterTypes, 2, info.length - 1);
|
||||
try
|
||||
{
|
||||
cls.getDeclaredConstructor(parameterTypes);
|
||||
System.out.println(" " + cls.getName() + ": Success");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println(" " + cls.getName() + ": Failed");
|
||||
for (Constructor<?> c : cls.getDeclaredConstructors())
|
||||
{
|
||||
System.out.println(" " + c.toString());
|
||||
}
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user