Skip to content

Commit

Permalink
Minecraft 1.16.5 backport
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Jul 28, 2024
1 parent ecd7fd0 commit a4c1fdf
Show file tree
Hide file tree
Showing 51 changed files with 611 additions and 166 deletions.
4 changes: 2 additions & 2 deletions build-logic/src/main/kotlin/dynamic_fps.java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ java {
withSourcesJar()

toolchain {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(8)
}
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"

javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(21)
languageVersion = JavaLanguageVersion.of(8)
}
}
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ maven_group = juliand665
archives_name = dynamic-fps

# File naming version
minecraft_version = 1.21.0
minecraft_version = 1.16.4
# Version for publishing
minecraft_version_min = 1.21
minecraft_version_max = 1.21
minecraft_version_min = 1.16.4
minecraft_version_max = 1.16.5

enabled_platforms=fabric,neoforge,quilt
enabled_platforms=fabric,quilt
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[versions]
minecraft = "1.21"
minecraft = "1.16.5"

# Platform libraries

fabric_loader = "0.15.10"
fabric_api = "0.100.1+1.21"
fabric_api = "0.29.4+1.16"

forge = "1.20.4-49.0.30"
forge = "1.16.5-36.2.41"

neoforge = "21.0.0-beta"
neoforge = "20.4.160-beta"

quilt_loader = "0.25.0"

Expand All @@ -18,8 +18,8 @@ battery = "1.1.0"

# Modding libraries

modmenu = "11.0.0-beta.1"
cloth_config = "15.0.127"
modmenu = "1.16.23"
cloth_config = "4.17.101"

mixinextras = "0.3.5"

Expand Down
14 changes: 11 additions & 3 deletions platforms/common/src/main/java/dynamic_fps/impl/DynamicFPSMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import dynamic_fps.impl.util.FallbackConfigScreen;
import dynamic_fps.impl.util.Logging;
import dynamic_fps.impl.feature.state.OptionHolder;
import dynamic_fps.impl.util.ModCompatHelper;
import dynamic_fps.impl.util.ResourceLocations;
import dynamic_fps.impl.util.Version;
import dynamic_fps.impl.feature.volume.SmoothVolumeHandler;
import dynamic_fps.impl.util.duck.DuckLoadingOverlay;
import dynamic_fps.impl.feature.state.WindowObserver;
import dynamic_fps.impl.service.Platform;
import dynamic_fps.impl.util.duck.DuckScreen;
import net.lostluma.battery.api.State;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -63,7 +65,7 @@ public static void init() {
doInit();

Platform platform = Platform.getInstance();
Version version = platform.getModVersion(Constants.MOD_ID).orElseThrow();
Version version = platform.getModVersion(Constants.MOD_ID).orElseThrow(RuntimeException::new);

Logging.getLogger().info("Dynamic FPS {} active on {}!", version, platform.getName());
}
Expand Down Expand Up @@ -174,7 +176,7 @@ public static boolean shouldShowToasts() {
}

public static boolean shouldShowLevels() {
return isDisabled() || !isLevelCoveredByOverlay();
return isDisabled() || !(isLevelCoveredByScreen() || isLevelCoveredByOverlay());
}

public static void onBatteryChargeChanged(int before, int after) {
Expand All @@ -196,11 +198,17 @@ public static void onBatteryStatusChanged(State before, State after) {
private static void doInit() {
// NOTE: Init battery tracker first here
// Since the idle handler queries it for info
ModCompatHelper.init();

BatteryTracker.init();
IdleHandler.init();
SmoothVolumeHandler.init();
}

private static boolean isLevelCoveredByScreen() {
return minecraft.screen != null && ((DuckScreen) minecraft.screen).dynamic_fps$rendersBackground();
}

private static void showNotification(String titleTranslationKey, String iconPath) {
if (!DynamicFPSConfig.INSTANCE.batteryTracker().notifications()) {
return;
Expand Down Expand Up @@ -243,7 +251,7 @@ public static void handleStateChange(PowerState previous, PowerState current) {
}

// The FOCUSED config doesn't have the user's actual vsync preference sadly ...
boolean enableVsync = current != PowerState.FOCUSED ? config.enableVsync() : minecraft.options.enableVsync().get();
boolean enableVsync = current != PowerState.FOCUSED ? config.enableVsync() : minecraft.options.enableVsync;

if (enableVsync != before.enableVsync()) {
minecraft.getWindow().updateVsync(enableVsync);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundSource;

import java.util.Locale;
Expand Down Expand Up @@ -64,7 +66,7 @@ public static Screen genConfigScreen(Screen parent) {
);

general.addEntry(
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
entryBuilder.startTextDescription(new TextComponent(" ")).build()
);

general.addEntry(
Expand Down Expand Up @@ -93,7 +95,7 @@ public static Screen genConfigScreen(Screen parent) {
);

general.addEntry(
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
entryBuilder.startTextDescription(new TextComponent(" ")).build()
);

VariableStepTransformer volumeTransformer = getVolumeStepTransformer();
Expand Down Expand Up @@ -125,7 +127,7 @@ public static Screen genConfigScreen(Screen parent) {
);

general.addEntry(
entryBuilder.startTextDescription(CommonComponents.SPACE).build()
entryBuilder.startTextDescription(new TextComponent(" ")).build()
);

BatteryTrackerConfig batteryTracker = config.batteryTracker();
Expand Down Expand Up @@ -219,7 +221,7 @@ public static Screen genConfigScreen(Screen parent) {

category.addEntry(
entryBuilder.startBooleanToggle(
Component.translatable("options.vsync"),
new TranslatableComponent("options.vsync"),
instance.enableVsync()
)
.setDefaultValue(standard.enableVsync())
Expand All @@ -239,7 +241,7 @@ public static Screen genConfigScreen(Screen parent) {

volumes.add(
entryBuilder.startIntSlider(
Component.translatable("soundCategory." + name),
new TranslatableComponent("soundCategory." + name),
(int) (instance.rawVolumeMultiplier(source) * 100),
0, 100
)
Expand All @@ -261,7 +263,7 @@ public static Screen genConfigScreen(Screen parent) {
.setDefaultValue(standard.graphicsState())
.setSaveConsumer(instance::setGraphicsState)
.setEnumNameProvider(ClothConfig::graphicsStateMessage)
.setTooltipSupplier(ClothConfig::graphicsStateTooltip)
.setTooltipSupplier(value -> graphicsStateTooltip((GraphicsState) value))
.build()
);

Expand Down Expand Up @@ -335,7 +337,7 @@ private static Component volumeTransitionMessage(int step) {
int value = getVolumeStepTransformer().toValue(step);

if (value <= 300) {
return Component.literal(value + "%");
return new TranslatableComponent(value + "%");
} else {
return localized("config", "volume_transition_speed_instant");
}
Expand All @@ -357,14 +359,14 @@ private static Component fpsTargetMessage(int step) {
int fps = getFpsTransformer().toValue(step);

if (fps != Constants.NO_FRAME_RATE_LIMIT) {
return Component.translatable("options.framerate", fps);
return new TranslatableComponent("options.framerate", fps);
} else {
return Component.translatable("options.framerateLimit.max");
return new TranslatableComponent("options.framerateLimit.max");
}
}

private static Component volumeMultiplierMessage(int value) {
return Component.literal(Integer.toString(value) + "%");
return new TranslatableComponent(Integer.toString(value) + "%");
}

public static Component IdleConditionMessage(Enum<IdleCondition> state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public static DynamicFPSConfig loadDefault() {
throw new IOException("Stream is null.");
}

data = stream.readAllBytes();
data = new byte[stream.available()];
stream.read(data, 0, stream.available());
} catch (IOException e) {
throw new RuntimeException("Failed to load Dynamic FPS config.", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package dynamic_fps.impl.config.option;

import net.minecraft.client.gui.GuiGraphics;
import com.mojang.blaze3d.platform.Window;

/**
* Screen corner to render the battery indicator in.
*/
public enum BatteryIndicatorPlacement {
TOP_LEFT(graphics -> new int[] {4, 4}),
TOP_RIGHT(graphics -> new int[] {graphics.guiWidth() - 47, 4}),
BOTTOM_LEFT(graphics -> new int[] {4, graphics.guiHeight() - 20}),
BOTTOM_RIGHT(graphics -> new int[] {graphics.guiWidth() - 47, graphics.guiHeight() - 20});
TOP_LEFT(window -> new int[] {4, 4}),
TOP_RIGHT(window -> new int[] {window.getGuiScaledWidth() - 47, 4}),
BOTTOM_LEFT(window -> new int[] {4, window.getGuiScaledHeight() - 20}),
BOTTOM_RIGHT(window -> new int[] {window.getGuiScaledWidth() - 47, window.getGuiScaledHeight() - 20});

private final DynamicPlacement placement;

BatteryIndicatorPlacement(DynamicPlacement placement) {
this.placement = placement;
}

public int[] get(GuiGraphics graphics) {
return this.placement.get(graphics);
public int[] get(Window window) {
return this.placement.get(window);
}

@FunctionalInterface
private interface DynamicPlacement {
int[] get(GuiGraphics graphics);
int[] get(Window window);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dynamic_fps.impl.feature.battery;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import dynamic_fps.impl.util.ResourceLocations;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;
import net.minecraft.network.chat.Component;
Expand All @@ -20,6 +22,8 @@ public class BatteryToast implements Toast {

private static BatteryToast queuedToast;

private static final Minecraft MINECRAFT = Minecraft.getInstance();

private static final ResourceLocation MOD_ICON = ResourceLocations.of("dynamic_fps", "textures/battery/toast/background_icon.png");
private static final ResourceLocation BACKGROUND_IMAGE = ResourceLocations.of("dynamic_fps", "textures/battery/toast/background.png");

Expand All @@ -43,7 +47,7 @@ public static void queueToast(Component title, ResourceLocation icon) {
}

@Override
public @NotNull Visibility render(GuiGraphics graphics, ToastComponent toastComponent, long currentTime) {
public @NotNull Visibility render(PoseStack poseStack, ToastComponent toastComponent, long currentTime) {
if (this.firstRender == 0) {
if (this == queuedToast) {
queuedToast = null;
Expand All @@ -54,15 +58,18 @@ public static void queueToast(Component title, ResourceLocation icon) {
this.description = localized("toast", "battery_charge", BatteryTracker.charge());
}

MINECRAFT.getTextureManager().bind(BACKGROUND_IMAGE);
// resource, x, y, z, ?, ?, width, height, width, height
graphics.blit(BACKGROUND_IMAGE, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());
GuiComponent.blit(poseStack, 0, 0, 0, 0.0f, 0.0f, this.width(), this.height(), this.width(), this.height());

graphics.blit(MOD_ICON, 2, 2, 0, 0.0f, 0.0f, 8, 8, 8, 8);
graphics.blit(this.icon, 8, 8, 0, 0.0f, 0.0f, 16, 16, 16, 16);
MINECRAFT.getTextureManager().bind(MOD_ICON);
GuiComponent.blit(poseStack, 2, 2, 0, 0.0f, 0.0f, 8, 8, 8, 8);
MINECRAFT.getTextureManager().bind(this.icon);
GuiComponent.blit(poseStack, 8, 8, 0, 0.0f, 0.0f, 16, 16, 16, 16);

graphics.drawString(toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315, false);
graphics.drawString(toastComponent.getMinecraft().font, this.description, 30, 18, -16777216, false);
GuiComponent.drawString(poseStack, toastComponent.getMinecraft().font, this.title, 30, 7, 0x5f3315);
GuiComponent.drawString(poseStack, toastComponent.getMinecraft().font, this.description, 30, 18, -16777216);

return currentTime - this.firstRender >= 5000.0 * toastComponent.getNotificationDisplayTimeMultiplier() ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
return currentTime - this.firstRender >= 5000.0 ? Toast.Visibility.HIDE : Toast.Visibility.SHOW;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void init() {
}
} else {
manager = temp; // Keep around to allow updating batteries
Thread.ofVirtual().name("refresh-battery").start(BatteryTracker::updateBatteries);
new Thread(BatteryTracker::updateBatteries, "refresh-battery").start();
}
}

Expand Down Expand Up @@ -127,7 +127,7 @@ private static void updateBatteries() {
updateState();

try {
Thread.sleep(updateInterval);
Thread.sleep(updateInterval.toMillis());
} catch (InterruptedException e) {
active = false;
Thread.currentThread().interrupt();
Expand Down
Loading

0 comments on commit a4c1fdf

Please sign in to comment.