简化obj模型烘焙

时间:2019-11-11 09:57:12

标签: java minecraft minecraft-forge

我正在尝试烘焙多个obj模型,但是我必须复制并粘贴长代码才能烘焙一个模型。这使我的主要mod类非常长。

我尝试创建类并创建新对象,但由于onModelBakeEvent应该是静态的,因此似乎不起作用。

@SubscribeEvent
public static void onModelBakeEvent(ModelBakeEvent event) {
    try {
        IUnbakedModel model = getModelOrLogError(new ResourceLocation("unixmod:block/fabricator.obj"), "Missing fabricator model");
        if (model instanceof OBJModel) {
            IBakedModel bakedModel = model.bake(event.getModelLoader(), ModelLoader.defaultTextureGetter(),
                    new BasicState(model.getDefaultState(), true), DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);

            IBakedModel bakedInvModel = model.bake(event.getModelLoader(), ModelLoader.defaultTextureGetter(),
                    new BasicState(model.getDefaultState(), true), DefaultVertexFormats.ITEM);

            bakedInvModel = new PerspectiveMapWrapper(bakedInvModel, BLOCK_TRANSFORMS);


            event.getModelRegistry().put(new ModelResourceLocation("unixmod:fabricator", ""), bakedModel);
            event.getModelRegistry().put(new ModelResourceLocation("unixmod:fabricator", "inventory"), bakedInvModel);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        IUnbakedModel model = getModelOrLogError(new ResourceLocation("unixmod:block/acidmushroom.obj"), "Missing acidmushroom model");
        if (model instanceof OBJModel) {
            IBakedModel bakedModel = model.bake(event.getModelLoader(), ModelLoader.defaultTextureGetter(),
                    new BasicState(model.getDefaultState(), true), DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);

            IBakedModel bakedInvModel = model.bake(event.getModelLoader(), ModelLoader.defaultTextureGetter(),
                    new BasicState(model.getDefaultState(), true), DefaultVertexFormats.ITEM);

            bakedInvModel = new PerspectiveMapWrapper(bakedInvModel, BLOCK_TRANSFORMS);


            event.getModelRegistry().put(new ModelResourceLocation("unixmod:acidmushroom", ""), bakedModel);
            event.getModelRegistry().put(new ModelResourceLocation("unixmod:acidmushroom", "inventory"), bakedInvModel);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

0 个答案:

没有答案