Chinese 1.4.7 Modding Tutorials: 第四章:基本物品

第四章:基本物品

在這次的教學,我會教你如何建立一個新的物品。
在這邊教學將會比較少地解釋在「基本方塊」已有的東西,
如果有一些不明白,可以回到前一章查看。
這次我會用這個主檔案開始:

package Tutorial;

importnet.minecraft.block.Block;
importnet.minecraft.item.Item;
importcpw.mods.fml.common.Mod;
importcpw.mods.fml.common.Mod.Init;
importcpw.mods.fml.common.event.FMLInitializationEvent;
importcpw.mods.fml.common.network.NetworkMod;
importcpw.mods.fml.common.registry.GameRegistry;
importcpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = “Seer_TutorialMod”, name = “TutorialMod”, version = “1.0.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
publicclass Tutorial {
      
       publicstatic Block tutorialBlock;
      
       @Init
       publicvoid load(FMLInitializationEvent event)
       {
             TutorialBlock= newBlockTutorialBlock(250, 0).setBlockName(“tutorialBlock”);
            
             GameRegistry.registerBlock(tutorialBlock, “Tutorial_tutorialBlock”);
             LanguageRegistry.addName(tutorialBlock, “Tutorial Block”);
        
       }
}

首先我們需要和方塊一樣,加上下面這句:


publicstaticItem tutorialItem;


和方塊一樣,藍色部分可以改成你想用的名字。

然後在load方法內加上這句:

tutorialItem = newItemTutorialItem(251, 1).setItemName(“tutorialItem”);


同樣地,你需要把tutorialItem改成你剛剛改掉的藍色部分。

然後我們按錯誤標示,建立ItemTutorialItem檔案,一開始應該是這樣:

package Tutorial;

publicclass ItemTutorialItem {
}

我們首先在publicclass ItemTutorialItem後面加上extends Item

然後在括號裡面加上這個語法:

public ItemTutorialItem(int id, int texture)

        {
         super(id);

        }


和方塊不同的是,super(id);這句縮減了許多,也沒有了材質的選擇。

不過你也同樣可以用this.setCreativeTab(CreativeTabs.tabMaterials);這句
來把物品加入至創造模式分欄中。
到這邊,基本物品就完成了,這邊是整個物品檔案的編碼:

package Tutorial;

importnet.minecraft.creativetab.CreativeTabs;
importnet.minecraft.item.Item;
publicclass ItemTutorialItem extends Item{
      
       public ItemTutorialItem(int id, int texture)
        {
         super(id);
         this.setCreativeTab(CreativeTabs.tabMaterials);
        }
}

我們現在回到主檔案,比起方塊,物品不需要在load方法裡面register

所以我們只需要加上這句來設定顯示名字:

LanguageRegistry.addName(tutorialItem, “Tutorial Item”);


內容就不多講了,方塊教學有寫到,大家忘記了可以去看看。

到了這邊,物品的增加就差不多了。這邊是整個主檔案的內容:

package Tutorial;

importnet.minecraft.block.Block;
importnet.minecraft.item.Item;
importcpw.mods.fml.common.Mod;
importcpw.mods.fml.common.Mod.Init;
importcpw.mods.fml.common.event.FMLInitializationEvent;
importcpw.mods.fml.common.network.NetworkMod;
importcpw.mods.fml.common.registry.GameRegistry;
importcpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = “Seer_TutorialMod”, name = “TutorialMod”, version = “1.0.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
publicclass Tutorial {
      
       publicstatic Block tutorialBlock;
       publicstatic Item tutorialItem;
      
       @Init
       publicvoid load(FMLInitializationEvent event)
       {
             tutorialBlock= newBlockTutorialBlock(250, 0).setBlockName(“tutorialBlock”);
             tutorialItem = new ItemTutorialItem(251, 1).setItemName(“tutorialItem”);
            
             GameRegistry.registerBlock(tutorialBlock, “Tutorial_tutorialBlock”);
             LanguageRegistry.addName(tutorialBlock, “Tutorial Block”);
             LanguageRegistry.addName(tutorialItem, “Tutorial Item”);
       }

You can download the source code over here.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">