From 99c1a4885b76e4e8e1cd6e74c67c829cb40ca8d3 Mon Sep 17 00:00:00 2001 From: TexTrue <65154269+TexBlock@users.noreply.github.com> Date: Sat, 20 Apr 2024 19:41:10 +0800 Subject: [PATCH] clean --- CHANGELOG.md | 4 +-- fabric/CHANGELOG.md | 4 +-- .../fabric/FabricEventHandler.java | 14 ++++++++ .../fabric/RyoamicLightsFabric.java | 7 +--- forge/CHANGELOG.md | 4 +-- .../forge/ForgeEventHandler.java | 32 +++++++++++++++++++ .../forge/RyoamicLightsForge.java | 27 +--------------- gradle.properties | 4 +-- 8 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 fabric/src/main/java/org/thinkingstudio/ryoamiclights/fabric/FabricEventHandler.java create mode 100644 forge/src/main/java/org/thinkingstudio/ryoamiclights/forge/ForgeEventHandler.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ca555c4..71b05693 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,2 @@ ## Changelog -- remove the mixin for embeddium (only forge) -- remove architectury dependency -- add keybind (press and hold the key) +- code clean diff --git a/fabric/CHANGELOG.md b/fabric/CHANGELOG.md index 6ca555c4..71b05693 100644 --- a/fabric/CHANGELOG.md +++ b/fabric/CHANGELOG.md @@ -1,4 +1,2 @@ ## Changelog -- remove the mixin for embeddium (only forge) -- remove architectury dependency -- add keybind (press and hold the key) +- code clean diff --git a/fabric/src/main/java/org/thinkingstudio/ryoamiclights/fabric/FabricEventHandler.java b/fabric/src/main/java/org/thinkingstudio/ryoamiclights/fabric/FabricEventHandler.java new file mode 100644 index 00000000..692d5069 --- /dev/null +++ b/fabric/src/main/java/org/thinkingstudio/ryoamiclights/fabric/FabricEventHandler.java @@ -0,0 +1,14 @@ +package org.thinkingstudio.ryoamiclights.fabric; + +import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; +import net.minecraft.client.MinecraftClient; +import org.thinkingstudio.ryoamiclights.RyoamicLights; + +public class FabricEventHandler { + public static void registerEvents() { + WorldRenderEvents.START.register(context -> { + MinecraftClient.getInstance().getProfiler().swap("dynamic_lighting"); + RyoamicLights.get().updateAll(context.worldRenderer()); + }); + } +} diff --git a/fabric/src/main/java/org/thinkingstudio/ryoamiclights/fabric/RyoamicLightsFabric.java b/fabric/src/main/java/org/thinkingstudio/ryoamiclights/fabric/RyoamicLightsFabric.java index ba1b4c4f..7011402b 100644 --- a/fabric/src/main/java/org/thinkingstudio/ryoamiclights/fabric/RyoamicLightsFabric.java +++ b/fabric/src/main/java/org/thinkingstudio/ryoamiclights/fabric/RyoamicLightsFabric.java @@ -20,8 +20,6 @@ import net.minecraft.resource.ResourceType; import net.minecraft.util.Identifier; import org.thinkingstudio.ryoamiclights.RyoamicLights; -import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; -import net.minecraft.client.MinecraftClient; import org.thinkingstudio.ryoamiclights.api.item.ItemLightSources; import org.thinkingstudio.ryoamiclights.fabric.api.DynamicLightsInitializer; @@ -48,9 +46,6 @@ public void reload(ResourceManager manager) { } }); - WorldRenderEvents.START.register(context -> { - MinecraftClient.getInstance().getProfiler().swap("dynamic_lighting"); - RyoamicLights.get().updateAll(context.worldRenderer()); - }); + FabricEventHandler.registerEvents(); } } diff --git a/forge/CHANGELOG.md b/forge/CHANGELOG.md index 6ca555c4..71b05693 100644 --- a/forge/CHANGELOG.md +++ b/forge/CHANGELOG.md @@ -1,4 +1,2 @@ ## Changelog -- remove the mixin for embeddium (only forge) -- remove architectury dependency -- add keybind (press and hold the key) +- code clean diff --git a/forge/src/main/java/org/thinkingstudio/ryoamiclights/forge/ForgeEventHandler.java b/forge/src/main/java/org/thinkingstudio/ryoamiclights/forge/ForgeEventHandler.java new file mode 100644 index 00000000..1a1ad45a --- /dev/null +++ b/forge/src/main/java/org/thinkingstudio/ryoamiclights/forge/ForgeEventHandler.java @@ -0,0 +1,32 @@ +package org.thinkingstudio.ryoamiclights.forge; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.resource.SynchronousResourceReloader; +import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; +import net.minecraftforge.client.event.RenderLevelStageEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.EventPriority; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import org.thinkingstudio.ryoamiclights.RyoamicLights; +import org.thinkingstudio.ryoamiclights.api.item.ItemLightSources; +import org.thinkingstudio.ryoamiclights.forge.api.DynamicLightsInitializerEvent; + +public class ForgeEventHandler { + public static void registerEvents() { + IEventBus forgeEventBus = MinecraftForge.EVENT_BUS; + IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); + + forgeEventBus.addListener(EventPriority.HIGHEST, event -> { + if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_TRIPWIRE_BLOCKS) { + MinecraftClient.getInstance().getProfiler().swap("dynamic_lighting"); + RyoamicLights.get().updateAll(event.getLevelRenderer()); + } + }); + modEventBus.addListener(EventPriority.HIGHEST, event -> { + event.registerReloadListener((SynchronousResourceReloader) ItemLightSources::load); + }); + + forgeEventBus.post(new DynamicLightsInitializerEvent()); + } +} diff --git a/forge/src/main/java/org/thinkingstudio/ryoamiclights/forge/RyoamicLightsForge.java b/forge/src/main/java/org/thinkingstudio/ryoamiclights/forge/RyoamicLightsForge.java index 631a2601..bb2036da 100644 --- a/forge/src/main/java/org/thinkingstudio/ryoamiclights/forge/RyoamicLightsForge.java +++ b/forge/src/main/java/org/thinkingstudio/ryoamiclights/forge/RyoamicLightsForge.java @@ -10,25 +10,14 @@ package org.thinkingstudio.ryoamiclights.forge; -import net.minecraft.client.MinecraftClient; -import net.minecraft.resource.SynchronousResourceReloader; import net.minecraftforge.client.ClientRegistry; import net.minecraftforge.client.ConfigGuiHandler; -import net.minecraftforge.client.event.RegisterClientReloadListenersEvent; -import net.minecraftforge.client.event.RenderLevelStageEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.EventPriority; -import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.IExtensionPoint; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.network.NetworkConstants; -import org.jetbrains.annotations.NotNull; import org.thinkingstudio.ryoamiclights.RyoamicLights; -import org.thinkingstudio.ryoamiclights.api.item.ItemLightSources; -import org.thinkingstudio.ryoamiclights.forge.api.DynamicLightsInitializerEvent; import org.thinkingstudio.ryoamiclights.gui.SettingsScreen; @Mod(RyoamicLights.NAMESPACE) @@ -41,7 +30,6 @@ public RyoamicLightsForge() { public void onInitializeClient() { ModLoadingContext context = ModLoadingContext.get(); - IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); RyoamicLights.get().clientInit(); @@ -49,20 +37,7 @@ public void onInitializeClient() { context.registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (a, b) -> true)); context.registerExtensionPoint(ConfigGuiHandler.ConfigGuiFactory.class, () -> new ConfigGuiHandler.ConfigGuiFactory((client, screen) -> new SettingsScreen(screen))); - modEventBus.addListener(EventPriority.HIGHEST, this::renderWorldLast); - modEventBus.addListener(EventPriority.HIGHEST, this::registerClientReloadListeners); - MinecraftForge.EVENT_BUS.post(new DynamicLightsInitializerEvent()); - } - - public void renderWorldLast(@NotNull RenderLevelStageEvent event) { - if (event.getStage() == RenderLevelStageEvent.Stage.AFTER_TRIPWIRE_BLOCKS) { - MinecraftClient.getInstance().getProfiler().swap("dynamic_lighting"); - RyoamicLights.get().updateAll(event.getLevelRenderer()); - } - } - - public void registerClientReloadListeners(RegisterClientReloadListenersEvent event) { - event.registerReloadListener((SynchronousResourceReloader) ItemLightSources::load); + ForgeEventHandler.registerEvents(); } } diff --git a/gradle.properties b/gradle.properties index 4a1837b9..5e427e26 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,14 +5,14 @@ enabled_platforms=fabric,forge quilt_mappings=1.18.2+build.26 archives_base_name=RyoamicLights -mod_version=0.2.1 +mod_version=0.2.2 maven_group=org.thinkingstudio.ryoamiclights fabric_loader_version=0.15.2 fabric_api_version=0.77.0+1.18.2 mod_menu_version=3.2.5 -forge_version=1.18.2-40.2.17 +forge_version=1.18.2-40.2.18 obsidianui_version=0.2.0+mc1.18.2