-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an event to register custom sprite source types
- Loading branch information
1 parent
7357532
commit 3bc2c25
Showing
5 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
patches/net/minecraft/client/renderer/texture/atlas/SpriteSources.java.patch
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- a/net/minecraft/client/renderer/texture/atlas/SpriteSources.java | ||
+++ b/net/minecraft/client/renderer/texture/atlas/SpriteSources.java | ||
@@ -16,7 +16,7 @@ | ||
|
||
@OnlyIn(Dist.CLIENT) | ||
public class SpriteSources { | ||
- private static final BiMap<ResourceLocation, SpriteSourceType> TYPES = HashBiMap.create(); | ||
+ private static final BiMap<ResourceLocation, SpriteSourceType> TYPES = net.neoforged.neoforge.client.ClientHooks.makeSpriteSourceTypesMap(); | ||
public static final SpriteSourceType SINGLE_FILE = register("single", SingleFile.CODEC); | ||
public static final SpriteSourceType DIRECTORY = register("directory", DirectoryLister.CODEC); | ||
public static final SpriteSourceType FILTER = register("filter", SourceFilter.CODEC); |
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
49 changes: 49 additions & 0 deletions
49
src/main/java/net/neoforged/neoforge/client/event/RegisterSpriteSourceTypesEvent.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.client.event; | ||
|
||
import com.google.common.collect.BiMap; | ||
import com.mojang.serialization.Codec; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.texture.atlas.SpriteSource; | ||
import net.minecraft.client.renderer.texture.atlas.SpriteSourceType; | ||
import net.minecraft.resources.ResourceLocation; | ||
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; | ||
|
||
/** | ||
* Fired to allow mods to register their own {@linkplain SpriteSourceType}. This event is fired once during the construction of the {@link Minecraft} instance or before datagen when client datagen is enabled. | ||
* | ||
* <p>This event is not {@linkplain ICancellableEvent cancellable}, and does not {@linkplain HasResult have a result}.</p> | ||
* | ||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus}, | ||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p> | ||
*/ | ||
public class RegisterSpriteSourceTypesEvent extends Event implements IModBusEvent { | ||
private final BiMap<ResourceLocation, SpriteSourceType> types; | ||
|
||
public RegisterSpriteSourceTypesEvent(BiMap<ResourceLocation, SpriteSourceType> types) { | ||
this.types = types; | ||
} | ||
|
||
/** | ||
* Registers the given {@link Codec} as SpriteSourceType under the given id. | ||
* | ||
* @param id The id to register the {@link SpriteSourceType} under | ||
* @param codec The codec for the {@link SpriteSourceType} to register | ||
*/ | ||
public SpriteSourceType register(ResourceLocation id, Codec<? extends SpriteSource> codec) { | ||
if (this.types.containsKey(id)) { | ||
throw new IllegalStateException("Duplicate sprite source type registration " + id); | ||
} | ||
SpriteSourceType sourceType = new SpriteSourceType(codec); | ||
this.types.put(id, sourceType); | ||
return sourceType; | ||
} | ||
} |
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
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