Jump to content

Recommended Posts

Posted (edited)

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
Posted

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.

Posted
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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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