-
Notifications
You must be signed in to change notification settings - Fork 56
Platform Helpers
Everything that differs between Fabric and (Neo)Forge, wrapped so your common code doesn't care.
This is the part that replaces Architectury and similar. Three classes:
-
PlatHelperfor common stuff: setup callbacks, side and mod queries, and factories for the vanilla classes whose constructors differ between loaders (spawn eggs, flower pots, particle types, block entity types, entity types). Also the Forge-only block and item hooks (burn time, flammability, food properties) emulated on Fabric. -
ClientHelperfor the client: registration callbacks for renderers, colors, particles, models, keybinds, shaders, item decorators, tooltip components, reload listeners. -
ForgeHelperfor Forge hooks with no Fabric equivalent. Safe to call anywhere, it does the vanilla thing when there's no Forge.
public static void init() {
// Forge/NeoForge only, must come first
// RegHelper.startRegisteringFor(modEventBus);
PlatHelper.addCommonSetup(MyMod::setup);
PlatHelper.addCommonSetupAsync(() -> { /* expensive, runs off thread */ });
if (PlatHelper.getPhysicalSide().isClient()) {
MyModClient.init();
}
}
private static void setup() {
// after registration is done
if (PlatHelper.isModLoaded("jei") && !PlatHelper.isDev()) {
RegHelper.registerItemBurnTime(Items.SKELETON_SKULL, 2);
}
}Tip
On Fabric you don't need separate client and server entry points with this. One init, one
getPhysicalSide() check, done.
Client side is the same shape, registration goes through small event objects:
public static void init() {
ClientHelper.addItemColorsRegistration(event -> event.register((stack, tint) -> 0, Items.POTION));
ClientHelper.addClientSetup(() -> ClientHelper.registerRenderType(Blocks.CYAN_STAINED_GLASS, RenderType.solid()));
}Examples: PlatHelperExample, ClientHelperExample
PlatHelper.openCustomMenu(player, provider, buf -> ...) opens a menu with extra data, which is
otherwise completely different on each loader.
ClientHelper.registerOptionalTexturePack(folder, name, defaultEnabled) gives you a built in
resource pack the player can toggle in the pack screen.
Basics Platform Helpers Registration Networking Events Configs Config Screen
Resources Runtime Resource Packs Texture Manipulation Resource Helpers Block Set API
Client Custom Models Item Rendering Rendered Textures Post Shaders GUI Toolkit Colors
World Block and Item Interfaces Additional Item Placements Improved Entities Fake Levels World Data Dispenser Behaviors
Utilities Codec Utilities Misc Helpers Commands
Datapacks Villagers Soft Fluids Map Markers Spawn Boxes Global Datapack Folder