-
-
Save Commoble/ffa5c45e74e77aa7b9e2cc5dbeca2f9f to your computer and use it in GitHub Desktop.
Subscribing to Client Events in Forge for Minecraft 1.15
This file contains 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
// The value here should match an entry in the META-INF/mods.toml file | |
@Mod(YourMod.MODID) | |
public class YourMod | |
{ | |
public static final String MODID = "yourmod"; | |
public YourMod() | |
{ | |
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus(); | |
IEventBus forgeBus = MinecraftForge.EVENT_BUS; | |
// use a layer of indirection when subscribing client events to avoid classloading client classes on server | |
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> ClientEventHandler.subscribeClientEvents(modBus, forgeBus)); | |
} | |
} | |
// this should be in a separate class somewhere! not the same class | |
public class ClientEventHandler | |
{ | |
// use addListener to subscribe whatever client events you need | |
// check out net.minecraftforge.client.event for most of the client-only events | |
public static void subscribeClientEvents(IEventBus modBus, IEventBus forgeBus) | |
{ | |
modBus.addListener(ClientEventHandler::onRegisterParticleFactories); | |
modBus.addListener(ClientEventHandler::onClientSetup); | |
} | |
private static void onRegisterParticleFactories(ParticleFactoryRegisterEvent event) | |
{ | |
Minecraft.getInstance().particles.registerFactory(MyParticleTypeDeferredRegistry.DUNGEON_PORTAL.get(), DungeonPortalParticle.Factory::new); | |
} | |
private static void onClientSetup(FMLClientSetupEvent event) | |
{ | |
// register entity and tile entity renderers here, set render layers of blocks | |
RenderingRegistry.registerEntityRenderingHandler(MyEntitityDeferredRegistry.UNRELENTING_CUBE.get(), UnrelentingCubeEntityRenderer::new); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment