Trauma
Trauma

Reputation: 11

Item textures are pink/black

I've tried to modify minecraft by adding a new item called "uranium". Therefore I created the class "Trauma.java" in the main package and a few other classes listed below. All packages and classes: Package Explorer

Trauma.java

package main;

import items.ItemUranium;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
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 proxy.ServerProxy;

@Mod(modid = Trauma.MODID)
public class Trauma {

    public static final String MODID = "Trauma";

    @SidedProxy(clientSide = "proxy.ClientProxy", serverSide = "proxy.ServerProxy")
    public static ServerProxy proxy;

    public static ItemUranium uranium = new ItemUranium();

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        GameRegistry.register(uranium);
    }

    @EventHandler
    public void init(FMLInitializationEvent event) {
        proxy.registerClientStuff();
    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent event) {

    }

}

BasicItem.java

package items;

import net.minecraft.item.Item;

public class BasicItem extends Item {

    public BasicItem(String name) {
        setUnlocalizedName(name);
        setRegistryName(name);
    }

}

ItemUranium.java

package items;

public class ItemUranium extends BasicItem {

    public ItemUranium() {
        super("uranium");
    }

}

ClientProxy.java

package proxy;

import items.BasicItem;
import main.Trauma;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;

public class ClientProxy extends ServerProxy {

    @Override
    public void registerClientStuff ()  {
        registerItemModel(Trauma.uranium);
    }

    public static void registerItemModel(BasicItem item) {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Trauma.MODID + ":" + item.getRegistryName(), "inventory"));
    }

}

ServerProxy.java

package proxy;

public class ServerProxy {

    public void registerClientStuff() {}

}

uranium.json

{
    "parent": "item/generated",
    "textures": {
        "layer0": "Trauma:items/uranium"
    }
}

uranium.png

ingame

Also I don't know why the item in inventory isn't called uranium...

I spent two hours on fixing the problem and it didn't help so it would be really nice if somebody of you may help me. Thanks :)

Upvotes: 0

Views: 231

Answers (1)

Don't use the Model Mesher:

The model mesher is Vanilla (Mojang) code and using it correctly has always been finicky and unreliable, failing if you called it too early and failing if you called it too late. So Forge added the ModelLoader class to resolve that problem.

Replace this line:

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(...)

With this line:

ModelLoader.setCustomModelResourceLocation(...)

The ... contents are identical.

Second, depending on what version of Minecraft you're using, you should...:

  1. Stop using GameRegistry.Register
    • Instead use the RegistryEvent.Register<T> events (where <T> will be <Block> to register blocks, <Item> to register items, etc)
  2. Register your models in the ModelRegistryEvent and no where else.
    • This event is @SideOnly(CLIENT) and can be subscribed to in your client proxy, avoiding the need to forward references through your proxy class. Eg. I do it like this, where lines 197-199 is the most common scenario needed, where the array is populated during the item registration event. The rest of that method handles the custom state mappers and custom mesh definitions that are used by only a handful of items/blocks and not relevant here.
  3. Include your Mod ID in your unlocalized name. The best way to do this would be setUnlocalizedName(getRegistryName().toString());

See also the Forge documentation on events.

Upvotes: 2

Related Questions