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

hey guys really stuck here, Can't figure out why my texture rendering isn't working. I THINK it is a path issue. I am using the forge eclipse environment.

 

main class:

 

package statslevelmod;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
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.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;

@Mod(modid = Level.MODID, name = Level.MODNAME, version = Level.VERSION)
public class Level {
    public static final String MODID = "statslevelmod";
    public static final String MODNAME = "Level";
    public static final String VERSION = "1.0.1";
    
    public static Item sharpstick;
    
    
    @EventHandler
    public void preInit (FMLPreInitializationEvent event) {
    	
    	System.out.println("Loading " + MODNAME + "!");
    	System.out.println("Version " + VERSION + "!");
    	
    	sharpstick = new SharpStick();
    	
    	MinecraftForge.EVENT_BUS.register(new LevelEventHandler());
    	
    	GameRegistry.addRecipe(new ItemStack(sharpstick),
    	"A ",
    	" A",
    	'A', Items.stick);
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event) {
    	
    	if (event.getSide() == Side.CLIENT) {
    		regTexture(sharpstick);
    	}
    }
    
    @EventHandler
    public void postInt (FMLPostInitializationEvent event) {
    	
    	System.out.println(MODID + " loaded successfuly!");
    }
    
    public static void regTexture(Item item) {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));    <----- where the error occurs.
    }
}

 

 

My Event Handler Class:

 

package statslevelmod;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

public class LevelEventHandler {

@SubscribeEvent
public void onPlayerMineEvent(PlayerEvent.BreakSpeed event) {

	if (event.state.getBlock() == Blocks.log) {

		event.newSpeed = -1;

	} else {

		event.newSpeed = -1;
	}
}

@SubscribeEvent
public void onPlayerClickEvent(PlayerInteractEvent event) {
	if (event.action == Action.RIGHT_CLICK_BLOCK) {

		if (event.entityPlayer.getCurrentEquippedItem() == null) {

			if (event.world.getBlockState(event.pos).getBlock() == Blocks.grass && event.face == event.face.UP) {

				if (!event.world.isRemote) {
					event.world.setBlockState(event.pos, Blocks.dirt.getDefaultState());


					Block.spawnAsEntity(event.world, event.pos, new ItemStack(Level.sharpstick));
				}						
			}
		}
	}
}
}

 

 

My Item Class

 

package statslevelmod;

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

public class SharpStick extends Item {

private final String name = "sharpStick";

public SharpStick() {
	super();

	GameRegistry.registerItem(this, name);
	setCreativeTab(CreativeTabs.tabMisc);
	setUnlocalizedName(name);
	setMaxStackSize(64);
}
}

 

 

My Item JSON file:

 

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

 

 

This is a screenshot of my Package Explorer:

http://i.imgur.com/Vnhc4zX.png

 

Any help is greatly appreciated, thanks :)

  • Author

Textures must be registered in init, not preInit.

 

Thanks! that fixed the crash but the item has no texture, so probably I have a pathing problem also.

  • Author

FIXED IT! Basically I copied and pasted my asset folder and subfolders everywhere, found it worked, so deleted one at a time to find the right one :D

Textures must be registered in init, not preInit.

 

This is the case if you're using the vanilla

ItemModelMesher#register

methods (like the OP is), but Forge's

ModelLoader#setCustomModelResourceLocation

and

ModelLoader.setCustomMeshDefinition

methods (which do the same thing as the vanilla methods) need to be called in preInit rather than init.

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

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.