简体   繁体   English

物品纹理为粉红色/黑色

[英]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. 因此,我在主程序包和下面列出的其他一些类中创建了“ Trauma.java”类。 All packages and classes: Package Explorer 所有软件包和类: 软件包资源管理器

Trauma.java 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 BasicItem.java

package items;

import net.minecraft.item.Item;

public class BasicItem extends Item {

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

}

ItemUranium.java ItemUranium.java

package items;

public class ItemUranium extends BasicItem {

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

}

ClientProxy.java 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 ServerProxy.java

package proxy;

public class ServerProxy {

    public void registerClientStuff() {}

}

uranium.json uranium.json

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

uranium.png 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 :) 谢谢 :)

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. 模型网格器是Vanilla(Mojang)代码,正确地使用它一直是挑剔和不可靠的,如果调用得太早就会失败,而调用得太晚就会失败。 So Forge added the ModelLoader class to resolve that problem. 因此,Forge添加了ModelLoader类来解决该问题。

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...: 其次,根据您使用的Minecraft版本,您应该...:

  1. Stop using GameRegistry.Register 停止使用GameRegistry.Register
    • Instead use the RegistryEvent.Register<T> events (where <T> will be <Block> to register blocks, <Item> to register items, etc) 而是使用RegistryEvent.Register<T>事件(其中<T>将是<Block>来注册块, <Item>来注册项,等等)
  2. Register your models in the ModelRegistryEvent and no where else. ModelRegistryEvent注册您的模型,在其他地方则没有。
    • This event is @SideOnly(CLIENT) and can be subscribed to in your client proxy, avoiding the need to forward references through your proxy class. 此事件为@SideOnly(CLIENT) ,可以在您的客户端代理中进行预订,从而避免了通过代理类转发引用的需要。 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. 这样做是这样的 ,其中最需要的是第197-199行 ,其中在项目注册事件期间填充了数组。 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. 在您的未本地化名称中包含您的Mod ID。 The best way to do this would be setUnlocalizedName(getRegistryName().toString()); 最好的方法是setUnlocalizedName(getRegistryName().toString());

See also the Forge documentation on events . 另请参阅有关事件的Forge文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM