-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use FRAPI SpriteFinder and remove resource reloader
- Loading branch information
Showing
9 changed files
with
42 additions
and
198 deletions.
There are no files selected for viewing
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
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
137 changes: 0 additions & 137 deletions
137
common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/BlockSpriteFinder.java
This file was deleted.
Oops, something went wrong.
32 changes: 10 additions & 22 deletions
32
common/src/main/java/net/caffeinemc/mods/sodium/client/render/texture/SpriteFinderCache.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 |
---|---|---|
@@ -1,38 +1,26 @@ | ||
package net.caffeinemc.mods.sodium.client.render.texture; | ||
|
||
import net.caffeinemc.mods.sodium.mixin.core.render.texture.TextureAtlasAccessor; | ||
import net.fabricmc.fabric.api.renderer.v1.model.SpriteFinder; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.renderer.texture.TextureAtlas; | ||
import net.minecraft.client.resources.model.ModelManager; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.resources.ResourceManager; | ||
import net.minecraft.server.packs.resources.ResourceManagerReloadListener; | ||
|
||
/** | ||
* Caches {@link BlockSpriteFinder}s for maximum efficiency. They must be refreshed after each resource reload. | ||
* Caches {@link SpriteFinder}s for maximum efficiency. They must be refreshed after each resource reload. | ||
* | ||
* <p><b>This class should not be used during a resource reload</b>, as returned SpriteFinders may be null or outdated. | ||
*/ | ||
public class SpriteFinderCache { | ||
private static BlockSpriteFinder blockAtlasSpriteFinder; | ||
private static SpriteFinder blockAtlasSpriteFinder; | ||
|
||
public static SpriteFinder forBlockAtlas() { | ||
if (blockAtlasSpriteFinder == null) { | ||
blockAtlasSpriteFinder = SpriteFinder.get(Minecraft.getInstance().getModelManager().getAtlas(TextureAtlas.LOCATION_BLOCKS)); | ||
} | ||
|
||
public static BlockSpriteFinder forBlockAtlas() { | ||
return blockAtlasSpriteFinder; | ||
} | ||
|
||
public static class ReloadListener implements ResourceManagerReloadListener { | ||
public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("sodium", "sprite_finder_cache"); | ||
public static final ReloadListener INSTANCE = new ReloadListener(); | ||
|
||
private ReloadListener() { | ||
} | ||
|
||
// BakedModelManager#getAtlas only returns correct results after the BakedModelManager is done reloading | ||
@Override | ||
public void onResourceManagerReload(ResourceManager manager) { | ||
ModelManager modelManager = Minecraft.getInstance().getModelManager(); | ||
TextureAtlas atlas = modelManager.getAtlas(TextureAtlas.LOCATION_BLOCKS); | ||
blockAtlasSpriteFinder = new BlockSpriteFinder(((TextureAtlasAccessor) atlas).getTexturesByName(), atlas); | ||
} | ||
public static void resetSpriteFinder() { | ||
blockAtlasSpriteFinder = null; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
common/src/main/java/net/caffeinemc/mods/sodium/mixin/core/render/TextureAtlasMixin.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,26 @@ | ||
package net.caffeinemc.mods.sodium.mixin.core.render; | ||
|
||
import net.caffeinemc.mods.sodium.client.render.texture.SpriteFinderCache; | ||
import net.minecraft.client.renderer.texture.SpriteLoader; | ||
import net.minecraft.client.renderer.texture.TextureAtlas; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(TextureAtlas.class) | ||
public class TextureAtlasMixin { | ||
@Shadow | ||
@Final | ||
private ResourceLocation location; | ||
|
||
@Inject(method = "upload", at = @At("RETURN")) | ||
private void sodium$deleteSpriteFinder(SpriteLoader.Preparations preparations, CallbackInfo ci) { | ||
if (this.location.equals(TextureAtlas.LOCATION_BLOCKS)) { | ||
SpriteFinderCache.resetSpriteFinder(); | ||
} | ||
} | ||
} |
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
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