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

Hi, I got back into modding some time ago and I am having Problems once again with my json files.

I was trying to create a block with different variants, which I succeeded in now, but however the ItemBlock still doesn't render properly.

I already used a formatter and it said that all jsons are valid.

Furthermore, the console shows no error, although I already know that it accesses the Jsons.

And I also searched for spelling mistakes and if all textures were where they belonged to the last two hours.

 

Json "pressure_switch" in blockstates folder

{
	"forge_marker": 1,
	"defaults": {
		"model": "minecraft:cube_all"
	},
	"variants": {
		"variant": {
			"a": {
				"textures": {
					"all": "zeldadungeons:blocks/pressure_switch.a"
				}
			},
			"b": {
				"textures": {
					"all": "zeldadungeons:blocks/pressure_switch.b"
				}
			}
		}
	}
}

Json "pressure_switch" in models/block  folder

{
	"parent": "minecraft:block/block"
}

Json "pressure_switch" in models/item folder

{
	"parent": "zeldadungeons:block/pressure_switch",
	"textures": {
		"layer0": "zeldadungeons:items/pressure_switch.a"
    }
}

 

This is ingame:

 

1.png

Edited by ArmamentHaki

Show your item model registration code.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Okay, until now I already changed quite a bit of code, but my former Problem is still remaining. I am probably loading the Model in a wrong way.

Here is the class that Manages my Item and Block models:

package net.zeldadungeons.init;

import net.zeldadungeons.ZeldaDungeons;
import net.zeldadungeons.init.blocks.BlockPressureSwitch;
import net.zeldadungeons.util.MeshDefinitionFix;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;

@Mod.EventBusSubscriber(value = Side.CLIENT, modid = ZeldaDungeons.MODID)
public class Modelizer 
{
	public static final Modelizer INSTANCE = new Modelizer();
	
	@SubscribeEvent
	public static void registerAll(final ModelRegistryEvent e)
	{
		INSTANCE.registerItemModels();
		INSTANCE.registerBlockModels();
	}

	private void registerItemModels() {
		

	}
	
	private void registerBlockModels(){
		registerBlockItemModel(Blockizer.PRESSURE_SWITCH.getDefaultState());
	}
	
	private void registerItemModel(Item item)
	{
		final ModelResourceLocation  resource = new ModelResourceLocation(item.getRegistryName(), "inventory");
		ModelBakery.registerItemVariants(item, resource);
		ModelLoader.setCustomMeshDefinition(item, MeshDefinitionFix.create(stack -> resource));
		ModelLoader.setCustomModelResourceLocation(item, 0, resource);
	}
	
	private void registerBlockItemModel(final IBlockState state) {
		final Block block = state.getBlock();
		final Item item = Item.getItemFromBlock(block);

		if (item != Items.AIR) {
			registerItemModel(item);
		}
	}

}

I have no normal Items yet, so that the registerItemModels method is empty. However, my Block Item Models are the Problem.

 

  • Author
2 hours ago, diesieben07 said:
  • You don't need to call ModelBakery.registerItemVariants if you use setCustomModelResourceLocation.
  • Your call to setCustomMeshDefinition is pointless. You don't need an ItemMeshDefinition if you are just going to return a constant location, it will just harm performance. Moreover, if you use setCustomMeshDefinition, setCustomModelResourceLocation is pointless since the former overrides the latter.
  • That workaround you are using with MeshDefinitionFix is no longer needed, afaik.

Other than that your code looks alright. 

Thank you. In the end, it was my json which was pointing to the wrong texture file, which I should have realised earlier as it was in the console the whole time. I will change the other things now

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.