Jump to content

Recommended Posts

Posted

So I know the answer is pretty much all over the place by now, however no matter where I look I just can't get it to work. Here's my code

 

[spoiler=ModBlocks]

public class ModBlocks {

public static final BlockConnected connected_polished_granite = new BlockConnectedPolishedGranite();

public static final BlockConnected connected_polished_andesite = new BlockConnectedPolishedAndesite();

public static final BlockConnected connected_polished_diorite = new BlockConnectedPolishedDiorite();

 

public static void init() {

GameRegistry.registerBlock(connected_polished_granite, "connected_polished_granite");

GameRegistry.registerBlock(connected_polished_andesite, "connected_polished_andesite");

GameRegistry.registerBlock(connected_polished_diorite, "connected_polished_diorite");

 

if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {

ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

String id = Reference.MOD_ID.toLowerCase();

mesher.register(GameRegistry.findItem(id, "connected_polished_granite"), 0, new ModelResourceLocation(id + ":cpg", "inventory"));

mesher.register(GameRegistry.findItem(id, "connected_polished_andesite"), 0, new ModelResourceLocation(id + ":cpa", "inventory"));

mesher.register(GameRegistry.findItem(id, "connected_polished_diorite"), 0, new ModelResourceLocation(id + ":cpd", "inventory"));

}

}

}

 

 

That class is run in the FMLInitializationEvent, the blocks register fine and render fine when placed. It's just the part where they don't render in the inventory, so if I could get like very clear instructions on what I need to fix it, I would really appreciate it. I know one person had an issue where it wouldn't render in his inventory/hand and someone cloned the github repo and it worked fine for me, so it might just be an issue on my end for some reason, but I've got no clue.

Posted

I literally was in it today.

 

Seems like when you want to add #inventory renderer to item that is not dependend to its meta, it must have same name.json as unlocalized name.

Idk, but that worked for me:

Block:

- Unlocalized name: connected_polished_granite

assets.mod.blockstates/connected_polished_granite.json  - must be with name of block.

assets.mod.models.block/connected_polished_granite_model.json    - refered from blockstates

assets.mod.models.item/connected_polished_granite.json    - must be with the name of block.

 

For convinience: (assets.mod.models.item/connected_polished_granite.json)

{
"parent": "mod:block/connected_polished_granite_model",
"display": {
	"thirdperson": {
		"rotation": [ 10, -45, 170 ],
		"translation": [ 0, 1.5, -2.75 ],
		"scale": [ 0.375, 0.375, 0.375 ]
	}
}
}

 

Seems like it has something to do with Model Maps (you have to put your item's model with same name as unlocalizedName for that item to actually use that model). Idk, never looked into that.

 

Also note: adding model to block's item must be in load() (or at least after block are done registering I think, i am doing in load)

1.7.10 is no longer supported by forge, you are on your own.

Posted

That somewhat helps, I didn't have models/item/connected_polished_granite Now I have that and the log doesn't say "Model definition for location unnamed:connected_polished_granite#inventory not found", however the texture for dropped, first, and third person is still null. Here's the item json file

 

[spoiler=assets/unnamed/models/item/connected_polished_granite.json]

{

    "parent": "unnamed:block/cpg",

    "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 the block model

[spoiler=assets/unnamed/models/block/cpg.json]

{

"parent": "block/cube",

"textures": {

"up": "unnamed:blocks/cpg",

"down": "unnamed:blocks/cpg",

"north": "unnamed:blocks/cpg",

"east": "unnamed:blocks/cpg",

"south": "unnamed:blocks/cpg",

"west": "unnamed:blocks/cpg",

"particle": "unnamed:blocks/cpg"

}

}

 

 

Posted

So I know the answer is pretty much all over the place by now, however no matter where I look I just can't get it to work. Here's my code

 

[spoiler=ModBlocks]

public class ModBlocks {

public static final BlockConnected connected_polished_granite = new BlockConnectedPolishedGranite();

public static final BlockConnected connected_polished_andesite = new BlockConnectedPolishedAndesite();

public static final BlockConnected connected_polished_diorite = new BlockConnectedPolishedDiorite();

 

public static void init() {

GameRegistry.registerBlock(connected_polished_granite, "connected_polished_granite");

GameRegistry.registerBlock(connected_polished_andesite, "connected_polished_andesite");

GameRegistry.registerBlock(connected_polished_diorite, "connected_polished_diorite");

 

if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {

ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

String id = Reference.MOD_ID.toLowerCase();

mesher.register(GameRegistry.findItem(id, "connected_polished_granite"), 0, new ModelResourceLocation(id + ":cpg", "inventory"));

mesher.register(GameRegistry.findItem(id, "connected_polished_andesite"), 0, new ModelResourceLocation(id + ":cpa", "inventory"));

mesher.register(GameRegistry.findItem(id, "connected_polished_diorite"), 0, new ModelResourceLocation(id + ":cpd", "inventory"));

}

}

}

 

 

That class is run in the FMLInitializationEvent, the blocks register fine and render fine when placed. It's just the part where they don't render in the inventory, so if I could get like very clear instructions on what I need to fix it, I would really appreciate it. I know one person had an issue where it wouldn't render in his inventory/hand and someone cloned the github repo and it worked fine for me, so it might just be an issue on my end for some reason, but I've got no clue.

 

> FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT

!! this is just begging for trouble, you should use proxies instead - see here http://greyminecraftcoder.blogspot.com.au/2013/11/how-forge-starts-up-your-code.html

 

Try fixing it and seeing if it solves your problem.

 

-TGG

 

 

 

 

Posted

That made no different at all

 

[spoiler=ClientProxy]

@Override public void registerRenderThings() {

ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

String id = Reference.MOD_ID.toLowerCase();

mesher.register(GameRegistry.findItem(id, "connected_polished_granite"), 0, new ModelResourceLocation(id + ":cpg", "inventory"));

mesher.register(GameRegistry.findItem(id, "connected_polished_andesite"), 0, new ModelResourceLocation(id + ":cpa", "inventory"));

mesher.register(GameRegistry.findItem(id, "connected_polished_diorite"), 0, new ModelResourceLocation(id + ":cpd", "inventory"));

}

 

 

 

Took the code out of the ModBlocks.init, moved the init of that to FMLPreInitialization, and did proxy.registerRenderThings in FMLInitialization.

Posted

Hi

 

Try doing the modelmesher code step by step and using your debugger or System.out.println to make sure it is working correctly..

eg

    Item itemBlockPartial = GameRegistry.findItem("minecraftbyexample", "mbe02_block_partial");
    ModelResourceLocation itemModelResourceLocation = new ModelResourceLocation("minecraftbyexample:mbe02_block_partial", "inventory");
    final int DEFAULT_ITEM_SUBTYPE = 0;
    Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemBlockPartial, DEFAULT_ITEM_SUBTYPE, itemModelResourceLocation);

Perhaps (eg) your String id is wrong, or similar.

 

If no joy with that, try placing a breakpoint in ItemRenderer.renderItemInFirstPerson at this line

          this.renderItem(entityplayersp, this.itemToRender, ItemCameraTransforms.TransformType.FIRST_PERSON);

and then trace through until you get to RenderItem.renderItemModelForEntity at this line

        IBakedModel ibakedmodel = this.itemModelMesher.getItemModel(stack);

This will let you see if the mesher has your model or not- i.e. if ibakedmodel is not found anywhere, or if it is found but is not right.  If that doesn't give you enough info, post back your results?

 

-TGG

 

 

 

 

 

 

Posted

Ok I understood half of that, I decided to do:

 

@SubscribeEvent public void onPlayerUpdate(TickEvent.PlayerTickEvent event) {

if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {

IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(event.player.getCurrentEquippedItem());

LogHelper.warn(model == null ? "null" : model.toString());

}

}

 

Yes I know it has the getEffectiveSide thing you said is bad, however this was just for debugging purposes. The log prints net.minecraftforge.client.model.IFlexibleBakedModel$Wrapper@7e80a98c

So the model is not null, no idea what the problem is

 

EDIT: Changing it to LogHelper.warn(model == null ? "null" : model.getTexture().getIconName());

The log says "missingno" So somewhere it gets messed up between the model and the texture, unless getTexture never has a value set (It is deprecated)

 

EDIT 2: Fixed, it was a really dumb mistake. ModelResourceLocation(id + ":connected_polished_granite", "inventory") instead of ModelResourceLocation(id + ":cpg", "inventory")

Posted

Seems like when you want to add #inventory renderer to item that is not dependend to its meta, it must have same name.json as unlocalized name.

Idk, but that worked for me:

Block:

- Unlocalized name: connected_polished_granite

assets.mod.blockstates/connected_polished_granite.json  - must be with name of block.

assets.mod.models.block/connected_polished_granite_model.json    - refered from blockstates

assets.mod.models.item/connected_polished_granite.json    - must be with the name of block.

 

Glad you fixed it ;p Am I that bad at explaining :C

1.7.10 is no longer supported by forge, you are on your own.

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.