Jump to content

Recommended Posts

Posted

So, I'm following this book that's been helping me get the basics of Minecraft modding down. The problem is, sometimes I'll run into some outdated information, and I have no idea how to progress. Right now I'm having a problem with ModelBakery.addVariantName being deprecated, and I'm not really sure how the new parameters work (it's suggesting that I use ModelBakery.registerItemVariants instead, but I have no idea how that works), or even if this means that none of my code will work the way that the book teaches it. Can someone please look at my code and tell me how I can fix it efficiently? Just for extra clarity, I'm also adding the .json and .lang files so that if I've done anything wrong, someone could point it out to me! Thank you so much!!!

 

Main code file:

 

package com.aideux.rockmetadataexamples;

import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.relauncher.Side;

@Mod(modid = RockMetadataExamples.MODID, version = RockMetadataExamples.VERSION)
public class RockMetadataExamples 
{
public static final String MODID = "aideux_rockmetadataexamples";
public static final String VERSION = "1.0";
public static Item rock;

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	if(event.getSide() == Side.CLIENT)
	{
		ItemRock.registerVariants();
	}
}
@EventHandler
public void init(FMLInitializationEvent event)
{
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register
	(rock, 0, new ModelResourceLocation(MODID + ":" + ((ItemRock) rock).getNameFromDamage(0), "inventory"));
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register
	(rock, 1, new ModelResourceLocation(MODID + ":" + ((ItemRock) rock).getNameFromDamage(1), "inventory"));
}
}

 

ItemRock class file:

 

package com.aideux.rockmetadataexamples;

import java.util.List;

import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemRock extends Item 
{
private static String name = "rock";
private static String[] metaNames = {"green", "black"};

public String getUnlocalizedName(ItemStack par1ItemStack)
{
	return super.getUnlocalizedName()+ "." + metaNames[par1ItemStack.getItemDamage()];
}

public static String getNameFromDamage(int damage)
{
	return name + metaNames[damage];
}

public static void registerVariants()
{
	String[] variantNames = new String[metaNames.length];
	for(int i = 0; i < metaNames.length; i++)
	{
		variantNames[i] = RockMetadataExamples.MODID + ":" + getNameFromDamage(i);
	}
	ModelBakery.addVariantName(RockMetadataExamples.rock, variantNames);
}

@SuppressWarnings({"unchecked", "rawtypes"})
@SideOnly(Side.CLIENT)
@Override
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
	for(int x = 0; x < metaNames.length; x++)
	{
		par3List.add(new ItemStack(this, 1, x));
	}
}

public ItemRock()
{
	GameRegistry.registerItem(this, name);
	setCreativeTab(CreativeTabs.tabMisc);

	setHasSubtypes(true);
}

public String getName()
{
	return name;
}
}

 

.json for black variant:

 

{
    "parent": "builtin/generated",
    "textures": {
        "layer0": "aideux_seconditemexample:items/rockblack"
    },
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25],
            "translation": [ 0, 4, 2],
            "scale": [ 1.7, 1.7, 1.7]
        }
    }

 

.json for green variant:

 

{
    "parent": "builtin/generated",
    "textures": {
        "layer0": "aideux_seconditemexample:items/rockgreen"
    },
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25],
            "translation": [ 0, 4, 2],
            "scale": [ 1.7, 1.7, 1.7]
        }
    }

 

and my .lang file:

 

item.aideux_rockmetadataexamples_rockGreen.name=Green Rock

item.aideux_rockmetadataexamples_rockBlack.name=Black Rock

 

Thank you so much again for all your help!!!

Posted

Well, for starters, things like the mesher (pertaining to rendering) exist only on the client side, so you need to learn about proxies. Even worse for the mesher is that it is fragile. Common wisdom now is that you should be calling some custom model loader in (client proxy's) preinit.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted

Well, for starters, things like the mesher (pertaining to rendering) exist only on the client side, so you need to learn about proxies. Even worse for the mesher is that it is fragile. Common wisdom now is that you should be calling some custom model loader in (client proxy's) preinit.

Could you maybe give me an example or edit my code so that I could understand from a more visual standpoint? Thank you!

Posted

Use

ModelLoader.setCustomModelResourceLocation

or

ModelLoader.setCustomMeshDefinition

in preInit instead of

ItemModelMesher#register

in init.

 

ModelBakery.registerVariantNames

takes arguments in the same format as

ModelBakery.addVariantName

(

"modid:modelName"

), but expects either

ResourceLocation

s or

ModelResourceLocation

s instead of

String

s.

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

Use

ModelLoader.setCustomModelResourceLocation

or

ModelLoader.setCustomMeshDefinition

in preInit instead of

ItemModelMesher#register

in init.

 

ModelBakery.registerVariantNames

takes arguments in the same format as

ModelBakery.addVariantName

(

"modid:modelName"

), but expects either

ResourceLocation

s or

ModelResourceLocation

s instead of

String

s.

 

So how are resource locations formatted? Is it similar to creating variables, or do I have to do something else? I'm sorry for not getting it, I'm really trying to. Again, I really appreciate all your guys' help!

Posted

So how are resource locations formatted? Is it similar to creating variables, or do I have to do something else? I'm sorry for not getting it, I'm really trying to. Again, I really appreciate all your guys' help!

 

Create a

ResourceLocation

or

ModelResourceLocation

with the

new

operator like you would any other object.

 

A

ResourceLocation

consists of a resource domain and a resource path. There are two public constructors:

  • One that takes a single string in the format
    "<domain>:<path>"


  • One that takes the domain and path as two separate strings

 

ModelResourceLocation

extends

ResourceLocation

and adds a variant. There are three public constructors:

  • One that takes a single string in the format
    "<domain>:<path>#<variant>"

    (the variant is optional and defaults to

    normal

    )

  • One that takes a
    ResourceLocation

    for the domain and path and a string for the variant

  • One that takes a string in the format
    "<domain>:<path>"

    for the domain and path and a string for the variant

 

The domain is the name of the assets folder to look in, usually your mod ID (i.e. the domain

minecraft

maps to assets/minecraft). If you don't specify a domain, it defaults to

minecraft

.

 

ModelBakery.registerVariantNames

tells Minecraft to load the specified models. It expects

<path>

to be the name of your model, which either maps to the item model assets/<domain>/models/item/<path>.json (this is the first priority) or the model specified by the variant with name

<variant>

in the blockstates file assets/<domain>/blockstates/<path>.json (this is added by Forge and only used when the item model wasn't found). If you provide a

ResourceLocation

, the variant will be

inventory

.

 

The model will be stored using the provided

ModelResourceLocation

as the key.

 

ModelLoader.setCustomModelResourceLocation

and

ModelLoader.setCustomMeshDefinition

tell Minecraft which model to use for the

Item

, using the provided

ModelResourceLocation

as the key.

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.

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.