Регистрация блков/предметов через отдельный класс

Сообщения
3
Лучшие ответы
0
Реакции
0
Версия Minecraft
1.10.x
Помню, что в 1.6-1.8 можно было регистрировать блоки и итемы через отдельные классы(ru.vm99.mod.item.Items) а теперь при попытке зарегестрировать блоки и итемы таким образом появляется проблема - игра не регистрирует их. А если напрямую в главный файл - все нормально. Вот код, уверен, там есть ошибка, которую я не вижу.
Код:
package ru.lonesimba.decor;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import ru.lonesimba.decor.block.BlockScaffold;

@Mod(modid = "decor", name = "Decorations", version = "0.1 #1")
public class MainClass {
 
 @SidedProxy(serverSide = "ru.lonesimba.decor.ServerProxy", clientSide = "ru.lonesimba.decor.ClientProxy")
 public static ServerProxy proxy;
 
 public static Block SCAFFOLD = new BlockScaffold();
 
 public void preInit(FMLPreInitializationEvent event) {
 //ModBlocks.blockRegistry();
 //ModItems.itemRegistry();

 GameRegistry.register(SCAFFOLD);
 }
 
 public void init(FMLInitializationEvent event) {
 proxy.init();
 }
 
 public void postinit(FMLPostInitializationEvent event) {
 
 }
 
 public static void initRender() {
 //ModBlocks.blockRenderRegistry();
 //ModItems.itemRenderRegistry();
 registerRenderBlock(SCAFFOLD);
 }
 
 public static void registerRenderBlock(Block block) {
 Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory"));
 }
 
 public static void registerRenderItem(Item item) {
 Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(item.getRegistryName(), "inventory"));
 }

}
Код:
package ru.lonesimba.decor;

import net.minecraft.block.Block;
import net.minecraftforge.fml.common.registry.GameRegistry;
import ru.lonesimba.decor.block.BlockScaffold;

public class ModBlocks {
 
 public static Block SCAFFOLD = new BlockScaffold();

 public static void blockRegistry() {
 GameRegistry.register(SCAFFOLD);
 }
 
 public static void blockRenderRegistry() {
 MainClass.registerRenderBlock(SCAFFOLD);
 }
}
Код:
package ru.lonesimba.decor;

import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
import ru.lonesimba.decor.item.ItemIronStick;

public class ModItems {

 public static Item ironstick = new ItemIronStick();
 
 public static void itemRegistry() {
 GameRegistry.registerItem(ironstick);
 }
 
 public static void itemRenderRegistry() {
 MainClass.registerRenderItem(ironstick);
 }

}
Код:
package ru.lonesimba.decor.item;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ItemIronStick extends Item {

 public ItemIronStick() {
 setCreativeTab(CreativeTabs.MISC);
 setFull3D();
 setUnlocalizedName("ironstick");
 }

}
Код:
package ru.lonesimba.decor.block;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class BlockScaffold extends Block {

 public BlockScaffold() {
 super(Material.WOOD);
 
 setRegistryName("scaffold");
 setUnlocalizedName("scaffold");
 setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
 
 GameRegistry.register(this);
 GameRegistry.register(new ItemBlock(this), getRegistryName());
 }


}
Код:
package ru.lonesimba.decor;

public class ClientProxy extends ServerProxy {

 public void init() {
 MainClass.initRender();
 }

}
Код:
package ru.lonesimba.decor;

public class ServerProxy {

 public void init() {
 
 }
}
 
Сообщения
685
Лучшие ответы
15
Реакции
18
@EventHandler перед postinit и init поставь
 
Сообщения
3
Лучшие ответы
0
Реакции
0
Добавил, пашет. Забыл о них за тот год, что не работал с модами, а в учебнике не указаны вовсе они. Вот еще проблемка с блокстейтами. Вот лог:
Код:
java.lang.Exception: Could not load model definition for variant decor:scaffold
 at net.minecraftforge.client.model.ModelLoader.getModelBlockDefinition(ModelLoader.java:274) ~[ModelLoader.class:?]
 at net.minecraft.client.renderer.block.model.ModelBakery.loadBlock(ModelBakery.java:121) ~[ModelBakery.class:?]
 at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:229) ~[ModelLoader.class:?]
 at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:146) ~[ModelLoader.class:?]
 at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
 at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:122) [SimpleReloadableResourceManager.class:?]
 at net.minecraft.client.Minecraft.startGame(Minecraft.java:540) [Minecraft.class:?]
 at net.minecraft.client.Minecraft.run(Minecraft.java:386) [Minecraft.class:?]
 at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_112]
 at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
 at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_112]
 at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
 at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: java.lang.RuntimeException: Encountered an exception when loading model definition of model decor:blockstates/scaffold.json
 at net.minecraft.client.renderer.block.model.ModelBakery.loadMultipartMBD(ModelBakery.java:205) ~[ModelBakery.class:?]
 at net.minecraft.client.renderer.block.model.ModelBakery.getModelBlockDefinition(ModelBakery.java:185) ~[ModelBakery.class:?]
 at net.minecraftforge.client.model.ModelLoader.getModelBlockDefinition(ModelLoader.java:270) ~[ModelLoader.class:?]
 ... 20 more
Caused by: java.io.FileNotFoundException: decor:blockstates/scaffold.json
 at net.minecraft.client.resources.SimpleReloadableResourceManager.getAllResources(SimpleReloadableResourceManager.java:83) ~[SimpleReloadableResourceManager.class:?]
 at net.minecraft.client.renderer.block.model.ModelBakery.loadMultipartMBD(ModelBakery.java:198) ~[ModelBakery.class:?]
 at net.minecraft.client.renderer.block.model.ModelBakery.getModelBlockDefinition(ModelBakery.java:185) ~[ModelBakery.class:?]
 at net.minecraftforge.client.model.ModelLoader.getModelBlockDefinition(ModelLoader.java:270) ~[ModelLoader.class:?]
 ... 20 more
[22:08:17] [Client thread/ERROR] [FML]: Exception loading model for variant decor:scaffold#inventory for item "decor:scaffold", normal location exception: 
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model decor:item/scaffold with loader VanillaLoader.INSTANCE, skipping
 at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:153) ~[ModelLoaderRegistry.class:?]
 at net.minecraftforge.client.model.ModelLoader.loadItemModels(ModelLoader.java:317) ~[ModelLoader.class:?]
 at net.minecraft.client.renderer.block.model.ModelBakery.loadVariantItemModels(ModelBakery.java:170) ~[ModelBakery.class:?]
 at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:147) ~[ModelLoader.class:?]
 at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
 at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:122) [SimpleReloadableResourceManager.class:?]
 at net.minecraft.client.Minecraft.startGame(Minecraft.java:540) [Minecraft.class:?]
 at net.minecraft.client.Minecraft.run(Minecraft.java:386) [Minecraft.class:?]
 at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_112]
 at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
 at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_112]
 at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
 at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: java.io.FileNotFoundException: decor:models/item/scaffold.json
 at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:69) ~[SimpleReloadableResourceManager.class:?]
 at net.minecraft.client.renderer.block.model.ModelBakery.loadModel(ModelBakery.java:311) ~[ModelBakery.class:?]
 at net.minecraftforge.client.model.ModelLoader.access$1100(ModelLoader.java:118) ~[ModelLoader.class:?]
 at net.minecraftforge.client.model.ModelLoader$VanillaLoader.loadModel(ModelLoader.java:868) ~[ModelLoader$VanillaLoader.class:?]
 at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:149) ~[ModelLoaderRegistry.class:?]
 ... 20 more
[22:08:17] [Client thread/ERROR] [FML]: Exception loading model for variant decor:scaffold#inventory for item "decor:scaffold", blockstate location exception: 
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model decor:scaffold#inventory with loader VariantLoader.INSTANCE, skipping
 at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:153) ~[ModelLoaderRegistry.class:?]
 at net.minecraftforge.client.model.ModelLoader.loadItemModels(ModelLoader.java:325) ~[ModelLoader.class:?]
 at net.minecraft.client.renderer.block.model.ModelBakery.loadVariantItemModels(ModelBakery.java:170) ~[ModelBakery.class:?]
 at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:147) ~[ModelLoader.class:?]
 at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
 at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:122) [SimpleReloadableResourceManager.class:?]
 at net.minecraft.client.Minecraft.startGame(Minecraft.java:540) [Minecraft.class:?]
 at net.minecraft.client.Minecraft.run(Minecraft.java:386) [Minecraft.class:?]
 at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_112]
 at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
 at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_112]
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_112]
 at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_112]
 at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
 at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: net.minecraft.client.renderer.block.model.ModelBlockDefinition$MissingVariantException
 at net.minecraft.client.renderer.block.model.ModelBlockDefinition.getVariant(ModelBlockDefinition.java:78) ~[ModelBlockDefinition.class:?]
 at net.minecraftforge.client.model.ModelLoader$VariantLoader.loadModel(ModelLoader.java:1183) ~[ModelLoader$VariantLoader.class:?]
 at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:149) ~[ModelLoaderRegistry.class:?]
 ... 20 more
Вот файлы:
Код:
{
 "variants": {
      "normal": { "model": "decor:scaffold" }

  }
}
Код:
{
  "parent": "block/cube_all",
  "textures": {
      "all": "decor:blocks/scaffold"}

}
Код:
{
  "parent": "decor:block/scaffold"
}
 
Сообщения
624
Лучшие ответы
4
Реакции
8
Создай отдельный класс.
Допустим ItemList.

Создай метод registerItem

Код:
 public static void registerItem(Item item, String name){
 LanguageRegistry.addName(item, name);
 GameRegistry.registerItem(item, "unlocalized" + name);
 }
После чего в том классе сделай метод на рег.предметов.

Код:
Item item_test;

public static void applyItems(){
 item_test= new Item(id++, "salt", 1);
 
 helper.registerItem(item_test, "Salt");
 }

Просто для примера и на 1.6, но тут информация нужная тебе - есть.
 
Сообщения
3
Лучшие ответы
0
Реакции
0
расстрою - в 1.10 нет LanguageRegistry/
[hr]
Разобрался, зарегистрировал через GameRegistry.register(). Просто я как всегда косячу(олфаги проде тимахи или олдесктона докажут). Но алмазы обоим, советы хорошие.
 
Сверху