Minecraft forge 不加载项目纹理 1.10.2

Minecraft forge doesn't load item texture 1.10.2

我正在尝试为我拥有的物品添加纹理,但它没有加载到 Minecraft 中。这是我的基地 mod class: 包裹 com.gandiber.thegalaxymod;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
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.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.common.util.EnumHelper;

@Mod(modid = TheGalaxyMod.MODID, version = TheGalaxyMod.VERSION)
public class TheGalaxyMod {
    public static final String MODID = "gandiber_thegalaxymod";
    public static final String VERSION = "1.0";
    public static ItemSword GalaxiumSword;
    public static ToolMaterial galaxium = EnumHelper.addToolMaterial("galaxium", 3, 4000, 15F, 38.0F, 22);

    @SidedProxy(serverSide = "com.gandiber.thegalaxymod.CommonProxy", clientSide = "com.gandiber.thegalaxymod.ClientProxy")
    public static CommonProxy proxy;

    @EventHandler
    public void init(FMLInitializationEvent event) {
        //Weapons
            GameRegistry.register(GalaxiumSword = new ItemGalaxySword(galaxium, "diamondswordcompressed"));

        // some example code
    GameRegistry.addRecipe(new ItemStack(Items.DIAMOND),
            "XXX",
            "XXX",
            "XXX",
            'X', Items.GOLD_INGOT);
    }
}

我常用的代理 class:

package com.gandiber.thegalaxymod;

import net.minecraft.item.Item;

public class CommonProxy {
    public void registerItemRenderer(Item item, int meta, String id) {

    }
}

我的客户端代理 class:

package com.gandiber.thegalaxymod;

import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.client.model.ModelLoader;

public class ClientProxy extends CommonProxy {
    @Override
    public void registerItemRenderer(Item item, int meta, String id) {
        ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(TheGalaxyMod.MODID + ":" + id, "inventory"));
    }
}

这是真正的剑物品class:

package com.gandiber.thegalaxymod;

import net.minecraft.item.Item;
import net.minecraft.item.ItemSword;
import net.minecraftforge.fml.common.registry.GameRegistry;
import thegalaxymod.tutorial.item.ItemModelProvider;

public class ItemGalaxySword extends ItemSword implements ItemModelProvider {
private String name;
    public ItemGalaxySword(ToolMaterial material, String name ) {
        super(material);
        setUnlocalizedName(name);
        setRegistryName(name);
    }

    @Override
    public void registerItemModel(Item item) {
        TheGalaxyMod.proxy.registerItemRenderer(this, 0, name);
    }
}

这是项目的 json model 文件:

{
    "parent": "item/generated",
    "textures": {
        "layer0": "gandiber_thegalaxymod:items/diamondswordcompressed"
    },
  "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]
      }
   }
}

这是渲染 class 基本上什么都不做的东西:

package thegalaxymod.tutorial.item;

import net.minecraft.item.Item;

public interface ItemModelProvider {
    void registerItemModel(Item item);
}

最后是实际的 PNG: 我希望你能下载这个。如果没有,请告诉我!

我的文件夹结构:

Json 文件: C:\Users\myusername\Documents\Mods\Auto-Bow\src\main\resources\assets\gandiber_thegalaxymod\models\item\diamondswordcompressed.json

PNG 文件: C:\Users\myusername\Documents\Mods\Auto-Bow\src\main\resources\assets\gandiber_thegalaxymod\textures\items\diamondswordcompressed.json

我尝试过的事情:

此外,如果这对任何人有帮助,这里是我的 fml-client-latest.log 文件: (Pastebin)

在您的 ItemGalaxySword class 中,您从未设置实例变量 name。 您应该将 this.name = name 添加到构造函数。

我找到问题了。当然运气好,我花了3个小时调试问题,问问题10分钟内就想出了答案。

有两个问题:

  1. 正如BdoubleB97所说,在我的"ItemGalaxySword"class中,忘记将参数"name"的值赋值给全局变量"name" .这是小问题。

  2. 另一个问题是 "registerItemModel" 方法从未被调用过。我实际上在 ItemGalaxySword 中创建了一个名为 initmodel 的不同方法,它完成了同样的事情,但现在我在 TheGalaxyMod 中有一个方法从我的所有 classes 调用 initmodel 方法,最后,客户端代理调用该方法。这段代码应该清楚一点:

编辑:今天晚些时候 post 编码,运行 没时间了。