Skip to content

Commit

Permalink
Ensure correct manager accessor interface is used on Forge
Browse files Browse the repository at this point in the history
  • Loading branch information
soir20 committed May 11, 2024
1 parent aa5615b commit 66e106f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import io.github.moremcmeta.moremcmeta.impl.client.io.TextureData;
import io.github.moremcmeta.moremcmeta.impl.client.io.TextureDataAssembler;
import io.github.moremcmeta.moremcmeta.impl.client.io.TextureDataReader;
import io.github.moremcmeta.moremcmeta.impl.client.mixin.TextureManagerAccessor;
import io.github.moremcmeta.moremcmeta.impl.client.resource.MetadataRegistryImpl;
import io.github.moremcmeta.moremcmeta.impl.client.resource.ModRepositorySource;
import io.github.moremcmeta.moremcmeta.impl.client.resource.OrderedResourceRepository;
Expand All @@ -58,6 +57,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.LoadingOverlay;
import net.minecraft.client.gui.screens.Overlay;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.MipmapGenerator;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
Expand Down Expand Up @@ -342,6 +342,13 @@ protected abstract StagedResourceReloadListener<Map<ResourceLocation, EventDrive
*/
protected abstract void startTicking(TextureManagerWrapper<EventDrivenTexture> texManager);

/**
* Get all textures currently registered with the texture manager.
* @param textureManager texture manager containing registered textures
* @return all registered textures
*/
protected abstract Map<ResourceLocation, AbstractTexture> allRegisteredTextures(TextureManager textureManager);

/**
* Divides the collection of all plugins into their separate subtypes.
* @param plugins the plugins to divide
Expand Down Expand Up @@ -635,10 +642,10 @@ private void addCompletedReloadCallback(TextureManagerWrapper<EventDrivenTexture

Optional<ReloadInstance> reloadInstance = reloadInstance(overlay.get(), logger);
reloadInstance.ifPresent((instance) -> instance.done().thenRun(() -> {
TextureManagerAccessor textureManager = (TextureManagerAccessor) Minecraft.getInstance().getTextureManager();
Map<ResourceLocation, AbstractTexture> allTextures = allRegisteredTextures(Minecraft.getInstance().getTextureManager());
SpriteFinder spriteFinder = new SpriteFinder(
(loc) -> new AtlasAdapter(loc, mipmapLevelGetter(logger)),
textureManager.moremcmeta_byPath().entrySet().stream()
allTextures.entrySet().stream()
.filter((entry) -> entry.getValue() instanceof TextureAtlas)
.map(Map.Entry::getKey)
.collect(Collectors.toSet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.LoadingOverlay;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -133,6 +134,11 @@ protected void startTicking(TextureManagerWrapper<EventDrivenTexture> texManager
ClientTickEvents.START_CLIENT_TICK.register((client) -> texManager.tick());
}

@Override
protected Map<ResourceLocation, AbstractTexture> allRegisteredTextures(TextureManager textureManager) {
return ((TextureManagerAccessor) textureManager).moremcmeta_byPath();
}

/**
* Retrieves all plugins with the given class.
* @param pluginClass the class of the plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.github.moremcmeta.moremcmeta.api.client.ClientPlugin;
import io.github.moremcmeta.moremcmeta.forge.api.client.MoreMcmetaClientPlugin;
import io.github.moremcmeta.moremcmeta.forge.impl.client.event.ClientTicker;
import io.github.moremcmeta.moremcmeta.forge.impl.client.mixin.TextureManagerAccessor;
import io.github.moremcmeta.moremcmeta.forge.impl.client.reflection.AnnotatedClassLoader;
import io.github.moremcmeta.moremcmeta.impl.client.MoreMcmeta;
import io.github.moremcmeta.moremcmeta.impl.client.resource.StagedResourceReloadListener;
Expand All @@ -31,6 +32,7 @@
import io.github.moremcmeta.moremcmeta.impl.client.texture.TexturePreparer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.LoadingOverlay;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.SpriteContents;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureManager;
Expand Down Expand Up @@ -169,4 +171,9 @@ protected void startTicking(TextureManagerWrapper<EventDrivenTexture> texManager
new ClientTicker(ImmutableList.of(texManager), MinecraftForge.EVENT_BUS, TickEvent.Phase.START, () -> true);
}

@Override
protected Map<ResourceLocation, AbstractTexture> allRegisteredTextures(TextureManager textureManager) {
return ((TextureManagerAccessor) textureManager).moremcmeta_byPath();
}

}

0 comments on commit 66e106f

Please sign in to comment.