为什么纹理没有加载?Minecraft 15.2 Forge 31.2

huangapple go评论79阅读模式
英文:

Why is it that the texture isn´t loading? Minecraft 15.2 Forge 31.2

问题

以下是您提供的内容的翻译部分:

我正在尝试为使用Forge创建的Minecraft物品应用纹理,但由于某种原因它无法加载。我对此还不熟悉,因此无法确定问题出在哪里,因此我将上传多行代码。
这段代码来自itemInit.Java:

package com.example.examplemod.init;

import com.example.examplemod.ExampleMod;

import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.ObjectHolder;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, bus = Bus.MOD)
@ObjectHolder(ExampleMod.MOD_ID)
public class itemInit {
    public static Item example_item = null;

    @SubscribeEvent
    public static void registerItems(final RegistryEvent.Register<Item> event) {
        event.getRegistry().register(new Item(new Item.Properties().group(ItemGroup.MISC)).setRegistryName("example_item"));
    }
}

这是example_item.json文件:

{
    "parent":"items/generated",
    "textures":{
    "layer0":"examplemod:items/example_item"
    }
}

en_us.json文件:

{
    "item.examplemod.example_item":"Super Seed"
}

这是项目层次结构的图片:项目层次结构

英文:

I am trying to apply a texture to an item created with forge for Minecraft but for some reason it wouldn´t load. I am new to this so I cant recognize where the problem is, so I will upload multiple lines of code.
This code is from itemInit.Java:

package com.example.examplemod.init;
    
import com.example.examplemod.ExampleMod;

import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.ObjectHolder;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;


@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, bus = Bus.MOD)
@ObjectHolder(ExampleMod.MOD_ID)
public class itemInit {
	public static Item example_item = null;
	
	@SubscribeEvent
	public static void registerItems(final RegistryEvent.Register&lt;Item&gt; event) {
		event.getRegistry().register(new Item(new Item.Properties().group(ItemGroup.MISC)).setRegistryName(&quot;example_item&quot;));
	}
}

This is the example_item.json:

{
	&quot;parent&quot;:&quot;items/generated&quot;,
	&quot;textures&quot;:{
	&quot;layer0&quot;:&quot;examplemod:items/example_item&quot;
	}
}

en_us.json:

{
	&quot;item.examplemod.example_item&quot;:&quot;Super Seed&quot;
}

And here is a picture of the project hierarchy:Project hierarchy

答案1

得分: 1

在你的 example_mod.json 文件中,将第2行改为:

"parent": "item/generated",

在目录 assets\examplemod\models 内,你有两个文件夹分别命名为 blocks 和 items。将它们的名称更改为 'block' 和 'item',不带引号。如果你遇到其他问题,请将错误日志发布到 pastebin 或其他网站。另外,为你的项目创建一个 GitHub 存储库,然后将链接发布在这里 为什么纹理没有加载?Minecraft 15.2 Forge 31.2

另外,我建议使用 DeferredRegister 类和 RegistryObjects 来注册你的自定义物品。
语法:

public static final DeferredRegister<Item> NAME = new DeferredRegister<>(ForgeRegistries.ITEMS, "Your Mod ID");

public static final RegistryObject<Item> Example_item = NAME.register("Registry_Name", () -> new Item(new Item.Properties()));
英文:

In your example_mod.json file, line 2, change it to

&quot;parent&quot;: &quot;item/generated&quot;,

Inside the directory assets\examplemod\models, you have two folders named blocks and items. Change their names to 'block' and 'item' without the quotation marks. If you encounter any other problem, post your error log using pastebin or some other site. Also, create a github repo for your project and then post the link here 为什么纹理没有加载?Minecraft 15.2 Forge 31.2

Also, I recommend using DeferredRegister class and RegistryObjects to register your custom items.
Syntax:

public static final DeferredRegister&lt;Item&gt; NAME = new DeferredRegister&lt;&gt;(ForgeRegistries.ITEMS, &quot;Your Mod ID&quot;);
   
public static final RegistryObject&lt;Item&gt; Example_item = NAME.register(&quot;Registry_Name&quot;, () -&gt; new Item(new Item.Properties()));

huangapple
  • 本文由 发表于 2020年10月20日 12:10:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/64438352.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定