Last active
September 17, 2019 17:17
-
-
Save Commoble/390caa58390e42d156b3e8ec351b3ccf to your computer and use it in GitHub Desktop.
This Is How Commoble Registers Things in Forge for Minecraft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Helper class that we use to register things | |
*/ | |
public class Registrator<T extends IForgeRegistryEntry<T>> | |
{ | |
public IForgeRegistry<T> registry; | |
public Registrator(IForgeRegistry<T> registry) | |
{ | |
this.registry = registry; | |
} | |
public T register(String registryKey, T entry) | |
{ | |
entry.setRegistryName(new ResourceLocation(DungeonFist.MODID, registryKey)); | |
registry.register(entry); | |
return entry; | |
} | |
} | |
/** | |
* In this class we keep all of the MOD events that fire during init for both sides, | |
* particularly registry events | |
*/ | |
@EventBusSubscriber(modid = DungeonFist.MODID, bus = Bus.MOD) | |
public class CommonModEventHandler | |
{ | |
@SubscribeEvent | |
public static void onBlockRegistryEvent(RegistryEvent.Register<Block> event) | |
{ | |
BlockRegistrar.registerBlocks(getRegistrator(event)); | |
} | |
public static <T extends IForgeRegistryEntry<T>> Registrator<T> getRegistrator(RegistryEvent.Register<T> event) | |
{ | |
return new Registrator<T>(event.getRegistry()); | |
} | |
} | |
/** | |
* Class for registering blocks and holding their references | |
*/ | |
@ObjectHolder(DungeonFist.MODID) | |
public class BlockRegistrar | |
{ | |
@ObjectHolder(DungeonFist.DUNGEON_PORTAL) | |
public static final Block DUNGEON_PORTAL = null; | |
@ObjectHolder(DungeonFist.DUNGEON_PORTAL_GLOWY_AIR) | |
public static final Block DUNGEON_PORTAL_GLOWY_AIR = null; | |
// register all the blocks, called by RegistryEventHandler | |
public static void registerBlocks(Registrator<Block> reg) | |
{ | |
reg.register(DungeonFist.DUNGEON_PORTAL, new DungeonPortalBlock(Block.Properties.create(Material.PORTAL).doesNotBlockMovement().hardnessAndResistance(-1.0F).sound(SoundType.GLASS).lightValue(11).noDrops())); | |
reg.register(DungeonFist.DUNGEON_PORTAL_GLOWY_AIR, new DungeonPortalGlowyAirBlock(Block.Properties.create(Material.PORTAL).doesNotBlockMovement().hardnessAndResistance(-1.0F).sound(SoundType.GLASS).lightValue(11).noDrops())); | |
} | |
} | |
// including this to make it more obvious that I'm using strings in places | |
@Mod(DungeonFist.MODID) | |
public class DungeonFist | |
{ | |
public static final String MODID = "dungeonfist"; | |
// object names | |
public static final String DUNGEON = "dungeon"; | |
public static final String DUNGEON_PORTAL = "dungeon_portal"; | |
public static final String DUNGEON_PORTAL_GLOWY_AIR = "dungeon_portal_glowy_air"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That's really nice
But very complicated