Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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();
	}
}

  • 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();
	}
}

  • 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

  • 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?

 

  • 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?

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.