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'm currently trying to have an ItemBlock change models depending on its variant which is set in the item's NBT data.

 

Currently This is what I have:

 

Registry:

public class RegisterUtil {
    public static void registerAll (FMLPreInitializationEvent event) {
        registerArcadeMachine(event, ArcadeBlocks.arcadeMachine);
    }
  
    private static void registerBlockWavefrontMeshDefinition (Item item, Block block) {
        registerItemBlock(item, block);
        OBJLoader.INSTANCE.addDomain(Reference.MODID);

        if (item instanceof IItemMeshDefinition) {
            ModelLoader.setCustomMeshDefinition(item, ((IItemMeshDefinition)item).getMeshDefinition());
            for (EnumGame g : EnumGame.values()) {
                ModelBakery.registerItemVariants(item, new ModelResourceLocation(block.getRegistryName(), "game=" + g.getName())); // Gives me missing model error
                //ModelBakery.registerItemVariants(item, new ModelResourceLocation(block.getRegistryName().toString() + "_" + g.getName(), "inventory")); // Says parent can't have non-vanilla model (or something along those lines)
            }
            //ModelBakery.registerItemVariants(item, new ModelResourceLocation(block.getRegistryName(), "game")); // Gives me missing model error
            //ModelBakery.registerItemVariants(item, new ModelResourceLocation(block.getRegistryName(), "inventory")); // No error, no model/textures
        }
    }

    @Deprecated
    private static void registerArcadeMachine (FMLPreInitializationEvent event, Block block) {
        final ItemBlockArcade item = new ItemBlockArcade(block);
        if (event.getSide() == Side.CLIENT) registerBlockWavefrontMeshDefinition(item, block);
    }

    private static void registerBlock (Block block) {
        GameRegistry.register(block.setUnlocalizedName(block.getRegistryName().toString()));
    }

    private static void registerItemBlock (Item item, Block block) {
        registerBlock(block);
        GameRegistry.register(item, block.getRegistryName());
    }
}

 

ItemBlock:

public class ItemBlockArcade extends ItemBlock implements IItemMeshDefinition {
    public ItemBlockArcade (Block block) {
        super(block);
        setMaxDamage(0);
        setHasSubtypes(true);
    }

    public int getMetadata (int damage) {
        return damage;
    }

  	// Not really sure how to use ItemMeshDefinition
    @Override
    @SideOnly(Side.CLIENT)
    public ItemMeshDefinition getMeshDefinition () {
        return new ItemMeshDefinition() {
            @Override
            public ModelResourceLocation getModelLocation(ItemStack stack) {
                //if (stack.hasTagCompound()) return new ModelResourceLocation(Reference.MODID + ":arcade_machine_" + EnumMob.getName(stack.getTagCompound().getInteger("Game")), "inventory");
                //else return new ModelResourceLocation(Reference.MODID + ":arcade_machine_snake", "inventory");

                if (stack.hasTagCompound()) return new ModelResourceLocation(Reference.MODID + ":arcade_machine", "game=" + EnumMob.getName(stack.getTagCompound().getInteger("Game")));
                else return new ModelResourceLocation(Reference.MODID + ":arcade_machine", "game=snake");
            }
        };
    }
}

 

Blockstate Json

{
	"forge_marker": 1,
	"defaults": {
		"model": "arcademod:arcade_machine.obj",
		"transform": "forge:default-block"
	},
	"variants": {
		"inventory": [{
			"model": "arcademod:arcade_machine.obj",
			"textures": {
				"#all": "arcademod:blocks/snake/bottom"
			}
		}],
        "game": {
			"snake": {
				"textures": {
					"#all": "arcademod:blocks/snake/bottom"
				}
			},
            "tetrominoes": {
                "textures": {
                	"#all": "arcademod:blocks/tetrominoes/back_panel"
                }
            }
		},
		"facing": {
			"south": {
				"y": 0
			},
			"west": {
				"y": 90
			},
			"north": {
				"y": 180
			},
			"east": {
				"y": 270
			}
		}
	}
}

 

All the ways I tried so far have just given me a purple/black texture and loaded no model. I'm pretty sure I'm doing something super simple incorrectly.

Edited by SuperHB

Your blockstates file has two properties (game and facing), but the ModelResourceLocation you return from the ItemMeshDefinition only includes one of them. It needs to include both, in alphabetical order.

 

You should also call ModelBakery.registerItemVariants with every possible ModelResourceLocation that can be returned by the ItemMeshDefinition to ensure that they're loaded by Minecraft.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author
2 hours ago, Choonster said:

Your blockstates file has two properties (game and facing), but the ModelResourceLocation you return from the ItemMeshDefinition only includes one of them. It needs to include both, in alphabetical order.

 

You should also call ModelBakery.registerItemVariants with every possible ModelResourceLocation that can be returned by the ItemMeshDefinition to ensure that they're loaded by Minecraft.

Thank you! That fixed everything.

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.