如何为Item注册obj模型?

kabuki_


版本信息
你使用的IDE:Eclipse
你使用的IDE版本: 4.12
Forge版本: 14.23.5.2823
Minecraft版本: 1.12
Mapping 文件版本: stable_39

提问
Forge的扩展里有支持加载Wavefront OBJ的方法,但是经查阅都只是得到十分模糊的描述,如何正确的加载和使用obj模型并使其支持类似 Property Override的功能(或者说不能使用OBJLoader,必须得自己写渲染器?),望指点

相关代码
这是些是我自己琢磨出来的,但是未能成功地注册
ModelHandler.class

@Mod.EventBusSubscriber(modid = MidgardReborn.MODID, value = Side.CLIENT)
public class ModelHandler {
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public static void registerModel(ModelRegistryEvent event) throws Exception
	{
		OBJLoader.INSTANCE.addDomain(MidgardReborn.MODID);
		
		for(Map.Entry<String, ResourceLocation> entry : RegistyManager.OBJModelRegisty.getInstance().getRegisty().entrySet())
		{
			ModelResourceLocation mrl = new ModelResourceLocation(entry.getValue(), "inventory");
			Item item = RegistyManager.OBJModelRegisty.getItemFromID(entry.getKey());
			if(item != null)
			{
				ModelLoader.setCustomModelResourceLocation(item, 0, mrl);
			}
		}
	}
}

RegistyManager.OBJModelRegisty.class

public abstract class RegistyManager<T> implements IRegistyManager<T>{
	
	protected Map<String, T> registy = Maps.newHashMap();

	@Override
	public Map<String, T> getRegisty() {
		return registy;
	}

	public static class OBJModelRegisty extends RegistyManager<ResourceLocation>
	{
		private static OBJModelRegisty instance = new OBJModelRegisty();
		private final ResourceLocation ITEM_CLAW = new ResourceLocation(MidgardReborn.MODID, "item_claw.obj");
		private final ResourceLocation ITEM_CLAW_LESS = new ResourceLocation(MidgardReborn.MODID, "item_claw_less.obj");
		
		private OBJModelRegisty() {
			registy.put("item_claw", ITEM_CLAW);
			registy.put("item_claw_less", ITEM_CLAW_LESS);
		}
		
		@Nullable
		public static Item getItemFromID(String name)
		{
			return ItemRegisty.instance.registy.get(name);
		}
		
		public static OBJModelRegisty getInstance()
		{
			return instance;
		}
	}
}

FledgeXu


请注意,1.12 Forge官方已经放弃支持,不会再有Bug修复,添加特性,请尽早迁移到1.14/1.15
你实现的太复杂了,你只需要简单的用OBJLoader.INSTANCE.addDomain(MidgardReborn.MODID);开启使用OBJ模型,然后在json文件里指定就行。
具体我没有用过,这里我找了一些资料。
基本上就是你需要在BlockState里指定OBJ,然后在Item的模型里指定BlockState,这么做好像是因为,Forge会在加载模型的时候自动搜索BlockState里的内容,顺便这个问题在1.14之后已经解决了,你可以直接在物品的json文件里指定使用OBJ模型。
好像Forge官方就提供例子,模型(资源文件夹)

For entities you need your own obj model loader/renderer.
For items/blocks you need to put your model and material(.obj and .mtl files) in an appropriate models subfolder in your assets, point to that model through a blockstates file for example(if you are using forge’s blockstates for items) and you are done. There are a few thing you need to know:

  1. When specifying an obj model to be used you must include the obj extension in the path too.
  2. You must call OBJLoader.INSTANCE.addDomain(modid) with your modid as a parameter before the models are loaded.
    Here(and the resources folder) is an example provided by forge itself.

kabuki_


那既然这样就可以解决了,那我是否能够继续使用类似 Property Override的功能呢?
我想要该模型像弓一样根据数据进行改变


FledgeXu


我觉应该是可以的,具体我没在1.12试过:joy::joy:


kabuki_


我想我已经自己解决了上述的问题,但是现在导入的模型不知道为什么会变得巨大无比,难道是单位不对么?


FledgeXu


应该是。
如果你用的是Blender,Minecraft的方块的标准大小是1m*1m*1m。


system


该主题在最后一个回复创建后7天后自动关闭。不再允许新的回复。