diff --git a/src/main/java/vazkii/botania/client/core/handler/SplashHandler.java b/src/main/java/vazkii/botania/client/core/handler/SplashHandler.java new file mode 100644 index 000000000..37b02d9bd --- /dev/null +++ b/src/main/java/vazkii/botania/client/core/handler/SplashHandler.java @@ -0,0 +1,58 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [2020-01-14, 01:26 (UTC+2)] + */ +package vazkii.botania.client.core.handler; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.ReloadListener; +import net.minecraft.client.util.Splashes; +import net.minecraft.profiler.IProfiler; +import net.minecraft.resources.IResourceManager; +import net.minecraft.resources.SimpleReloadableResourceManager; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.ParticleFactoryRegisterEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.ObfuscationReflectionHelper; +import vazkii.botania.common.core.handler.ConfigHandler; +import vazkii.botania.common.lib.LibMisc; + +import javax.annotation.Nonnull; +import java.util.Collections; +import java.util.List; + +@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = LibMisc.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) +public class SplashHandler { + // This is probably the best spot to add a splash listener. It's an event fired after splash reload listener + // is registered, but before resource reload happens. Doing the initial load ourselves is not effective, + // as we would do it before the splashes are added, and the list is cleared when adding. + @SubscribeEvent + public static void registerFactories(ParticleFactoryRegisterEvent event) { + ((SimpleReloadableResourceManager) Minecraft.getInstance().getResourceManager()).addReloadListener(new SplashResourceListener()); + } + + private static class SplashResourceListener extends ReloadListener> { + @Override + @Nonnull + protected List prepare(IResourceManager resourceManagerIn, IProfiler profilerIn) { + return Collections.emptyList(); + } + + @Override + protected void apply(List list, IResourceManager resourceManagerIn, IProfiler profilerIn) { + if (!ConfigHandler.CLIENT.splashesEnabled.get()) + return; + + Splashes splashes = Minecraft.getInstance().getSplashes(); + List splashList = ObfuscationReflectionHelper.getPrivateValue(Splashes.class, splashes, "field_215280_c"); //possibleSplashes + splashList.add("Do not feed bread to elves!"); + } + } +} diff --git a/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java b/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java index e8171086e..32f3b606f 100644 --- a/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java +++ b/src/main/java/vazkii/botania/common/core/handler/ConfigHandler.java @@ -40,6 +40,7 @@ public final class ConfigHandler { public final ForgeConfigSpec.BooleanValue debugInfo; public final ForgeConfigSpec.BooleanValue matrixMode; public final ForgeConfigSpec.BooleanValue referencesEnabled; + public final ForgeConfigSpec.BooleanValue splashesEnabled; public Client(ForgeConfigSpec.Builder builder) { useShaders = builder @@ -108,6 +109,9 @@ public final class ConfigHandler { referencesEnabled = builder .comment("Set this to false to disable the references in the flower tooltips. (You monster D:)") .define("references", true); + splashesEnabled = builder + .comment("Set this to false to disable Botania's splashes in the main menu.") + .define("splashes", true); } }