From 075ea45cc30db4f9c267d61e07fb431fc536e8b6 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Fri, 27 Dec 2024 17:54:23 +0100 Subject: [PATCH] Don't expose some functions to the API --- .../viafabricplus/ViaFabricPlus.java | 13 +++++--- .../ProtocolTranslator.java | 2 +- .../viafabricplus/save/SaveManager.java | 30 +++++++++++++++++++ .../viafabricplus/api/ViaFabricPlusBase.java | 14 --------- build.gradle | 2 +- .../viafabricplus/ViaFabricPlusImpl.java | 14 +++------ .../viafabricplus/screen/VFPScreen.java | 4 +-- .../visuals/ViaFabricPlusVisuals.java | 10 +++++++ .../armor_hud/ArmorHudEmulation1_8.java | 3 +- .../GridItemSelectionScreen.java | 10 ++++--- 10 files changed, 65 insertions(+), 37 deletions(-) create mode 100644 api-legacy/src/main/java/de/florianmichael/viafabricplus/save/SaveManager.java rename {api/src => src}/main/java/com/viaversion/viafabricplus/screen/VFPScreen.java (98%) diff --git a/api-legacy/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/api-legacy/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 21e34d8f..0ec25a73 100644 --- a/api-legacy/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/api-legacy/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -21,7 +21,9 @@ package de.florianmichael.viafabricplus; +import de.florianmichael.viafabricplus.save.SaveManager; import de.florianmichael.viafabricplus.settings.SettingsManager; +import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.io.File; @@ -34,7 +36,10 @@ public class ViaFabricPlus { private static final ViaFabricPlus INSTANCE = new ViaFabricPlus(); + private final Logger logger = LogManager.getLogger("ViaFabricPlus-Legacy"); + private final SettingsManager settingsManager = new SettingsManager(); + private final SaveManager saveManager = new SaveManager(); @Deprecated public static ViaFabricPlus global() { @@ -43,7 +48,7 @@ public class ViaFabricPlus { @Deprecated public Logger getLogger() { - return com.viaversion.viafabricplus.ViaFabricPlus.getImpl().logger(); + return logger; } @Deprecated @@ -52,13 +57,13 @@ public class ViaFabricPlus { } @Deprecated - public Object getSettingsManager() { + public SettingsManager getSettingsManager() { return settingsManager; } @Deprecated - public Object getSaveManager() { - throw new IllegalArgumentException("ViaFabricPlus#getSaveManager is not supported anymore."); + public SaveManager getSaveManager() { + return saveManager; } } \ No newline at end of file diff --git a/api-legacy/src/main/java/de/florianmichael/viafabricplus/protocoltranslator/ProtocolTranslator.java b/api-legacy/src/main/java/de/florianmichael/viafabricplus/protocoltranslator/ProtocolTranslator.java index a1d23f3b..62f2ae40 100644 --- a/api-legacy/src/main/java/de/florianmichael/viafabricplus/protocoltranslator/ProtocolTranslator.java +++ b/api-legacy/src/main/java/de/florianmichael/viafabricplus/protocoltranslator/ProtocolTranslator.java @@ -54,7 +54,7 @@ public class ProtocolTranslator { @Deprecated public static UserConnection createDummyUserConnection(final ProtocolVersion clientVersion, final ProtocolVersion serverVersion) { - return ViaFabricPlus.getImpl().createDummyUserConnection(clientVersion, serverVersion); + throw new UnsupportedOperationException("This method is not supported anymore"); } @Deprecated diff --git a/api-legacy/src/main/java/de/florianmichael/viafabricplus/save/SaveManager.java b/api-legacy/src/main/java/de/florianmichael/viafabricplus/save/SaveManager.java new file mode 100644 index 00000000..c484d944 --- /dev/null +++ b/api-legacy/src/main/java/de/florianmichael/viafabricplus/save/SaveManager.java @@ -0,0 +1,30 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus + * Copyright (C) 2021-2024 the original authors + * - FlorianMichael/EnZaXD + * - RK_01/RaphiMC + * Copyright (C) 2023-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.florianmichael.viafabricplus.save; + +/** + * Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point. + */ +@Deprecated +public class SaveManager { + +} diff --git a/api/src/main/java/com/viaversion/viafabricplus/api/ViaFabricPlusBase.java b/api/src/main/java/com/viaversion/viafabricplus/api/ViaFabricPlusBase.java index 686b6c37..2ff5703e 100644 --- a/api/src/main/java/com/viaversion/viafabricplus/api/ViaFabricPlusBase.java +++ b/api/src/main/java/com/viaversion/viafabricplus/api/ViaFabricPlusBase.java @@ -51,13 +51,6 @@ public interface ViaFabricPlusBase { return 1; } - /** - * Get the logger for this mod. - * - * @return The logger - */ - Logger logger(); - /** * Get the root path of the mod. * @@ -103,13 +96,6 @@ public interface ViaFabricPlusBase { */ void setTargetVersion(final ProtocolVersion newVersion, final boolean revertOnDisconnect); - /** - * @param clientVersion The client version - * @param serverVersion The server version - * @return Creates a dummy UserConnection class with a valid protocol pipeline to emulate packets - */ - UserConnection createDummyUserConnection(final ProtocolVersion clientVersion, final ProtocolVersion serverVersion); - /** * @return the current UserConnection of the connection to the server, if the player isn't connected to a server it will return null */ diff --git a/build.gradle b/build.gradle index 29199a76..c20fce76 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ dependencies { modJij fabricApi.module("fabric-registry-sync-v0", project.fabric_api_version) // Sub projects, since they are Fabric mods as well (mainly to access the game code) we have to first - // implement the namedElements (raw output) to compile against, then include the mappedElements into the output jar1 + // implement the namedElements (raw output) to compile against, then include the mappedElements into the output jar implementation project(path: ":viafabricplus-api", configuration: "namedElements") implementation project(path: ":viafabricplus-api-legacy", configuration: "namedElements") implementation project(path: ":viafabricplus-visuals", configuration: "namedElements") diff --git a/src/main/java/com/viaversion/viafabricplus/ViaFabricPlusImpl.java b/src/main/java/com/viaversion/viafabricplus/ViaFabricPlusImpl.java index 99684d3e..b3b22d95 100644 --- a/src/main/java/com/viaversion/viafabricplus/ViaFabricPlusImpl.java +++ b/src/main/java/com/viaversion/viafabricplus/ViaFabricPlusImpl.java @@ -144,11 +144,6 @@ public final class ViaFabricPlusImpl implements ViaFabricPlusBase { // -------------------------------------------------------------------------------------------- // Proxy the most important/used internals to a general API point for mods - @Override - public Logger logger() { - return logger; - } - @Override public Path rootPath() { return path; @@ -179,11 +174,6 @@ public final class ViaFabricPlusImpl implements ViaFabricPlusBase { ProtocolTranslator.setTargetVersion(newVersion, revertOnDisconnect); } - @Override - public UserConnection createDummyUserConnection(ProtocolVersion clientVersion, ProtocolVersion serverVersion) { - return ProtocolTranslator.createDummyUserConnection(clientVersion, serverVersion); - } - @Override public UserConnection getPlayNetworkUserConnection() { return ProtocolTranslator.getPlayNetworkUserConnection(); @@ -269,4 +259,8 @@ public final class ViaFabricPlusImpl implements ViaFabricPlusBase { return NegativeItemUtil.getCount(stack); } + public Logger logger() { + return logger; + } + } diff --git a/api/src/main/java/com/viaversion/viafabricplus/screen/VFPScreen.java b/src/main/java/com/viaversion/viafabricplus/screen/VFPScreen.java similarity index 98% rename from api/src/main/java/com/viaversion/viafabricplus/screen/VFPScreen.java rename to src/main/java/com/viaversion/viafabricplus/screen/VFPScreen.java index 9207a3f9..dc6fb256 100644 --- a/api/src/main/java/com/viaversion/viafabricplus/screen/VFPScreen.java +++ b/src/main/java/com/viaversion/viafabricplus/screen/VFPScreen.java @@ -21,7 +21,7 @@ package com.viaversion.viafabricplus.screen; -import com.viaversion.viafabricplus.ViaFabricPlus; +import com.viaversion.viafabricplus.ViaFabricPlusImpl; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ConfirmLinkScreen; @@ -233,7 +233,7 @@ public class VFPScreen extends Screen { * @param next The screen which should be opened after the error screen is closed */ public static void showErrorScreen(final Text title, final Throwable throwable, final Screen next) { - ViaFabricPlus.getImpl().logger().error("Something went wrong!", throwable); + ViaFabricPlusImpl.INSTANCE.logger().error("Something went wrong!", throwable); final MinecraftClient client = MinecraftClient.getInstance(); client.execute(() -> client.setScreen(new NoticeScreen(() -> client.setScreen(next), title, Text.translatable("base.viafabricplus.something_went_wrong").append("\n" + throwable.getMessage()), Text.translatable("base.viafabricplus.cancel"), false))); diff --git a/visuals/src/main/java/com/viaversion/viafabricplus/visuals/ViaFabricPlusVisuals.java b/visuals/src/main/java/com/viaversion/viafabricplus/visuals/ViaFabricPlusVisuals.java index 4bf095a4..000fec5f 100644 --- a/visuals/src/main/java/com/viaversion/viafabricplus/visuals/ViaFabricPlusVisuals.java +++ b/visuals/src/main/java/com/viaversion/viafabricplus/visuals/ViaFabricPlusVisuals.java @@ -30,9 +30,15 @@ import com.viaversion.viafabricplus.visuals.features.classic_creative_menu.GridI import com.viaversion.viafabricplus.visuals.settings.VisualSettings; import net.minecraft.client.MinecraftClient; import net.raphimc.vialegacy.api.LegacyProtocolVersion; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ViaFabricPlusVisuals implements ViaFabricPlusLoadEntrypoint { + public static final ViaFabricPlusVisuals INSTANCE = new ViaFabricPlusVisuals(); + + private final Logger logger = LogManager.getLogger("ViaFabricPlus-Visuals"); + @Override public void onPlatformLoad(ViaFabricPlusBase platform) { UnicodeFontFix1_12_2.init(); @@ -55,4 +61,8 @@ public class ViaFabricPlusVisuals implements ViaFabricPlusLoadEntrypoint { })); } + public Logger logger() { + return logger; + } + } diff --git a/visuals/src/main/java/com/viaversion/viafabricplus/visuals/features/armor_hud/ArmorHudEmulation1_8.java b/visuals/src/main/java/com/viaversion/viafabricplus/visuals/features/armor_hud/ArmorHudEmulation1_8.java index e0da6973..587524dc 100644 --- a/visuals/src/main/java/com/viaversion/viafabricplus/visuals/features/armor_hud/ArmorHudEmulation1_8.java +++ b/visuals/src/main/java/com/viaversion/viafabricplus/visuals/features/armor_hud/ArmorHudEmulation1_8.java @@ -22,6 +22,7 @@ package com.viaversion.viafabricplus.visuals.features.armor_hud; import com.viaversion.viafabricplus.ViaFabricPlus; +import com.viaversion.viafabricplus.visuals.ViaFabricPlusVisuals; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Types; @@ -54,7 +55,7 @@ public final class ArmorHudEmulation1_8 { try { sendArmorUpdate(userConnection); } catch (Throwable t) { - ViaFabricPlus.getImpl().logger().error("Error sending armor update", t); + ViaFabricPlusVisuals.INSTANCE.logger().error("Error sending armor update", t); } } } else { diff --git a/visuals/src/main/java/com/viaversion/viafabricplus/visuals/features/classic_creative_menu/GridItemSelectionScreen.java b/visuals/src/main/java/com/viaversion/viafabricplus/visuals/features/classic_creative_menu/GridItemSelectionScreen.java index 45185207..0e9fc417 100644 --- a/visuals/src/main/java/com/viaversion/viafabricplus/visuals/features/classic_creative_menu/GridItemSelectionScreen.java +++ b/visuals/src/main/java/com/viaversion/viafabricplus/visuals/features/classic_creative_menu/GridItemSelectionScreen.java @@ -22,20 +22,22 @@ package com.viaversion.viafabricplus.visuals.features.classic_creative_menu; import com.viaversion.viafabricplus.ViaFabricPlus; -import com.viaversion.viafabricplus.screen.VFPScreen; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.registry.Registries; import net.minecraft.resource.featuretoggle.FeatureFlags; +import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; import java.util.ArrayList; import java.util.List; @SuppressWarnings("DataFlowIssue") -public final class GridItemSelectionScreen extends VFPScreen { +public final class GridItemSelectionScreen extends Screen { public static final GridItemSelectionScreen INSTANCE = new GridItemSelectionScreen(); @@ -48,7 +50,7 @@ public final class GridItemSelectionScreen extends VFPScreen { public ItemStack selectedItem = null; public GridItemSelectionScreen() { - super("Classic item selection", false); + super(Text.of("Classic item selection")); } @Override @@ -88,7 +90,7 @@ public final class GridItemSelectionScreen extends VFPScreen { this.client.player.getInventory().main.set(client.player.getInventory().selectedSlot, selectedItem); this.client.player.playerScreenHandler.sendContentUpdates(); - playClickSound(); + ClickableWidget.playClickSound(this.client.getSoundManager()); this.close(); } return super.mouseClicked(mouseX, mouseY, button);