From 2e5c9e134f03e27671f4345854801246c8477b4d Mon Sep 17 00:00:00 2001 From: XFactHD Date: Tue, 31 Oct 2023 03:04:50 +0100 Subject: [PATCH] Collapse TextureStitchEvent into a single post-stitch event --- .../renderer/texture/TextureAtlas.java.patch | 2 +- .../neoforge/client/ClientHooks.java | 6 +- .../event/TextureAtlasStitchedEvent.java | 40 +++++++++ .../client/event/TextureStitchEvent.java | 85 ------------------- 4 files changed, 44 insertions(+), 89 deletions(-) create mode 100644 src/main/java/net/neoforged/neoforge/client/event/TextureAtlasStitchedEvent.java delete mode 100644 src/main/java/net/neoforged/neoforge/client/event/TextureStitchEvent.java diff --git a/patches/net/minecraft/client/renderer/texture/TextureAtlas.java.patch b/patches/net/minecraft/client/renderer/texture/TextureAtlas.java.patch index 97efb1c279..cc880b6619 100644 --- a/patches/net/minecraft/client/renderer/texture/TextureAtlas.java.patch +++ b/patches/net/minecraft/client/renderer/texture/TextureAtlas.java.patch @@ -5,7 +5,7 @@ this.animatedTextures = List.copyOf(list1); } + -+ net.neoforged.neoforge.client.ClientHooks.onTextureStitchedPost(this); ++ net.neoforged.neoforge.client.ClientHooks.onTextureAtlasStitched(this); } @Override diff --git a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java index 0d55bbd334..955e2bfb27 100644 --- a/src/main/java/net/neoforged/neoforge/client/ClientHooks.java +++ b/src/main/java/net/neoforged/neoforge/client/ClientHooks.java @@ -154,7 +154,7 @@ import net.neoforged.neoforge.client.event.RenderTooltipEvent; import net.neoforged.neoforge.client.event.ScreenEvent; import net.neoforged.neoforge.client.event.ScreenshotEvent; -import net.neoforged.neoforge.client.event.TextureStitchEvent; +import net.neoforged.neoforge.client.event.TextureAtlasStitchedEvent; import net.neoforged.neoforge.client.event.ToastAddEvent; import net.neoforged.neoforge.client.event.ViewportEvent; import net.neoforged.neoforge.client.event.sound.PlaySoundEvent; @@ -283,8 +283,8 @@ public static boolean renderSpecificFirstPersonArm(PoseStack poseStack, MultiBuf return NeoForge.EVENT_BUS.post(new RenderArmEvent(poseStack, multiBufferSource, packedLight, player, arm)).isCanceled(); } - public static void onTextureStitchedPost(TextureAtlas map) { - ModLoader.get().postEvent(new TextureStitchEvent.Post(map)); + public static void onTextureAtlasStitched(TextureAtlas atlas) { + ModLoader.get().postEvent(new TextureAtlasStitchedEvent(atlas)); } public static void onBlockColorsInit(BlockColors blockColors) { diff --git a/src/main/java/net/neoforged/neoforge/client/event/TextureAtlasStitchedEvent.java b/src/main/java/net/neoforged/neoforge/client/event/TextureAtlasStitchedEvent.java new file mode 100644 index 0000000000..be85c732ae --- /dev/null +++ b/src/main/java/net/neoforged/neoforge/client/event/TextureAtlasStitchedEvent.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.neoforge.client.event; + +import net.minecraft.client.renderer.texture.TextureAtlas; +import net.neoforged.bus.api.Event; +import net.neoforged.bus.api.ICancellableEvent; +import net.neoforged.fml.LogicalSide; +import net.neoforged.fml.event.IModBusEvent; +import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; +import org.jetbrains.annotations.ApiStatus; + +/** + * Fired after a texture atlas is stitched together and all textures therein have been loaded. + * + *

This event is not {@linkplain ICancellableEvent cancellable}, and does not {@linkplain HasResult have a result}.

+ * + *

This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus()} mod-specific event bus}, + * only on the {@linkplain LogicalSide#CLIENT logical client}.

+ * + * @see TextureAtlas + */ +public class TextureAtlasStitchedEvent extends Event implements IModBusEvent { + private final TextureAtlas atlas; + + @ApiStatus.Internal + public TextureAtlasStitchedEvent(TextureAtlas atlas) { + this.atlas = atlas; + } + + /** + * {@return the texture atlas} + */ + public TextureAtlas getAtlas() { + return atlas; + } +} diff --git a/src/main/java/net/neoforged/neoforge/client/event/TextureStitchEvent.java b/src/main/java/net/neoforged/neoforge/client/event/TextureStitchEvent.java deleted file mode 100644 index 214dca759e..0000000000 --- a/src/main/java/net/neoforged/neoforge/client/event/TextureStitchEvent.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) Forge Development LLC and contributors - * SPDX-License-Identifier: LGPL-2.1-only - */ - -package net.neoforged.neoforge.client.event; - -import net.minecraft.client.renderer.texture.TextureAtlas; -import net.neoforged.bus.api.Event; -import net.neoforged.fml.LogicalSide; -import net.neoforged.fml.event.IModBusEvent; -import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; -import org.jetbrains.annotations.ApiStatus; - -/** - * Fired after a texture atlas is stitched together. - * - * @see TextureStitchEvent.Post - * @see TextureAtlas - */ -public abstract class TextureStitchEvent extends Event implements IModBusEvent { - private final TextureAtlas atlas; - - @ApiStatus.Internal - public TextureStitchEvent(TextureAtlas atlas) { - this.atlas = atlas; - } - - /** - * {@return the texture atlas} - */ - public TextureAtlas getAtlas() { - return atlas; - } - - // Use atlas info JSON files instead - // /** - // *

Fired before a texture atlas is stitched together. - // * This can be used to add custom sprites to be stitched into the atlas.

- // * - // *

This event is not {@linkplain ICancellableEvent cancellable}, and does not {@linkplain HasResult have a result}.

- // * - // *

This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus()} mod-specific event bus}, - // * only on the {@linkplain LogicalSide#CLIENT logical client}.

- // */ - // public static class Pre extends TextureStitchEvent - // { - // private final Set sprites; - // - // @ApiStatus.Internal - // public Pre(TextureAtlas map, Set sprites) - // { - // super(map); - // this.sprites = sprites; - // } - // - // /** - // * Adds a sprite to be stitched into the texture atlas. - // * - // *

Callers should check that the atlas which the event is fired for is the atlas they wish to stitch the - // * sprite into, as otherwise they would be stitching the sprite into all atlases.

- // * - // * @param sprite the location of the sprite - // */ - // public boolean addSprite(ResourceLocation sprite) - // { - // return this.sprites.add(sprite); - // } - // } - - /** - * Fired after a texture atlas is stitched together and all textures therein has been loaded. - * - *

This event is not {@linkplain ICancellableEvent cancellable}, and does not {@linkplain HasResult have a result}.

- * - *

This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus()} mod-specific event bus}, - * only on the {@linkplain LogicalSide#CLIENT logical client}.

- */ - public static class Post extends TextureStitchEvent { - @ApiStatus.Internal - public Post(TextureAtlas map) { - super(map); - } - } -}