First I am making a new topic on this because I feel like forge has changed a lot since 1.13 and a lot isn't the same as all the tutorials out there.
So back in the days I always wanted to make (minecraft) mods, now some years later I am finally a professional programmer so I thought let's take another shot at it in my free hours.
I've watched some tutorials with forge 1.13 and up and I noticed that a lot of these guys keep static references everywhere which in my opinion is very bad practice. For example if you would develop for Android then a static reference will almost always fall out of context at some point and cause crashes. I watched these tutorials and started making a starter mod with some basic item(s).
This is how I initialize the mod which is nothing special but then I have an `ItemList` class where I would keep all my items which I init from the EventBusSubscriber.
Then I get an instance of every item within it's class so I can keep item properties like group in it's own class to keep my code organized. I hate it when I would have to put half of the settings within the class and the others in ItemList.
So for the more experienced modders out there. What do you think about below approach and how could I improve it. Also I would like to know more about how you guys did it. I feel like the documentation is really outdated and incomplete.
Code below:
@Mod("xiocraft")
public class XioCraftMod
{
public static XioCraftMod instance;
public static final String ID = "xiocraft";
private static final Logger LOGGER = LogManager.getLogger();
public XioCraftMod()
{
instance = this;
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientRegistries);
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event)
{
}
private void clientRegistries(final FMLClientSetupEvent event)
{
}
@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
@SubscribeEvent
public static void registerBlocks(final RegistryEvent.Register<Block> event)
{
}
@SubscribeEvent
public static void registerItems(final RegistryEvent.Register<Item> event)
{
ItemList.register(event);
}
}
}
public class ItemList {
public static Item dough;
public static Item lahmacun;
public static void register(final RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(
dough = DoughItem.getInstance(),
lahmacun = LahmacunItem.getInstance()
);
}
}
public class DoughItem extends Item {
public static final String ID = "dough";
public DoughItem(Properties properties) {
super(properties);
}
public static Item getInstance() {
return new DoughItem(
new Item.Properties()
.group(ItemGroup.FOOD)
)
.setRegistryName(new ResourceLocation(XioCraftMod.ID, DoughItem.ID));
}
}