Posted February 21, 20169 yr I am trying to use the OBJLoader to load and obj model in one of my blocks but for some reason it only works for the item itself and not the block? If I change the ModelResourceLocation from inventory to normal neither works? I tried to look at the mbe05 example but nothing seems to be wrong: https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe05_block_smartblockmodel2 My ModelBakeEvent: @SubscribeEvent public void ModelBakeEvent(ModelBakeEvent event){ try { Function<ResourceLocation, TextureAtlasSprite> textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation resourceLocation) { return Minecraft.getMinecraft().getTextureMapBlocks().registerSprite(resourceLocation); } }; OBJModel model = (OBJModel) OBJLoader.instance.loadModel(new ResourceLocation(RefValues.MOD_ID+":models/obj/Gemstone.obj")); IBakedModel baked = model.bake(model.getDefaultState(), Attributes.DEFAULT_BAKED_FORMAT, textureGetter); event.modelRegistry.putObject(new ModelResourceLocation(RefValues.MOD_ID+":"+RefValues.RUBY+RefValues.GEMSTONE, "inventory"), baked); } catch (IOException e) { e.printStackTrace(); } }
February 22, 20169 yr Author I tried adding my own custom state mapper but it doesn't seem to do anything? @SubscribeEvent public void ModelBakeEvent(ModelBakeEvent event){ StateMapperBase ignoreState = new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState iBlockState) { return new ModelResourceLocation(RefValues.MOD_ID+":"+RefValues.RUBY+RefValues.GEMSTONE); } }; ModelLoader.setCustomStateMapper(Gemstone.getGemstone(RefValues.RUBY), ignoreState); try { Function<ResourceLocation, TextureAtlasSprite> textureGetter = new Function<ResourceLocation, TextureAtlasSprite>() { public TextureAtlasSprite apply(ResourceLocation resourceLocation) { return Minecraft.getMinecraft().getTextureMapBlocks().registerSprite(resourceLocation); } }; OBJModel model = (OBJModel) OBJLoader.instance.loadModel(new ResourceLocation(RefValues.MOD_ID+":models/obj/Gemstone.obj")); IBakedModel baked = model.bake(model.getDefaultState(), Attributes.DEFAULT_BAKED_FORMAT, textureGetter); event.modelRegistry.putObject(new ModelResourceLocation(RefValues.MOD_ID+":"+RefValues.RUBY+RefValues.GEMSTONE, "inventory"), baked); } catch (IOException e) { e.printStackTrace(); } }
February 22, 20169 yr Author That still didn't seem to work... So I was looking over the mbe05 example again and it turns out I don't even need the ModelBakeEvent since I'm using a custom ModelLoader but it doesn't seem to work. blockstate json { "variants": { "normal": { "model": "cwm:Gemstone.obj" } } } Setting StateMap on Load OBJLoader.instance.addDomain(RefValues.MOD_ID); StateMapperBase objState = new StateMapperBase() { @Override protected ModelResourceLocation getModelResourceLocation(IBlockState iBlockState) { return new ModelResourceLocation(RefValues.MOD_ID+":"+RefValues.RUBY+RefValues.GEMSTONE); } }; ModelLoader.setCustomStateMapper(Gemstone.getGemstone(RefValues.RUBY), objState); Setting Item Renderer Item item = Item.getItemFromBlock(Gemstone.getGemstone(RefValues.RUBY)); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(RefValues.MOD_ID+":"+RefValues.RUBY+RefValues.GEMSTONE)); Relevant console output [12:29:53] [Client thread/ERROR] [FML]: Model definition for location cwm:rubyGemstone#facing=north not found [12:29:53] [Client thread/ERROR] [FML]: Model definition for location cwm:rubyGemstone#facing=east not found [12:29:53] [Client thread/ERROR] [FML]: Model definition for location cwm:rubyGemstone#facing=south not found [12:29:44] [Client thread/ERROR] [FML]: Model definition for location cwm:rubyGemstone#facing=down not found [12:29:44] [Client thread/ERROR] [FML]: Model definition for location cwm:rubyGemstone#facing=west not found [12:29:44] [Client thread/ERROR] [FML]: Model definition for location cwm:rubyGemstone#facing=north not found
February 23, 20169 yr Author I didn't realize that it had to set the state map in preInit It had it in Init. That fixed it! Thanks! But now it doesn't work in the inventory?
February 23, 20169 yr Author Oh, I figured it out. If I ItemModelMesher#register, instead of ModelLoader.setCustomModelResourceLocation It works in both the inventory and the world. Is there any reason I shouldn't use ItemModelMesher#register?
February 23, 20169 yr Author Okay, but why doesn't the model work in the inventory when I use ModelLoader?
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.