Minecraft forge不加载项目纹理1.10.2

时间:2017-04-29 01:06:17

标签: java eclipse minecraft minecraft-forge

我正在尝试为我拥有的项目添加纹理,并且它不会在Minecraft中加载。这是我的基础mod类: 包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);
    }
}

我的常用代理类:

package com.gandiber.thegalaxymod;

import net.minecraft.item.Item;

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

    }
}

我的客户端代理类:

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"));
    }
}

这是实际剑的项目类:

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模型文件:

{
    "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]
      }
   }
}

这是渲染类的东西,它什么都没做:

package thegalaxymod.tutorial.item;

import net.minecraft.item.Item;

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

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

我的文件夹结构:

Json文件: C:\ Users \用户名为myUsername \文件\ MODS的\自动弓\ SRC \主\资源\资产\ gandiber_thegalaxymod \模型\项目\ diamondswordcompressed.json

PNG文件: C:\ Users \用户名为myUsername \文件\ MODS的\自动弓\ SRC \主\资源\资产\ gandiber_thegalaxymod \纹理\项目\ diamondswordcompressed.json

我尝试过的事情:

  • 删除json文件的第二部分,以便只显示“layer0”。
  • 删除setCustomModelResourceLocation方法中的“inventory”参数。

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

我已经找到了问题所在。当然,幸运的是,我花了3个小时来调试问题,并在提出问题的10分钟内找到了答案。

有两个问题:

  1. 正如BdoubleB97所说,在我的“ItemGalaxySword”类中,我忘了将参数“name”的值赋给全局变量“name”。这是一个小问题。

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

  3. 编辑:今天晚些时候发布代码,时间不多了。