Блок с EnumType

Версия Minecraft
1.12.2
API
Forge
183
8
16
Здравсвуйте все. Мне нужно создать 13 блоков руды, и чтобы не нагромождать лишних классов, я сделал из через EnumType. В итоге класс - это симбиоз класса ванильного камня и вот этой статьи:

public class BlockOreFactory extends Block {
public static final PropertyEnum<BlockOreFactory.EnumType> VARIANT = PropertyEnum.create("variant", BlockOreFactory.EnumType.class);
public BlockOreFactory() {
super(Material.ROCK);
this.setCreativeTab(FactorySimulator.FactorySimulator);
this.setDefaultState(this.createBlockState().getBaseState().withProperty(VARIANT, EnumType.COOPER));
}
public String getLocalizedName()
{
return I18n.translateToLocal(this.getUnlocalizedName() + "." + BlockOreFactory.VARIANT.getName() + ".name");
}
public MapColor getMapColor(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
return state.getValue(VARIANT).getMapColor();
}
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return Item.getItemFromBlock(getBlockFromName(BlockOreFactory.VARIANT.getName()));
}

public int damageDropped(IBlockState state)
{
return state.getValue(VARIANT).getMetadata();
}

public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items)
{
for (BlockOreFactory.EnumType blockorefactory$enumtype : BlockOreFactory.EnumType.values())
{
items.add(new ItemStack(this, 1, blockorefactory$enumtype.getMetadata()));
}
}

public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(VARIANT, BlockOreFactory.EnumType.byMetadata(meta));
}

public int getMetaFromState(IBlockState state)
{
return state.getValue(VARIANT).getMetadata();
}

protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {VARIANT});
}
public enum EnumType implements IStringSerializable
{
COOPER(0, MapColor.BROWN, "cooper", true),
TIN(1, MapColor.GRAY, "tin", true),
CHROMIUM(2, MapColor.PINK, "chromium", true),
SILVER(3, MapColor.SILVER, "silver", true),
TUNGSTEN(4, MapColor.BLACK, "tungsten", true),
THORIUM(5, MapColor.GREEN, "thorium", true),
TITANIUM(6, MapColor.PURPLE, "titanium", true),
PLATINUM(7, MapColor.SNOW, "platinum", true),
URANIUM(8, MapColor.GREEN, "uranium", true),
TANTALUM(9, MapColor.LIME, "tantalum", true),
IRIDIUM(10, MapColor.CYAN, "iridium", true),
OSMIUM(11, MapColor.LIGHT_BLUE, "osmium", true),
NEODYMIUM(12, MapColor.BLUE, "neodymium", true);
private static final BlockOreFactory.EnumType[] META_LOOKUP = new BlockOreFactory.EnumType[values().length];
private final int meta;
private final String name;
private final String unlocalizedName;
private final MapColor mapColor;
private final boolean isNatural;

EnumType(int meta, MapColor mapColor, String name, boolean isNatural)
{
this(meta, mapColor, name, name, isNatural);
}

EnumType(int meta, MapColor mapColor, String name, String unlocalizedName, boolean isNatural)
{
this.meta = meta;
this.name = name;
this.unlocalizedName = unlocalizedName;
this.mapColor = mapColor;
this.isNatural = isNatural;
}

public int getMetadata()
{
return this.meta;
}

public MapColor getMapColor()
{
return this.mapColor;
}

public String toString()
{
return this.name;
}

public static BlockOreFactory.EnumType byMetadata(int meta)
{
if (meta < 0 || meta >= META_LOOKUP.length)
{
meta = 0;
}

return META_LOOKUP[meta];
}
public String getName()
{
return this.name;
}

public String getUnlocalizedName()
{
return this.unlocalizedName;
}

public boolean isNatural()
{
return this.isNatural;
}

static
{
for (BlockOreFactory.EnumType blockorefactory$enumtype : values())
{
META_LOOKUP[blockorefactory[imath]enumtype.getMetadata()] = blockorefactory[/imath]enumtype;
}
}
}
}
ItemBlockOreFactory.java:
public class ItemBlockOreFactory extends ItemMultiTexture {
    public ItemBlockOreFactory(Block block) {
        super(block, block, new String[] {"cooper","tin","chromium", "silver", "tungsten", "thorium", "titanium", "platinum", "uranium", "tantalum", "iridium", "osmium", "neodymium"});
        this.setHasSubtypes(true);
    }
    @Override
    public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
    {
        if (this.isInCreativeTab(tab))
        {
            this.block.getSubBlocks(tab, items);
        }
    }
    @Override
    public String getUnlocalizedName(ItemStack stack)
    {
        return super.getUnlocalizedName() + "." + BlockOreFactory.EnumType.byMetadata(stack.getMetadata()).getName();
    }
}
BlockRegister.java:
public class BlockRegister {
    public static Block ORE_FACTORY = new BlockOreFactory();

    public static void register() {
        registerBlockMeta(ORE_FACTORY, new ItemBlockOreFactory(ORE_FACTORY));
    }

    @SideOnly(Side.CLIENT)
    public static void registerRender() {
        setRender(ORE_FACTORY);
    }

    public static void registerBlockMeta(Block block, ItemBlock itemBlock) {
        ForgeRegistries.BLOCKS.register(block);
        ForgeRegistries.ITEMS.register(itemBlock.setRegistryName(block.getRegistryName()));
    }
    private static void setRegister(Block block) {
        ForgeRegistries.BLOCKS.register(block);
        ForgeRegistries.ITEMS.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
    }

    @SideOnly(Side.CLIENT)
    private static void setRender(Block block) {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));
    }
}
в итоге я получаю это:
Краш-лог:
net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Factory Simulator (factory_simulator)
Caused by: java.lang.NullPointerException: Can't use a null-name for the registry, object Block{minecraft:air}.
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864)
    at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:294)
    at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:288)
    at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:120)
    at com.kirik.fs.register.BlockRegister.registerBlockMeta(BlockRegister.java:27)
    at com.kirik.fs.register.BlockRegister.register(BlockRegister.java:18)
    at com.kirik.fs.proxy.CommonProxy.preInit(CommonProxy.java:15)
    at com.kirik.fs.proxy.ClientProxy.preInit(ClientProxy.java:14)
    at com.kirik.fs.FactorySimulator.preInit(FactorySimulator.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:639)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
    at com.google.common.eventbus.EventBus.post(EventBus.java:217)
    at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
    at com.google.common.eventbus.EventBus.post(EventBus.java:217)
    at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:629)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
    at net.minecraft.client.Minecraft.init(Minecraft.java:467)
    at net.minecraft.client.Minecraft.run(Minecraft.java:378)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.legacydev.Main.start(Main.java:86)
    at net.minecraftforge.legacydev.MainClient.main(MainClient.java:29)
Я вообще не понимаю, откуда он воздух взял...(строка краша 2)
 
Краш-лог
net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Factory Simulator (factory_simulator)
Caused by: java.lang.NullPointerException: Can't use a null-name for the registry, object Block{minecraft:air}.
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864)
at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:294)
at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:288)
at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:120)
at com.kirik.fs.register.BlockRegister.registerBlockMeta(BlockRegister.java:27)
at com.kirik.fs.register.BlockRegister.register(BlockRegister.java:18)
at com.kirik.fs.proxy.CommonProxy.preInit(CommonProxy.java:15)
at com.kirik.fs.proxy.ClientProxy.preInit(ClientProxy.java:14)
at com.kirik.fs.FactorySimulator.preInit(FactorySimulator.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:639)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
at com.google.common.eventbus.EventBus.post(EventBus.java:217)
at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)
at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
at com.google.common.eventbus.EventBus.post(EventBus.java:217)
at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)
at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:629)
at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
at net.minecraft.client.Minecraft.init(Minecraft.java:467)
at net.minecraft.client.Minecraft.run(Minecraft.java:378)
at net.minecraft.client.main.Main.main(Main.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.minecraftforge.legacydev.Main.start(Main.java:86)
at net.minecraftforge.legacydev.MainClient.main(MainClient.java:29)
Краш-лог:
net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Factory Simulator (factory_simulator)
Caused by: java.lang.NullPointerException: Can't use a null-name for the registry, object Block{minecraft:air}.
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:864)
	at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:294)
	at net.minecraftforge.registries.ForgeRegistry.add(ForgeRegistry.java:288)
	at net.minecraftforge.registries.ForgeRegistry.register(ForgeRegistry.java:120)
	at com.kirik.fs.register.BlockRegister.registerBlockMeta(BlockRegister.java:27)
	at com.kirik.fs.register.BlockRegister.register(BlockRegister.java:18)
	at com.kirik.fs.proxy.CommonProxy.preInit(CommonProxy.java:15)
	at com.kirik.fs.proxy.ClientProxy.preInit(ClientProxy.java:14)
	at com.kirik.fs.FactorySimulator.preInit(FactorySimulator.java:20)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:639)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)
	at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
	at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
	at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
	at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
	at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
	at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
	at com.google.common.eventbus.EventBus.post(EventBus.java:217)
	at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)
	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:629)
	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
	at net.minecraft.client.Minecraft.init(Minecraft.java:467)
	at net.minecraft.client.Minecraft.run(Minecraft.java:378)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.legacydev.Main.start(Main.java:86)
	at net.minecraftforge.legacydev.MainClient.main(MainClient.java:29)
7,099
324
1,510
У блока не вызвал setRegistryName перед регистрацией
 
Сверху