Sams Teach Yourself Mod Development for Minecraft® in 24 Hours Editor-In-Chief Copyright © 2015 by Pearson Education, Inc
Total Page:16
File Type:pdf, Size:1020Kb
Jimmy Koene SamsTeachYourself Mod Development for Minecraft® in Hours24 800 East 96th Street, Indianapolis, Indiana, 46240 USA Sams Teach Yourself Mod Development for Minecraft® in 24 Hours Editor-in-Chief Copyright © 2015 by Pearson Education, Inc. Greg Wiegand All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or Executive Editor transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without Rick Kughen written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of Development Editor this book, the publisher and author assume no responsibility for errors or omissions. Nor is any Mark Renfrow liability assumed for damages resulting from the use of the information contained herein. Managing Editor ISBN-13: 978-0-672-33719-2 Kristy Hart ISBN-10: 0-672-33719-3 Senior Project Library of Congress Control Number: 2014943465 Editor Printed in the United States of America Betsy Gratner Copy Editor Second Printing: December 2014 Karen Annett Trademarks Indexer All terms mentioned in this book that are known to be trademarks or service marks have been Erika Millen appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or Proofreader service mark. Katie Matejka Minecraft is a trademark of Mojang Synergies / Notch Development AB. This book is not affiliated Technical Editors with or sponsored by Mojang Synergies / Notch Development AB LexManos Warning and Disclaimer Boris Minkin Every effort has been made to make this book as complete and as accurate as possible, but no Publishing warranty or fitness is implied. The information provided is on an “as is” basis. The author(s) and Coordinator the publisher shall have neither liability nor responsibility to any person or entity with respect to Kristen Watterson any loss or damages arising from the information contained in this book. Cover Designer Special Sales Mark Shirar For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, Senior Compositor training goals, marketing focus, or branding interests), please contact our corporate sales depart- Gloria Schurick ment at [email protected] or (800) 382-3419. For government sales inquiries, please contact [email protected]. For questions about sales outside the U.S., please contact [email protected]. Contents at a Glance Introduction .................................................................................... 1 Part I: Introduction HOUR 1 Setting Up the Minecraft Development Environment ........................... 7 2 Creating the Basics for Forge ........................................................... 21 3 Working with Recipes and Other Small Modifications ....................... 39 Part II: Items HOUR 4 Making Your First Item ................................................................... 53 5 Creating Multiple Items in a Smart Way .......................................... 67 6 Cooking Up a Food Item ................................................................. 83 7 Making Your Own Tools ................................................................. 95 8 Creating Armor ........................................................................... 111 Part III: Blocks HOUR 9 Making Your First Block ............................................................... 123 10 Creating Multiple Blocks in a Smart Way ...................................... 135 11 Making Your Blocks Unique .......................................................... 145 12 Creating a Tile Entity ................................................................... 175 Part IV: World Generation HOUR 13 Generating Ores .......................................................................... 195 14 Generating Plants ........................................................................ 207 15 Using MCEdit .............................................................................. 223 16 Generating Your Structure ............................................................ 231 Part V: Entities HOUR 17 Learning About Entities ................................................................ 245 18 Creating an Entity Model Using Techne ......................................... 253 iv Sams Teach Yourself Mod Development for Minecraft® in 24 Hours 19 Coding a Mob ............................................................................. 265 20 Creating a Throwable .................................................................. 283 Part VI: Final Pointers HOUR 21 Editing Vanilla Minecraft ............................................................. 297 22 Structuring Your Mod ................................................................... 311 23 Releasing Your Mod ..................................................................... 325 24 What’s Next ................................................................................ 333 APPENDIX A Additional Code Fragments ....................................................... 341 INDEX .................................................................................................. 395 Table of Contents Introduction 1 Who Should Read This Book ....................................................................... 1 How This Book Is Organized ....................................................................... 2 Conventions Used ...................................................................................... 4 Downloading the Code and Resources ......................................................... 5 Part I: Introduction HOUR 1: Setting Up the Minecraft Development Environment 7 Understanding How Minecraft Is Written and What You Will Do with It ........ 7 Learning About Forge ................................................................................. 8 Setting Up the JDK ..................................................................................... 9 Setting Up Eclipse ..................................................................................... 16 Setting Up Forge ....................................................................................... 16 Summary ................................................................................................ 19 Q&A ....................................................................................................... 19 Workshop ................................................................................................ 20 Exercises .................................................................................................. 20 HOUR 2: Creating the Basics for Forge 21 Understanding the Java in the ExampleMod ............................................... 21 Creating Your Own Package ..................................................................... 27 Creating Your Own Class File .................................................................... 31 Creating the Mod File ............................................................................... 34 Summary ................................................................................................ 35 Q&A ....................................................................................................... 35 Workshop ................................................................................................ 36 Exercises .................................................................................................. 36 vi Sams Teach Yourself Mod Development for Minecraft® in 24 Hours HOUR 3: Working with Recipes and Other Small Modifications 39 Learning About Recipes in Minecraft ......................................................... 39 Crafting a Recipe ..................................................................................... 40 Creating a Shapeless Recipe ...................................................................... 44 Creating a Smelting Recipe ....................................................................... 45 Using Special ItemStacks ........................................................................ 46 Changing the Mob Spawn in a Dungeon ................................................... 48 Changing Chest Items .............................................................................. 49 Examining the Results in the Mod File ....................................................... 49 Summary ................................................................................................ 51 Q&A ....................................................................................................... 51 Workshop ................................................................................................ 51 Exercises .................................................................................................. 52 Part II: Items HOUR 4: Making Your First Item 53 Understanding What an Item Is ................................................................ 53 Creating a Basic Item ............................................................................... 54 Summary ................................................................................................ 65 Q&A ......................................................................................................