-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's horrible, but it works, and it's wonderful Fixes #106 Maybe fix #90 (PepperCode1/Continuity#446)
- Loading branch information
1 parent
988e01d
commit 24a0360
Showing
5 changed files
with
140 additions
and
80 deletions.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
.../org/redlance/dima_dencep/mods/rrls/mixins/workaround/ReloadableResourceManagerMixin.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,138 @@ | ||
/* | ||
* Copyright 2023 - 2024 dima_dencep. | ||
* | ||
* Licensed under the Open Software License, Version 3.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* https://spdx.org/licenses/OSL-3.0.txt | ||
*/ | ||
|
||
package org.redlance.dima_dencep.mods.rrls.mixins.workaround; | ||
|
||
import com.google.common.collect.Lists; | ||
import net.minecraft.Util; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiSpriteManager; | ||
import net.minecraft.client.gui.font.FontManager; | ||
import net.minecraft.client.resources.SplashManager; | ||
import net.minecraft.client.resources.language.LanguageManager; | ||
import net.minecraft.server.packs.PackResources; | ||
import net.minecraft.server.packs.PackType; | ||
import net.minecraft.server.packs.resources.CloseableResourceManager; | ||
import net.minecraft.server.packs.resources.MultiPackResourceManager; | ||
import net.minecraft.server.packs.resources.PreparableReloadListener; | ||
import net.minecraft.server.packs.resources.ReloadInstance; | ||
import net.minecraft.server.packs.resources.ReloadableResourceManager; | ||
import net.minecraft.util.Unit; | ||
import net.minecraft.util.profiling.InactiveProfiler; | ||
import org.redlance.dima_dencep.mods.rrls.ConfigExpectPlatform; | ||
import org.redlance.dima_dencep.mods.rrls.Rrls; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Executor; | ||
import java.util.function.BiConsumer; | ||
|
||
@Mixin(ReloadableResourceManager.class) | ||
public class ReloadableResourceManagerMixin { | ||
@Shadow | ||
private CloseableResourceManager resources; | ||
|
||
@Unique | ||
private static final Minecraft RRLS$MINECRAFT = Minecraft.getInstance(); | ||
|
||
@Unique | ||
private final List<PreparableReloadListener> rrls$listeners = Lists.newArrayList(); | ||
|
||
@Inject( | ||
method = "registerReloadListener", | ||
at = @At( | ||
value = "TAIL" | ||
) | ||
) | ||
public void rrls$initReloader(PreparableReloadListener listener, CallbackInfo ci) { | ||
if (!ConfigExpectPlatform.hideType().forceClose()) { | ||
return; | ||
} | ||
|
||
if (listener instanceof FontManager fontManager && | ||
!fontManager.fontSets.containsKey(Minecraft.DEFAULT_FONT) | ||
) { | ||
rrls$reloadListener(fontManager, RRLS$MINECRAFT, | ||
(unused, throwable) -> rrls$refreshScreen() | ||
); | ||
} | ||
|
||
if (listener instanceof LanguageManager languageManager && | ||
languageManager.getLanguages().size() <= 1 | ||
) { | ||
rrls$reloadListener(languageManager, Util.backgroundExecutor(), (unused, throwable) -> {}); | ||
} | ||
|
||
if (listener instanceof SplashManager splashManager && | ||
splashManager.splashes.isEmpty() | ||
) { | ||
rrls$reloadListener(splashManager, Util.backgroundExecutor(), | ||
(unused, throwable) -> rrls$refreshScreen() | ||
); | ||
} | ||
|
||
if (listener instanceof GuiSpriteManager spriteManager && | ||
spriteManager.textureAtlas.texturesByName.isEmpty() | ||
) { | ||
rrls$reloadListener(spriteManager, RRLS$MINECRAFT, (unused, throwable) -> {}); | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "createReload", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/server/packs/resources/SimpleReloadInstance;create(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/util/List;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Z)Lnet/minecraft/server/packs/resources/ReloadInstance;" | ||
) | ||
) | ||
private void rrls$initReloaders(Executor backgroundExecutor, Executor gameExecutor, CompletableFuture<Unit> waitingFor, List<PackResources> resourcePacks, CallbackInfoReturnable<ReloadInstance> cir) { | ||
for (PreparableReloadListener listener : this.rrls$listeners) { | ||
rrls$reloadListener(listener, RRLS$MINECRAFT, (unused, throwable) -> {}); | ||
} | ||
this.rrls$listeners.clear(); | ||
} | ||
|
||
@Unique | ||
private void rrls$reloadListener(PreparableReloadListener listener, Executor gameExecutor, BiConsumer<Void, Throwable> action) { | ||
try { | ||
if (this.resources.getNamespaces().isEmpty()) { | ||
this.resources = new MultiPackResourceManager(PackType.CLIENT_RESOURCES, | ||
RRLS$MINECRAFT.getResourcePackRepository().openAllSelected() | ||
); | ||
} | ||
|
||
Rrls.LOGGER.info("Quick reload listener '{}'", listener.getName()); | ||
|
||
listener.reload( | ||
CompletableFuture::completedFuture, (ReloadableResourceManager) (Object) this, InactiveProfiler.INSTANCE, | ||
InactiveProfiler.INSTANCE, Util.backgroundExecutor(), gameExecutor | ||
).whenCompleteAsync(action, Util.backgroundExecutor()); | ||
|
||
} catch (Throwable th) { | ||
this.rrls$listeners.add(listener); | ||
} | ||
} | ||
|
||
@Unique | ||
private void rrls$refreshScreen() { | ||
if (ConfigExpectPlatform.reInitScreen() && RRLS$MINECRAFT.screen != null) { | ||
RRLS$MINECRAFT.screen.init(RRLS$MINECRAFT, | ||
RRLS$MINECRAFT.getWindow().getGuiScaledWidth(), RRLS$MINECRAFT.getWindow().getGuiScaledHeight() | ||
); | ||
} | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
.../java/org/redlance/dima_dencep/mods/rrls/mixins/workaround/SimpleReloadInstanceMixin.java
This file was deleted.
Oops, something went wrong.
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