Skip to content

Commit

Permalink
Merge pull request #107 from dima-dencep/1.21.x/dev
Browse files Browse the repository at this point in the history
5.0.7
  • Loading branch information
dima-dencep authored Aug 10, 2024
2 parents b6978f1 + 29eae0a commit 8c47af8
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
game-version-filter: none
game-versions: |
${{ steps.read_property.outputs.minecraft_version }}
1.21.1
java: |
21
Expand Down Expand Up @@ -104,6 +105,7 @@ jobs:
game-version-filter: none
game-versions: |
${{ steps.read_property.outputs.minecraft_version }}
1.21.1
dependencies: |
cloth-config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@

public enum Type {
PROGRESS,
TEXT
TEXT,
TEXT_WITH_BACKGROUND
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package org.redlance.dima_dencep.mods.rrls.mixins;

import net.minecraft.client.gui.components.FocusableTextWidget;
import net.minecraft.network.chat.Component;
import org.redlance.dima_dencep.mods.rrls.ConfigExpectPlatform;
import org.redlance.dima_dencep.mods.rrls.config.Type;
import org.redlance.dima_dencep.mods.rrls.utils.DummyGuiGraphics;
Expand All @@ -20,6 +22,7 @@
import org.spongepowered.asm.mixin.Final;
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.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
Expand Down Expand Up @@ -48,6 +51,9 @@ private static int replaceAlpha(int color, int alpha) {
return 0;
}

@Unique
private FocusableTextWidget rrls$textWidget;

@Inject(
method = "<init>",
at = @At(
Expand All @@ -56,6 +62,9 @@ private static int replaceAlpha(int color, int alpha) {
)
private void rrls$init(Minecraft client, ReloadInstance reload, Consumer<Optional<Throwable>> onFinish, boolean fadeIn, CallbackInfo ci) {
rrls$setState(OverlayHelper.lookupState(client.screen, fadeIn));

if (ConfigExpectPlatform.type() == Type.TEXT_WITH_BACKGROUND)
rrls$textWidget = new FocusableTextWidget(1, Component.literal(ConfigExpectPlatform.reloadText()), minecraft.font, 12);
}

@Override
Expand All @@ -75,9 +84,40 @@ private static int replaceAlpha(int color, int alpha) {
minecraft.font, ConfigExpectPlatform.reloadText(), i / 2, 70,
ConfigExpectPlatform.rgbProgress() ? ThreadLocalRandom.current().nextInt(0, 0xFFFFFF) : -1
);

case Type.TEXT_WITH_BACKGROUND -> {
if (rrls$textWidget != null) {
rrls$textWidget.setMaxWidth(i);
rrls$textWidget.setX(i / 2 - rrls$textWidget.getWidth() / 2);
rrls$textWidget.setY(j - j / 3);

if (ConfigExpectPlatform.rgbProgress())
rrls$textWidget.setColor(ThreadLocalRandom.current().nextInt(0, 0xFFFFFF));

// This will make sure the widget is rendered above other widgets in Pause screen
graphics.pose().pushPose();
graphics.pose().translate(0, 0,255);

rrls$textWidget.render(graphics, 0, 0, 0);

graphics.pose().popPose();
}
}
}
}

@Inject(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/Minecraft;setOverlay(Lnet/minecraft/client/gui/screens/Overlay;)V"
)
)
public void rrls$onLoadDone(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick, CallbackInfo ci)
{
this.rrls$textWidget = null;
}

@Inject(
method = "render",
at = @At(
Expand Down Expand Up @@ -174,7 +214,11 @@ private static int replaceAlpha(int color, int alpha) {
require = 0
)
public float rrls$changeAnimationSpeed(float instance) {
return ConfigExpectPlatform.animationSpeed();
if (!rrls$getState().isRendering()) {
return ConfigExpectPlatform.animationSpeed();
}

return instance;
}

@Override // YAY Conflicts!!!
Expand Down
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()
);
}
}
}

This file was deleted.

1 change: 0 additions & 1 deletion common/src/main/resources/rrls.accesswidener
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
accessWidener v2 named
extendable method net/minecraft/server/packs/resources/SimplePreparableReloadListener reload (Lnet/minecraft/server/packs/resources/PreparableReloadListener$PreparationBarrier;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;Lnet/minecraft/util/profiling/ProfilerFiller;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;
accessible method net/minecraft/client/gui/GuiGraphics flushIfUnmanaged ()V
extendable method net/minecraft/client/gui/GuiGraphics flushIfUnmanaged ()V
accessible method net/minecraft/client/gui/GuiGraphics flushIfManaged ()V
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/rrls.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"compat.OverlayMixin",
"compat.ServerPackManagerMixin",
"workaround.GuiGraphicsMixin",
"workaround.SimpleReloadInstanceMixin",
"workaround.ReloadableResourceManagerMixin",
"workaround.VertexBufferMixin",
"workaround.EntityRenderDispatcherMixin"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public NeoForgeLoadingOverlayMixin(Minecraft client, ReloadInstance monitor, Con
require = 0
)
public float rrls$changeAnimationSpeed(float instance) {
return ConfigExpectPlatform.animationSpeed();
if (!rrls$getState().isRendering()) {
return ConfigExpectPlatform.animationSpeed();
}

return instance;
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ org.gradle.parallel=true
minecraft_version = 1.21
parchment_version = 2024.07.28
loader_version = 0.16.0
forge_version = 21.0.146
forge_version = 21.0.167

# Mod Properties
mod_version = 5.0.6
mod_version = 5.0.7
maven_group = org.redlance.dima_dencep.mods
archives_base_name = rrls

Expand Down

0 comments on commit 8c47af8

Please sign in to comment.