JAR snapshot Java JAR Minecraft Java mod JAR Minecraft Java 2012 Minecraft Minecraft 12 Java Minecraft Minecraft Java 2013 11 Devoxx4Kids http://devoxx4kids.org/usa/
xii D Devoxx4Kids Minecraft Minecraft Google Minecraft Minecraft wiki http://minecraft.gamepedia.com/minecraft_wiki YouTube A Minecraft Minecraft Forge TNT bouncy sponges zombie knights Forge
xiii Java keyword syntax class method annotation array Eclipse Java Italic URL Constant width Constant width bold Constant width italic 這個圖示代表一個提示或建議 這個圖示代表一般註釋 這個圖示代表警告或注意事項
第一章 Minecraft 方塊 blocks 材料 materials 3D 物品 item 工具 tools entities Minecraft monsters creepers Bosses A Minecraft 改造 modifications TNT 用戶端 client server 單人遊戲模式 singleplayer mode Minecraft 多人遊戲模式 multiplayer mode Minecraft Minecraft Minecraft Minecraft Forge
2 Java Development Kit Minecraft Forge Eclipse 你也可以跟著 YouTube 上的安裝說明影片來學習 (http://bit.ly/1bqmq2z) Java Notch Markus Notch Persson Notch Twitter @notch(http://twitter.com/notch) Java Minecraft Java Notch Java.png.gif.jpg.mov.mp4.oggy Java.java Java 原始 source Java 0 1 編譯 compile Java Java 開發工具 Java Development Kit 簡稱 JDK Java Java javac Java 編譯器.java binary.class.class Java compilation
3 java Java Java virtual machine 簡稱 JVM.class JVM interpretation jar.class archive.jar Minecraft Java.class JDK JAR Minecraft JDK JDK Oracle http://bit.ly/tea7ic http:// bit.ly/1estuoy JDK JDK Minecraft Forge Minecraft Forge Forge Bukkit ModLoader Forge Minecraft Forge http://files.minecraftforge.net/ 1.1 Minecraft 1-1 Forge 1.8 1-2
4 在本書編寫期間, 最新的 Forge 版本是 1.8, 這個版本可能會隨著書籍的出版或你開始閱讀的日期不同而有所變動 請跟著選取最適合的版本 本書的模組是以 Forge1.8 來製作 倘若之後 Forge 的版本不適用於本書的模組, 我們會更新本書, 以及 GitHub 上的原始碼, 附錄 C 則包含了 GitHub 原始碼的有關細節 1-2 Forge 1.2 1.8 Src AdFly Skip Ad ZIP Forge Installer Minecraft Forge library ZIP Minecraft Eclipse Eclipse integrated development environment 簡稱 IDE IDE package IDE Eclipse Eclipse Eclipse
5 Eclipse Eclipse http://www.eclipse.org/downloads/ 1-3 Window Windows 1-3 Eclipse Eclipse 的版本在撰寫本書時是 4.4.1 版, 它的版本有可能會隨著出版日 期以及你閱讀本書的時刻而有所變更 下載最新可取得的 Eclipse 版本是 沒有問題的 Eclipse Eclipse https://wiki.eclipse.org/eclipse/installation Eclipse Forge Eclipse Forge forge Windows Ctrl Esc Windows 8.0 8.1 R cmd Enter Command Prompt Mac command control Spotlight Spotlight Mac terminal Terminal Window Mac Forge
6 cd Desktop mkdir forge cd forge ZIP Mac Windows ZIP forge/ cd forge Windows dir Mac ls 1-4 dir ls 1-4 1-4 Forge 1-1 Forge 1-1 Forge workspace gradlew setupdecompworkspace eclipse Mac./gradlew gradlew 在執行這些指令前, 請確認你的電腦已連上網路了
7 1-1 5 30 BUILD SUCCESSFUL Minecraft Forge http://bit.ly/1nfdpvn 1.6.4 1.6.4 1.8 Execution failed for task ':deobfuscatejar'. > Java heap space Windows gradlew.bat Mac gradlew Windows Notepad notepad Enter... gradlew.bat Mac TextEdit Applications TextEdit... gradlew DEFAULT_JVM_OPTS="" DEFAULT_JVM_OPTS="-Xmx1024m" Minecraft Forge http://www. minecraftforge.net/forum/ Eclipse Eclipse Windows eclipse.exe Mac eclipse Eclipse Java Minecraft Forge 專案 Project 1-1
8 workspace workspace Eclipse 1-5 1-5 Browse... forge/ eclipse/ Open OK 確認你有選取 eclipse/ 檔案夾, 否則你將無法進入你的專案 OK Eclipse Eclipse 1-6
9 1-6 Eclipse Eclipse Package Explorer tab Eclipse Minecraft console X
10.java.class Java.java class Java Eclipse Minecraft/ 1-7 1-7 Eclipse Minecraft Forge JAR src/main/java Java com.example.examplemod ExampleMod.java Java Forge IDE Java 1-2
11 1-2 package com.example.examplemod; ❶ 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; @Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION) ❸ public class ExampleMod ❹ { public static final String MODID = "examplemod"; ❺ public static final String VERSION = "1.0"; } @EventHandler ❻ public void init(fmlinitializationevent event) ❼ { // ❽ System.out.println("DIRT BLOCK >> "+Blocks.dirt.getUnlocalizedName()); ❾ } Java keyword Java ❶ 套件 package Java package ; Java /example/ examplemod Java 套件可以讓邏輯上相關的類別群組在一起 這允許了相似的類別名稱可以在不同套件中使用 這好比像是在不同的桶子中搜尋不同的蠟筆一樣 如果沒有透過分類, 很難找出正確的蠟筆, 同樣的, 如果在多個套件中如果沒有組織好類別, 將會不容易做尋找 ❷ Java Java 導入 import
12 statement import Blocks net.minecraft.init net.minecraft.init.blocks Mod net.minecraftforge.fml.common net.mine craftforge.fml.common.mod ❸ @Mod Forge @ Java 註釋 annotation Java Forge Java element = @Mod modid version MODID VERSION 變數 variable ❹ Java Java class.java ExampleMod ExampleMod.java 範圍 scope { } ❺ MODID VERSION type MODID VERSION String = MODID examplemod VERSION 1.0 Java 是個大小寫有別的程式語言, 所以確認你的程式要跟本書上面的程式完全相同才行 舉例來說 String 的 S 如果你打成小寫, 那就會出現錯誤, 因為 string 不是一個 Java 類別,String 才是 因此 MODID 與 modid 分別是代表不同的變數 ❻ Forge listening events chat message 事件處理器 event
13 handler Forge @EventHandler ❼ Java 方法 method 名稱 init 參數 Parameter 參數名 型態 FMLInitializationEvent event ( ) 主體 Body { } Java 回傳型態 Return type caller void init Forge ❽ Java 註解 comment // /* */ ❾ Java System.out.println Minecraft ( ) DIRT BLOCK >> + Blocks.dirt.getUnlocalizedName()
14 Minecraft 1-8 1-8 Eclipse Minecraft javac java jar JDK Eclipse Forge Java JAR JAR Minecraft client launcher 1-9 1-9 Minecraft
15 Forge 1.8 Forge Eclipse 1-10 1-10 Eclipse 1-10 log Minecraft [Client thread/info] [STDOUT]: [com.example.examplemod.examplemod:init:18]: DIRT BLOCK >> tile.dirt Forge init Minecraft Forge Minecraft Eclipse Eclipse Java Minecraft