英文:
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<Item> event) {
event.getRegistry().register(new Item(new Item.Properties().group(ItemGroup.MISC)).setRegistryName("example_item"));
}
}
This is the example_item.json:
{
"parent":"items/generated",
"textures":{
"layer0":"examplemod:items/example_item"
}
}
en_us.json:
{
"item.examplemod.example_item":"Super Seed"
}
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 存储库,然后将链接发布在这里
另外,我建议使用 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
"parent": "item/generated",
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
Also, I recommend using DeferredRegister class and RegistryObjects to register your custom items.
Syntax:
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()));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论