Appendix A. Additional Code Fragments

This appendix provides a variety of code fragments that you might need when writing your mod. It includes custom blocks, entity AI, and the code for a completely custom dimension.

Configs

Configs can be used to make your mod more configurable. Listing A.1 shows an example of a Config class.

LISTING A.1 A Config Example

package com.wuppy.samsmod;import net.minecraftforge.common.config.Configuration;import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;public class Config{       public static boolean spawnSamDungeon = true;       public static void loadConfig(FMLPreInitializationEvent event)       {               Configuration config = new Configuration(event.getSuggestedConfigurationFile()); ...

Get Sams Teach Yourself Mod Development for Minecraft in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.