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

For some reason, my texture isn't loading. This is my main FirstMod.java code.

 

package com.andytphan.firstmod;

import com.andytphan.firstmod.ItemKey;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
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.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;

@Mod(modid = FirstMod.MODID, version = FirstMod.VERSION)
public class FirstMod
{
    public static final String MODID = "firstmod";
    public static final String VERSION = "1.0";
    
    public static Item key;
    
    @EventHandler
    public void preInit (FMLPreInitializationEvent event)
    {
    	key = new ItemKey();
    	GameRegistry.registerItem(key, "key");
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    	GameRegistry.addRecipe(new ItemStack(Items.apple),
    			"XXX",
    			"XXX",
    			"XXX",
    			'X', Blocks.leaves
    	);
    	ItemStack enchantedStoneSword = new ItemStack(Items.stone_sword);
    	enchantedStoneSword.addEnchantment(Enchantment.sharpness, 5);
    	enchantedStoneSword.addEnchantment(Enchantment.knockback, 5);
    	
    	GameRegistry.addShapelessRecipe(enchantedStoneSword, Items.stone_sword, Items.flint, Items.gunpowder);
    }
    
    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {
    	if(event.getSide() == Side.CLIENT) {
    		RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
    		renderItem.getItemModelMesher().register(key, 0, new ModelResourceLocation(MODID + ":" + "key", "inventory"));
    	}
    }
}

 

This is my Key item code.

package com.andytphan.firstmod;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ItemKey extends Item {
public ItemKey() {
	GameRegistry.registerItem(this, "key");
	setUnlocalizedName(FirstMod.MODID + "_" + "key");
	setCreativeTab(CreativeTabs.tabMisc);
}

}

 

Finally, this is my json file code.

 

{
"parent": "builtin/generated",
"textures": {
	"layer0": "firstmod/items:key"
},
"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]
	}
}
}

You've mixed up the slash and the colon in your model's texture path. The colon separates the resource domain (your mod ID) from the resource path (the path of the texture relative to assets/<modid>/textures), the slash separates directories within the resource path (like in regular file paths). Use

"firstmod:items/key"

instead of

"firstmod/items:key"

.

 

You should use the sided proxy system (i.e. the

@SidedProxy

annotation) to register your models rather than checking for the client side in your

@Mod

class.

 

You should also use Forge's

ModelLoader.setCustomModelResourceLocation

/

ModelLoader.setCustomMeshDefinition

in preInit instead of Minecraft's

ItemModelMesher#register

overloads in init/postInit.

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

Do not do that ItemModelMesher stuff that you do in postInit (if you were to use that it'd have to be in init).

Use ModelLoader.setCustomModelResourceLocation in preInit. The rendering registration also needs to be in your ClientProxy or you will crash servers with your mod.

What is the full path to the json file?

 

The path to the json file is pathtomodding/src/main/resources/assests/firstmod/models/items/key.json.

Modders who use crafting tables to make enchanted items have often run into trouble, so don't be surprised if your enchantedStoneSword recipe rinses away your enchantments. Be sure to test it to find out.

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.

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.