This chapter is from the book
Workshop
You now know the basics of items. In the next few hours, you will learn more about them. Therefore, it’s important to fully understand the basics. To do that, you might want to work through this workshop.
Quiz
- What would the best unlocalized name be for an item variable called alarmClock?
What is wrong with the following code?
public static
Itemkey
; @EventHandlerpublic void
preInit(FMLPreInitializationEvent event) { GameRegistry.registerItem(key,“Key”
);key
=new
ItemKey(); }
Answers
- The best unlocalized name is alarmClock, because it’s generally smartest to use the variable name.
- The item is registered before initializing it to something. This will crash your mod. Always make sure the registerItem method is below the Item init line.