本帖最后由 wszhxwsz 于 2022-2-8 13:39 编辑 
mod开发时建立一个物品(铜粒),inteljidea并未报错,但是在mc中用give指令找不到这一物品,下面是源码复制代码ItemCopperGrains.java
复制代码ItemRegistryHandlder.java
复制代码ZxMod.java
文件目录
 
 
mod开发时建立一个物品(铜粒),inteljidea并未报错,但是在mc中用give指令找不到这一物品,下面是源码
- package zzzz.zxmod.item.item;
 
 
- import net.minecraft.item.Item;
 
- import zzzz.zxmod.ZxMod;
 
 
- public class ItemCopperGrains extends Item
 
- {
 
-     public ItemCopperGrains()
 
-     {
 
-         this.setUnlocalizedName(ZxMod.MODID + ".cropperGrains");
 
-         this.setRegistryName("cropper_grains");
 
-         this.setMaxStackSize(64);
 
-     }
 
- }
 
- package zzzz.zxmod.item.item;
 
 
- import net.minecraft.client.renderer.block.model.ModelResourceLocation;
 
- import net.minecraft.item.Item;
 
- import net.minecraftforge.client.event.ModelRegistryEvent;
 
- import net.minecraftforge.client.model.ModelLoader;
 
- import net.minecraftforge.event.RegistryEvent.Register;
 
- import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
 
- import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
 
- import net.minecraftforge.fml.relauncher.Side;
 
- import net.minecraftforge.fml.relauncher.SideOnly;
 
- import net.minecraftforge.registries.IForgeRegistry;
 
 
- import java.util.Objects;
 
 
- @EventBusSubscriber
 
- public class ItemRegistryHandler
 
- {
 
-     public static final ItemCopperGrains COPPER_GRAINS = new ItemCopperGrains();
 
 
-     @SubscribeEvent
 
-     public static void onRegistry(Register<Item> event)
 
-     {
 
-         IForgeRegistry<Item> registry = event.getRegistry();
 
-         registry.register(COPPER_GRAINS);
 
-     }
 
-     @SubscribeEvent
 
-     @SideOnly(Side.CLIENT)
 
-     public static void onModelRegistry(ModelRegistryEvent event)
 
-     {
 
-         ModelLoader.setCustomModelResourceLocation(COPPER_GRAINS,0,
 
-         new ModelResourceLocation(Objects.requireNonNull(COPPER_GRAINS.getRegistryName()), "inventory"));
 
-     }
 
- }
 
- package zzzz.zxmod;
 
 
- import net.minecraft.init.Blocks;
 
- import net.minecraftforge.fml.common.Mod;
 
- import net.minecraftforge.fml.common.Mod.EventHandler;
 
- import net.minecraftforge.fml.common.event.FMLInitializationEvent;
 
- import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
 
- import org.apache.logging.log4j.Logger;
 
 
- @Mod(modid = ZxMod.MODID, name = ZxMod.NAME, version = ZxMod.VERSION, acceptedMinecraftVersions = "[1.12,1.13)")
 
- public class ZxMod
 
- {
 
-     public static final String MODID = "zxmod";
 
-     public static final String NAME = "Zx Mod";
 
-     public static final String VERSION = "1.0";
 
 
-     private static Logger logger;
 
 
-     @EventHandler
 
-     public void preInit(FMLPreInitializationEvent event)
 
-     {
 
-         logger = event.getModLog();
 
-     }
 
 
-     @EventHandler
 
-     public void init(FMLInitializationEvent event)
 
-     {
 
-         // some example code
 
-         logger.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
 
-     }
 
- }
 
文件目录
 
 本帖最后由 苍穹空 于 2022-2-8 20:33 编辑 
这一看就是土球的读者
所以我直接给你对着书看了一遍
首先我希望代码里的中文逗号是格式转换的锅,而不是你在代码里打了中文逗号
然后
public static void onModelRegistry(ModelRegistryEvent event)
{
ModelLoader.setCustomModelResourceLocation(COPPER_GRAINS,0,
new ModelResourceLocation(Objects.requireNonNull(COPPER_GRAINS.getRegistryName()), "inventory"));
这一块跟书里的不一样(当然我也不知道你在干嘛,毕竟不是正儿八经的mod开发者 )
)
书上咋写的你手上应该有,感觉你搞了个错误的替代了
在游戏里/give 你的名字 modid 冒号 tab补全
看看这样能不能查到物品
(虽然我不能理解为什么铜粒要加复数)
最后,我电脑坏了,手机上看的,如果我的帮助无法帮到你,不用回复
因为我也不会
啊啊啊隐藏代码我没记下来不然我肯定隐藏
这边建议去下一些mod的源码看看那些大佬是怎么做的,但是无尽贪婪,拔刀剑,潘马斯这些不建议一般人去看👀
这一看就是土球的读者
所以我直接给你对着书看了一遍
首先我希望代码里的中文逗号是格式转换的锅,而不是你在代码里打了中文逗号
然后
public static void onModelRegistry(ModelRegistryEvent event)
{
ModelLoader.setCustomModelResourceLocation(COPPER_GRAINS,0,
new ModelResourceLocation(Objects.requireNonNull(COPPER_GRAINS.getRegistryName()), "inventory"));
这一块跟书里的不一样(当然我也不知道你在干嘛,毕竟不是正儿八经的mod开发者
书上咋写的你手上应该有,感觉你搞了个错误的替代了
在游戏里/give 你的名字 modid 冒号 tab补全
看看这样能不能查到物品
(虽然我不能理解为什么铜粒要加复数)
最后,我电脑坏了,手机上看的,如果我的帮助无法帮到你,不用回复
这边建议去下一些mod的源码看看那些大佬是怎么做的,但是无尽贪婪,拔刀剑,潘马斯这些不建议一般人去看👀
 本帖最后由 wszhxwsz 于 2022-2-9 13:13 编辑 
tab是真的好用,查到了,谢谢大佬,s的话,我会自行修改的
苍穹空 发表于 2022-2-8 20:31
这一看就是土球的读者
所以我直接给你对着书看了一遍
首先我希望代码里的中文逗号是格式转换的锅, ...
tab是真的好用,查到了,谢谢大佬,s的话,我会自行修改的
wszhxwsz 发表于 2022-2-9 12:49
tab是真的好用,查到了,谢谢大佬,s的话,我会自行修改的
写一个创造模式物品栏一劳永逸