diff --git a/build.gradle.kts b/build.gradle.kts index a5610c6..a6400ba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -20,8 +20,6 @@ preprocess { val forge11904 = createNode("1.19.4-forge", 1_19_04, "srg") val fabric11902 = createNode("1.19.2-fabric", 1_19_02, "yarn") val forge11902 = createNode("1.19.2-forge", 1_19_02, "srg") - val fabric11802 = createNode("1.18.2-fabric", 1_18_02, "yarn") - val forge11802 = createNode("1.18.2-forge", 1_18_02, "srg") fabric12101.link(neoforge12101) neoforge12101.link(neoforge12006) @@ -34,6 +32,4 @@ preprocess { fabric11904.link(forge11904) forge11904.link(forge11902) forge11902.link(fabric11902) - fabric11902.link(fabric11802) - fabric11802.link(forge11802) } diff --git a/settings.gradle.kts b/settings.gradle.kts index 5ba1d22..53bfd0e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -19,8 +19,6 @@ rootProject.name = "world-host" rootProject.buildFileName = "build.gradle.kts" listOf( - "1.18.2-forge", - "1.18.2-fabric", "1.19.2-forge", "1.19.2-fabric", "1.19.4-forge", diff --git a/src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java b/src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java index 4e002f5..fe61603 100644 --- a/src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java +++ b/src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java @@ -12,11 +12,7 @@ //$$ import java.util.UUID; //$$ import java.util.concurrent.CompletableFuture; //$$ import net.minecraft.client.resources.DefaultPlayerSkin; -//#if MC >= 1.19.2 //$$ import net.minecraft.core.UUIDUtil; -//#else -//$$ import net.minecraft.world.entity.player.Player; -//#endif //#endif // TODO: Remove in 1.20.2+ @@ -43,11 +39,7 @@ public static WHPlayerSkin fromSkinManager(SkinManager skinManager, GameProfile //$$ skinTexture = skinManager.registerTexture(skin, MinecraftProfileTexture.Type.SKIN); //$$ skinModel = skin.getMetadata("model"); //$$ } else { - //#if MC >= 1.19.2 - //$$ final UUID uuid = UUIDUtil.getOrCreatePlayerUUID(profile); - //#else - //$$ final UUID uuid = Player.createPlayerUUID(profile); - //#endif + //$$ final UUID uuid = UUIDUtil.getOrCreatePlayerUUID(profile); //$$ skinTexture = DefaultPlayerSkin.getDefaultSkin(uuid); //$$ skinModel = DefaultPlayerSkin.getSkinModelName(uuid); //$$ } diff --git a/src/main/java/io/github/gaming32/worldhost/WorldHost.java b/src/main/java/io/github/gaming32/worldhost/WorldHost.java index 7a00faf..ad31924 100644 --- a/src/main/java/io/github/gaming32/worldhost/WorldHost.java +++ b/src/main/java/io/github/gaming32/worldhost/WorldHost.java @@ -15,6 +15,7 @@ import io.github.gaming32.worldhost.gui.screen.FriendsScreen; import io.github.gaming32.worldhost.gui.screen.JoiningWorldHostScreen; import io.github.gaming32.worldhost.gui.screen.OnlineFriendsScreen; +import io.github.gaming32.worldhost.mixin.MinecraftAccessor; import io.github.gaming32.worldhost.origincheck.OriginCheckers; import io.github.gaming32.worldhost.plugin.FriendAdder; import io.github.gaming32.worldhost.plugin.InfoTextsCategory; @@ -47,6 +48,7 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentUtils; import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket; @@ -101,13 +103,6 @@ import static net.minecraft.commands.Commands.literal; -//#if MC >= 1.19.2 -import io.github.gaming32.worldhost.mixin.MinecraftAccessor; -//#else -//$$ import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; -//$$ import net.minecraft.world.entity.player.Player; -//#endif - //#if FABRIC import dev.isxander.mainmenucredits.MainMenuCredits; import net.fabricmc.api.ClientModInitializer; @@ -138,10 +133,8 @@ //$$ import net.neoforged.neoforge.client.gui.IConfigScreenFactory; //#elseif NEOFORGE //$$ import net.neoforged.neoforge.client.ConfigScreenHandler; -//#elseif MC >= 1.19.2 -//$$ import net.minecraftforge.client.ConfigScreenHandler; //#else -//$$ import net.minecraftforge.client.ConfigGuiHandler; +//$$ import net.minecraftforge.client.ConfigScreenHandler; //#endif //#endif @@ -264,12 +257,9 @@ public void onInitializeClient() { //$$ container.registerExtensionPoint( //#if MC >= 1.20.5 //$$ IConfigScreenFactory.class, (ignored, screen) -> new WorldHostConfigScreen(screen) - //#elseif MC >= 1.19.2 + //#else //$$ ConfigScreenHandler.ConfigScreenFactory.class, //$$ () -> new ConfigScreenHandler.ConfigScreenFactory((ignored, screen) -> new WorldHostConfigScreen(screen)) - //#else - //$$ ConfigGuiHandler.ConfigGuiFactory.class, - //$$ () -> new ConfigGuiHandler.ConfigGuiFactory((ignored, screen) -> new WorldHostConfigScreen(screen)) //#endif //$$ ); //$$ } @@ -301,7 +291,7 @@ private static void init(IOFunction assetGetter, Path modPath) { if (!nonstandardOrigins.isEmpty()) { LOGGER.warn("Found nonstandard download origins: {}", nonstandardOrigins); WHToast.builder("world-host.nonstandard_origin") - .description(Components.translatable( + .description(Component.translatable( "world-host.nonstandard_origin.desc", nonstandardOrigins.stream() .map(URI::getHost) @@ -318,11 +308,7 @@ private static void init(IOFunction assetGetter, Path modPath) { LOGGER.error("Failed to create cache directory", e); } profileCache = new GameProfileCache( - //#if MC >= 1.19.2 ((MinecraftAccessor)Minecraft.getInstance()).getAuthenticationService().createProfileRepository(), - //#else - //$$ new YggdrasilAuthenticationService(Minecraft.getInstance().getProxy()).createProfileRepository(), - //#endif CACHE_DIR.resolve("usercache.json").toFile() ); profileCache.setExecutor(Minecraft.getInstance()); @@ -634,7 +620,7 @@ public static void commandRegistrationHandler(CommandDispatcher= 1.20.0 () -> //#endif - Components.translatable( + Component.translatable( "world-host.worldhost.tempip.success", Components.copyOnClickText(protoClient.getUserIp() + ':' + port) ), @@ -646,9 +632,9 @@ public static void commandRegistrationHandler(CommandDispatcher style + ComponentUtils.wrapInSquareBrackets(Component.literal("/worldhost ip")).withStyle(style -> style .withColor(ChatFormatting.GREEN) .withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/worldhost ip")) ) @@ -789,8 +775,8 @@ public static void showFriendOrOnlineToast( @Nullable Runnable clickAction ) { profileFuture.thenAccept(profile -> - WHToast.builder(Components.translatable(title, profile.name())) - .description(Components.translatable(description)) + WHToast.builder(Component.translatable(title, profile.name())) + .description(Component.translatable(description)) .icon(profile.iconRenderer()) .clickAction(clickAction) .ticks(ticks) @@ -830,7 +816,7 @@ public static FriendlyByteBuf writeServerStatus(@Nullable ServerStatus metadata) public static ServerStatus createEmptyServerStatus() { //#if MC >= 1.19.4 return new ServerStatus( - Components.EMPTY, Optional.empty(), Optional.empty(), Optional.empty(), false + CommonComponents.EMPTY, Optional.empty(), Optional.empty(), Optional.empty(), false //#if FORGELIKE && MC < 1.20.4 //$$ , Optional.empty() //#elseif NEOFORGE @@ -974,19 +960,19 @@ public static void connect(Screen parentScreen, long cid, String host, int port) private static int ipCommand(CommandContext ctx) { if (protoClient == null) { - ctx.getSource().sendFailure(Components.translatable("world-host.worldhost.ip.not_connected")); + ctx.getSource().sendFailure(Component.translatable("world-host.worldhost.ip.not_connected")); return 0; } final String externalIp = getExternalIp(); if (externalIp == null) { - ctx.getSource().sendFailure(Components.translatable("world-host.worldhost.ip.no_server_support")); + ctx.getSource().sendFailure(Component.translatable("world-host.worldhost.ip.no_server_support")); return 0; } ctx.getSource().sendSuccess( //#if MC >= 1.20.0 () -> //#endif - Components.translatable( + Component.translatable( "world-host.worldhost.ip.success", Components.copyOnClickText(externalIp) ), diff --git a/src/main/java/io/github/gaming32/worldhost/WorldHostComponents.java b/src/main/java/io/github/gaming32/worldhost/WorldHostComponents.java index b7af95f..2185e87 100644 --- a/src/main/java/io/github/gaming32/worldhost/WorldHostComponents.java +++ b/src/main/java/io/github/gaming32/worldhost/WorldHostComponents.java @@ -1,11 +1,9 @@ package io.github.gaming32.worldhost; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.network.chat.Component; public class WorldHostComponents { - public static final Component FRIENDS = Components.translatable("world-host.friends"); - public static final Component SERVERS = Components.translatable("world-host.servers"); - public static final Component PLAY_TEXT = Components.translatable("world-host.play_world"); - public static final Component ELLIPSIS = Components.literal("..."); // TODO: Remove in 1.19.2 + public static final Component FRIENDS = Component.translatable("world-host.friends"); + public static final Component SERVERS = Component.translatable("world-host.servers"); + public static final Component PLAY_TEXT = Component.translatable("world-host.play_world"); } diff --git a/src/main/java/io/github/gaming32/worldhost/config/option/EnumOption.java b/src/main/java/io/github/gaming32/worldhost/config/option/EnumOption.java index c7d0209..33e97f3 100644 --- a/src/main/java/io/github/gaming32/worldhost/config/option/EnumOption.java +++ b/src/main/java/io/github/gaming32/worldhost/config/option/EnumOption.java @@ -3,10 +3,10 @@ import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.config.ConfigProperty; import io.github.gaming32.worldhost.gui.widget.EnumButton; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.Component; import net.minecraft.util.StringRepresentable; import org.quiltmc.parsers.json.JsonReader; import org.quiltmc.parsers.json.JsonWriter; @@ -74,8 +74,8 @@ public Collection createWidgets(int x, int y, int widt final EnumButton button = new EnumButton<>( x, y, width, height, translationBase, - Components.translatable(translationBase), - I18n.exists(tooltipKey) ? Components.translatable(tooltipKey) : null, + Component.translatable(translationBase), + I18n.exists(tooltipKey) ? Component.translatable(tooltipKey) : null, enumType, b -> setValue(WorldHost.CONFIG, b.getValue()) ); diff --git a/src/main/java/io/github/gaming32/worldhost/config/option/StringOption.java b/src/main/java/io/github/gaming32/worldhost/config/option/StringOption.java index cf085fc..b6ec816 100644 --- a/src/main/java/io/github/gaming32/worldhost/config/option/StringOption.java +++ b/src/main/java/io/github/gaming32/worldhost/config/option/StringOption.java @@ -5,7 +5,6 @@ import io.github.gaming32.worldhost.gui.screen.WorldHostScreen; import io.github.gaming32.worldhost.gui.widget.SimpleStringWidget; import io.github.gaming32.worldhost.gui.widget.TooltipEditBox; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.resources.language.I18n; @@ -19,7 +18,7 @@ import java.util.List; public final class StringOption extends ConfigOption { - private static final Component RESET = Components.translatable("controls.reset"); + private static final Component RESET = Component.translatable("controls.reset"); private final String defaultValue; @@ -53,8 +52,8 @@ public Collection createWidgets(int x, int y, int widt final String translationBase = "world-host.config." + property.getName(); final String tooltipKey = translationBase + ".tooltip"; - final Component translation = Components.translatable(translationBase); - final Component tooltip = I18n.exists(tooltipKey) ? Components.translatable(tooltipKey) : null; + final Component translation = Component.translatable(translationBase); + final Component tooltip = I18n.exists(tooltipKey) ? Component.translatable(tooltipKey) : null; final var label = new SimpleStringWidget(x + 5, y + 10 - font.lineHeight / 2, translation, tooltip, font); diff --git a/src/main/java/io/github/gaming32/worldhost/config/option/YesNoOption.java b/src/main/java/io/github/gaming32/worldhost/config/option/YesNoOption.java index 7eda165..9e6d52f 100644 --- a/src/main/java/io/github/gaming32/worldhost/config/option/YesNoOption.java +++ b/src/main/java/io/github/gaming32/worldhost/config/option/YesNoOption.java @@ -2,10 +2,10 @@ import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.gui.widget.YesNoButton; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.Component; import org.quiltmc.parsers.json.JsonReader; import org.quiltmc.parsers.json.JsonWriter; @@ -38,8 +38,8 @@ public Collection createWidgets(int x, int y, int widt final String tooltipKey = translationBase + ".tooltip"; final YesNoButton button = new YesNoButton( x, y, width, height, - Components.translatable(translationBase), - I18n.exists(tooltipKey) ? Components.translatable(tooltipKey) : null, + Component.translatable(translationBase), + I18n.exists(tooltipKey) ? Component.translatable(tooltipKey) : null, b -> setValue(WorldHost.CONFIG, b.isToggled()) ); button.setToggled(getValue(WorldHost.CONFIG)); diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/AddFriendScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/AddFriendScreen.java index ba053ac..73dd7a8 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/AddFriendScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/AddFriendScreen.java @@ -4,7 +4,6 @@ import io.github.gaming32.worldhost.gui.widget.UserListWidget; import io.github.gaming32.worldhost.plugin.FriendAdder; import io.github.gaming32.worldhost.plugin.FriendListFriend; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.Util; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.Screen; @@ -26,19 +25,19 @@ //#endif public class AddFriendScreen extends WorldHostScreen { - private static final Component FRIEND_USERNAME_TEXT = Components.translatable("world-host.add_friend.enter_username"); - private static final Component ADD_FRIEND_TEXT = Components.literal("+"); + private static final Component FRIEND_USERNAME_TEXT = Component.translatable("world-host.add_friend.enter_username"); + private static final Component ADD_FRIEND_TEXT = Component.literal("+"); //#if MC >= 1.20.0 @VisibleForTesting - public static final Component ADD_FRIEND_SILENT_TEXT = Components.literal("+\ud83d\udd08"); - private static final Component ADD_FRIEND_NOTIFY_TEXT = Components.literal("+\ud83d\udd0a"); + public static final Component ADD_FRIEND_SILENT_TEXT = Component.literal("+\ud83d\udd08"); + private static final Component ADD_FRIEND_NOTIFY_TEXT = Component.literal("+\ud83d\udd0a"); //#else //$$ @VisibleForTesting - //$$ public static final Component ADD_FRIEND_SILENT_TEXT = Components.literal("+Q"); - //$$ private static final Component ADD_FRIEND_NOTIFY_TEXT = Components.literal("+N"); + //$$ public static final Component ADD_FRIEND_SILENT_TEXT = Component.literal("+Q"); + //$$ private static final Component ADD_FRIEND_NOTIFY_TEXT = Component.literal("+N"); //#endif - private static final Component ADD_FRIEND_SILENT_TOOLTIP = Components.translatable("world-host.friends.add_silently.tooltip"); - private static final Component ADD_FRIEND_NOTIFY_TOOLTIP = Components.translatable("world-host.add_friend.tooltip"); + private static final Component ADD_FRIEND_SILENT_TOOLTIP = Component.translatable("world-host.friends.add_silently.tooltip"); + private static final Component ADD_FRIEND_NOTIFY_TOOLTIP = Component.translatable("world-host.add_friend.tooltip"); private final Screen parent; private final BiConsumer addAction; diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java index a934b45..ce6a67e 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/FriendsScreen.java @@ -7,7 +7,6 @@ import io.github.gaming32.worldhost.plugin.FriendListFriend; import io.github.gaming32.worldhost.plugin.InfoTextsCategory; import io.github.gaming32.worldhost.plugin.ProfileInfo; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; @@ -26,7 +25,7 @@ //#endif public class FriendsScreen extends ScreenWithInfoTexts { - public static final Component ADD_FRIEND_TEXT = Components.translatable("world-host.add_friend"); + public static final Component ADD_FRIEND_TEXT = Component.translatable("world-host.add_friend"); private final Screen parent; private Button infoButton; @@ -66,7 +65,7 @@ protected void init() { ); infoButton = addRenderableWidget( - button(Components.translatable("world-host.friends.show_info"), button -> { + button(Component.translatable("world-host.friends.show_info"), button -> { if (list.getSelected() != null) { list.getSelected().friend.showFriendInfo(this); } @@ -77,7 +76,7 @@ protected void init() { infoButton.active = false; removeButton = addRenderableWidget( - button(Components.translatable("world-host.friends.remove"), button -> { + button(Component.translatable("world-host.friends.remove"), button -> { if (list.getSelected() != null) { list.getSelected().maybeRemove(); } @@ -188,7 +187,7 @@ public FriendsEntry(FriendListFriend friend) { @NotNull @Override public Component getNarration() { - return Components.translatable("narrator.select", getNameWithTag()); + return Component.translatable("narrator.select", getNameWithTag()); } public Component getNameWithTag() { @@ -219,8 +218,8 @@ public void maybeRemove() { } minecraft.setScreen(FriendsScreen.this); }, - Components.translatable("world-host.friends.remove.title"), - Components.translatable("world-host.friends.remove.message") + Component.translatable("world-host.friends.remove.title"), + Component.translatable("world-host.friends.remove.message") )); } diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/JoiningWorldHostScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/JoiningWorldHostScreen.java index 27e7632..39239b9 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/JoiningWorldHostScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/JoiningWorldHostScreen.java @@ -1,7 +1,6 @@ package io.github.gaming32.worldhost.gui.screen; import io.github.gaming32.worldhost.WorldHost; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; @@ -14,7 +13,7 @@ //#endif public class JoiningWorldHostScreen extends WorldHostScreen { - private static final Component MESSAGE = Components.translatable("world-host.joining_world_host"); + private static final Component MESSAGE = Component.translatable("world-host.joining_world_host"); public final Screen parent; diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/OnlineFriendsScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/OnlineFriendsScreen.java index 493f840..1a461f7 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/OnlineFriendsScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/OnlineFriendsScreen.java @@ -15,7 +15,6 @@ import io.github.gaming32.worldhost.plugin.OnlineFriend; import io.github.gaming32.worldhost.plugin.ProfileInfo; import io.github.gaming32.worldhost.mixin.ServerStatusPingerAccessor; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.ChatFormatting; import net.minecraft.SharedConstants; import net.minecraft.Util; @@ -77,7 +76,7 @@ public class OnlineFriendsScreen extends ScreenWithInfoTexts implements FriendsL private List tooltip; public OnlineFriendsScreen(Screen parent) { - super(Components.translatable("world-host.online_friends.title"), InfoTextsCategory.ONLINE_FRIENDS_SCREEN); + super(Component.translatable("world-host.online_friends.title"), InfoTextsCategory.ONLINE_FRIENDS_SCREEN); this.parent = parent; } @@ -96,14 +95,14 @@ protected void init() { addWidget(list); joinButton = addRenderableWidget( - button(Components.translatable("selectServer.select"), button -> connect()) + button(Component.translatable("selectServer.select"), button -> connect()) .width(152) .pos(width / 2 - 154, height - 54) .build() ); addRenderableWidget( - button(Components.translatable("selectServer.refresh"), button -> WorldHost.refreshFriendsList()) + button(Component.translatable("selectServer.refresh"), button -> WorldHost.refreshFriendsList()) .width(152) .pos(width / 2 + 2, height - 54) .build() @@ -365,7 +364,7 @@ public OnlineFriendsListEntry(OnlineFriend friend) { @NotNull @Override public Component getNarration() { - return Components.translatable("narrator.select", displayName); + return Component.translatable("narrator.select", displayName); } @Override @@ -437,7 +436,7 @@ public void render( final int relY = mouseY - y; if (relX >= entryWidth - 15 && relX <= entryWidth - 5 && relY >= 0 && relY <= 8) { if (incompatibleVersion) { - tooltip = List.of(Components.translatable("multiplayer.status.incompatible").getVisualOrderText()); + tooltip = List.of(Component.translatable("multiplayer.status.incompatible").getVisualOrderText()); } } else if (relX >= entryWidth - labelWidth - 17 && relX <= entryWidth - 17 && relY >= 0 && relY <= 8) { tooltip = new ArrayList<>(); @@ -448,11 +447,7 @@ public void render( tooltip = joinabilityTooltip; } - //#if MC >= 1.19.0 final boolean touchscreen = minecraft.options.touchscreen().get(); - //#else - //$$ final boolean touchscreen = minecraft.options.touchscreen; - //#endif if (joinable && (touchscreen || hovered)) { fill(context, x, y, x + 32, y + 32, 0xa0909090); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); @@ -477,18 +472,18 @@ private void updateDisplayInfo() { updateNameAndTooltip(); final var metadata = WorldHost.ONLINE_FRIEND_PINGS.get(friend.uuid()); if (metadata == null) { - serverInfo.status = Components.EMPTY; - serverInfo.motd = Components.EMPTY; + serverInfo.status = CommonComponents.EMPTY; + serverInfo.motd = CommonComponents.EMPTY; return; } //#if MC >= 1.19.4 serverInfo.motd = metadata.description(); metadata.version().ifPresentOrElse(version -> { - serverInfo.version = Components.literal(version.name()); + serverInfo.version = Component.literal(version.name()); serverInfo.protocol = version.protocol(); }, () -> { - serverInfo.version = Components.translatable("multiplayer.status.old"); + serverInfo.version = Component.translatable("multiplayer.status.old"); serverInfo.protocol = 0; }); metadata.players().ifPresentOrElse(players -> { @@ -498,11 +493,11 @@ private void updateDisplayInfo() { final List playerList = new ArrayList<>(players.sample().size()); for(GameProfile gameProfile : players.sample()) { - playerList.add(Components.literal(gameProfile.getName())); + playerList.add(Component.literal(gameProfile.getName())); } if (players.sample().size() < players.online()) { - playerList.add(Components.translatable( + playerList.add(Component.translatable( "multiplayer.status.and_more", players.online() - players.sample().size() )); @@ -512,7 +507,7 @@ private void updateDisplayInfo() { } else { serverInfo.playerList = List.of(); } - }, () -> serverInfo.status = Components.translatable("multiplayer.status.unknown").withStyle(ChatFormatting.DARK_GRAY)); + }, () -> serverInfo.status = Component.translatable("multiplayer.status.unknown").withStyle(ChatFormatting.DARK_GRAY)); metadata.favicon().ifPresent(favicon -> { if (!Arrays.equals(favicon.iconBytes(), serverInfo.getIconBytes())) { serverInfo.setIconBytes(favicon.iconBytes()); @@ -522,14 +517,14 @@ private void updateDisplayInfo() { //$$ if (metadata.getDescription() != null) { //$$ serverInfo.motd = metadata.getDescription(); //$$ } else { - //$$ serverInfo.motd = Components.EMPTY; + //$$ serverInfo.motd = Component.empty(); //$$ } //$$ //$$ if (metadata.getVersion() != null) { - //$$ serverInfo.version = Components.literal(metadata.getVersion().getName()); + //$$ serverInfo.version = Component.literal(metadata.getVersion().getName()); //$$ serverInfo.protocol = metadata.getVersion().getProtocol(); //$$ } else { - //$$ serverInfo.version = Components.translatable("multiplayer.status.old"); + //$$ serverInfo.version = Component.translatable("multiplayer.status.old"); //$$ serverInfo.protocol = 0; //$$ } //$$ @@ -542,17 +537,17 @@ private void updateDisplayInfo() { //$$ final GameProfile[] sampleProfiles = metadata.getPlayers().getSample(); //$$ if (sampleProfiles != null && sampleProfiles.length > 0) { //$$ for (final GameProfile sampleProfile : sampleProfiles) { - //$$ lines.add(Components.literal(sampleProfile.getName())); + //$$ lines.add(Component.literal(sampleProfile.getName())); //$$ } //$$ if (sampleProfiles.length < metadata.getPlayers().getNumPlayers()) { - //$$ lines.add(Components.translatable( + //$$ lines.add(Component.translatable( //$$ "multiplayer.status.and_more", metadata.getPlayers().getNumPlayers() - sampleProfiles.length //$$ )); //$$ } //$$ serverInfo.playerList = lines; //$$ } //$$ } else { - //$$ serverInfo.status = Components.translatable("multiplayer.status.unknown").withStyle(ChatFormatting.DARK_GRAY); + //$$ serverInfo.status = Component.translatable("multiplayer.status.unknown").withStyle(ChatFormatting.DARK_GRAY); //$$ } //$$ //$$ String favicon = serverInfo.getIconB64(); @@ -574,9 +569,9 @@ private void updateNameAndTooltip() { final MutableComponent newDisplayName; if (security == SecurityLevel.SECURE) { - newDisplayName = Components.literal(profile.name()); + newDisplayName = Component.literal(profile.name()); } else { - newDisplayName = Components.translatable( + newDisplayName = Component.translatable( "world-host.world_with_security", profile.name(), EnumButton.getTranslation("world-host.config.requiredSecurityLevel", security) diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/PlayerInfoScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/PlayerInfoScreen.java index b605579..5c91294 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/PlayerInfoScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/PlayerInfoScreen.java @@ -3,9 +3,9 @@ import com.mojang.authlib.GameProfile; import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.gui.widget.WHPlayerSkinWidget; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; //#if MC >= 1.20.0 import net.minecraft.client.gui.GuiGraphics; @@ -18,7 +18,7 @@ public class PlayerInfoScreen extends WorldHostScreen { private GameProfile profile; public PlayerInfoScreen(Screen parentScreen, GameProfile profile) { - super(Components.empty()); + super(Component.empty()); this.parentScreen = parentScreen; this.profile = profile; diff --git a/src/main/java/io/github/gaming32/worldhost/gui/screen/WorldHostConfigScreen.java b/src/main/java/io/github/gaming32/worldhost/gui/screen/WorldHostConfigScreen.java index 7ca92cc..9ecf191 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/screen/WorldHostConfigScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/screen/WorldHostConfigScreen.java @@ -3,7 +3,6 @@ import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.WorldHostComponents; import io.github.gaming32.worldhost.config.option.ConfigOptions; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; @@ -20,8 +19,8 @@ //#endif public class WorldHostConfigScreen extends WorldHostScreen { - private static final Component TITLE = Components.translatable("world-host.config.title"); - private static final Component UPNP = Components.literal("UPnP"); + private static final Component TITLE = Component.translatable("world-host.config.title"); + private static final Component UPNP = Component.literal("UPnP"); private final Screen parent; diff --git a/src/main/java/io/github/gaming32/worldhost/gui/widget/CustomCycleButton.java b/src/main/java/io/github/gaming32/worldhost/gui/widget/CustomCycleButton.java index 259777c..629e353 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/widget/CustomCycleButton.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/widget/CustomCycleButton.java @@ -1,8 +1,8 @@ package io.github.gaming32.worldhost.gui.widget; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,7 +45,7 @@ protected CustomCycleButton( Consumer onUpdate, T[] values ) { super( - x, y, width, height, Components.EMPTY, b -> { + x, y, width, height, CommonComponents.EMPTY, b -> { @SuppressWarnings("unchecked") final B cycle = (B)b; final int add = Screen.hasShiftDown() ? -1 : 1; cycle.setValueIndex(Math.floorMod(cycle.getValueIndex() + add, cycle.getValues().length)); diff --git a/src/main/java/io/github/gaming32/worldhost/gui/widget/EnumButton.java b/src/main/java/io/github/gaming32/worldhost/gui/widget/EnumButton.java index 8f039bb..4c32f28 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/widget/EnumButton.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/widget/EnumButton.java @@ -1,6 +1,5 @@ package io.github.gaming32.worldhost.gui.widget; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.network.chat.Component; import net.minecraft.util.StringRepresentable; import org.jetbrains.annotations.NotNull; @@ -34,7 +33,7 @@ private Component[] getTranslations(String translationBase) { } public static Component getTranslation(String base, StringRepresentable element) { - return Components.translatable(base + '.' + element.getSerializedName()); + return Component.translatable(base + '.' + element.getSerializedName()); } public void setValue(E value) { diff --git a/src/main/java/io/github/gaming32/worldhost/gui/widget/FriendsButton.java b/src/main/java/io/github/gaming32/worldhost/gui/widget/FriendsButton.java index 34a1c5f..d8804f3 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/widget/FriendsButton.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/widget/FriendsButton.java @@ -4,10 +4,10 @@ import io.github.gaming32.worldhost.WorldHostComponents; import io.github.gaming32.worldhost.gui.screen.WorldHostScreen; import io.github.gaming32.worldhost.plugin.OnlineFriend; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.Button; +import net.minecraft.network.chat.CommonComponents; import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -24,7 +24,7 @@ public final class FriendsButton extends Button implements FriendsListUpdate { public FriendsButton(int x, int y, int width, int height, OnPress onPress) { super( - x, y, width, height, Components.EMPTY, onPress + x, y, width, height, CommonComponents.EMPTY, onPress //#if MC >= 1.19.4 , DEFAULT_NARRATION //#endif diff --git a/src/main/java/io/github/gaming32/worldhost/gui/widget/OnlineStatusButton.java b/src/main/java/io/github/gaming32/worldhost/gui/widget/OnlineStatusButton.java index c155c33..2fbe85e 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/widget/OnlineStatusButton.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/widget/OnlineStatusButton.java @@ -3,7 +3,6 @@ import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.gui.screen.WorldHostConfigScreen; import io.github.gaming32.worldhost.mixin.PlainTextButtonAccessor; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -31,9 +30,9 @@ public final class OnlineStatusButton extends PlainTextButton { }; private static final List> TEXTS = List.of( - () -> Components.translatable("world-host.online_status.offline", WorldHost.reconnectDelay / 20 + 1), - () -> Components.translatable("world-host.online_status.connecting"), - () -> Components.translatable("world-host.online_status.online") + () -> Component.translatable("world-host.online_status.offline", WorldHost.reconnectDelay / 20 + 1), + () -> Component.translatable("world-host.online_status.connecting"), + () -> Component.translatable("world-host.online_status.online") ); private final int alignedX; @@ -79,9 +78,9 @@ private static int getStatus() { private static Component generateStatusComponent() { final int status = getStatus(); - return Components.translatable( + return Component.translatable( "world-host.online_status", - Components.literal("\u25cf").withStyle(COLORS[status]), + Component.literal("\u25cf").withStyle(COLORS[status]), TEXTS.get(status).get() ); } diff --git a/src/main/java/io/github/gaming32/worldhost/gui/widget/UserListWidget.java b/src/main/java/io/github/gaming32/worldhost/gui/widget/UserListWidget.java index 6aa83c0..4ef0679 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/widget/UserListWidget.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/widget/UserListWidget.java @@ -2,18 +2,17 @@ import com.mojang.blaze3d.systems.RenderSystem; import io.github.gaming32.worldhost.WorldHost; -import io.github.gaming32.worldhost.WorldHostComponents; import io.github.gaming32.worldhost.gui.screen.WorldHostScreen; import io.github.gaming32.worldhost.plugin.FriendListFriend; import io.github.gaming32.worldhost.plugin.ProfileInfo; import io.github.gaming32.worldhost.toast.IconRenderer; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.locale.Language; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.util.FormattedCharSequence; @@ -70,7 +69,7 @@ public UserListWidget( Function> getApplicableActions, @Nullable UserListWidget old ) { - super(x, y, width, height, Components.empty()); + super(x, y, width, height, Component.empty()); this.font = font; this.getApplicableActions = getApplicableActions; if (old != null && !old.users.isEmpty()) { @@ -246,11 +245,11 @@ public int getVisibleCount() { public static Component getNameWithTag(FriendListFriend user, ProfileInfo profile) { return user.tag() - .map(component -> Components.translatable( + .map(component -> Component.translatable( "world-host.friends.tagged_friend", profile.name(), component )) - .orElseGet(() -> Components.literal(profile.name())); + .orElseGet(() -> Component.literal(profile.name())); } private final class UserInfo { @@ -283,8 +282,8 @@ int getMaxNameWidth() { } FormattedCharSequence clipName(Component unclippedName) { - final FormattedText clipped = font.substrByWidth(unclippedName, getMaxNameWidth() - font.width(WorldHostComponents.ELLIPSIS)); - return Language.getInstance().getVisualOrder(FormattedText.composite(clipped, WorldHostComponents.ELLIPSIS)); + final FormattedText clipped = font.substrByWidth(unclippedName, getMaxNameWidth() - font.width(CommonComponents.ELLIPSIS)); + return Language.getInstance().getVisualOrder(FormattedText.composite(clipped, CommonComponents.ELLIPSIS)); } IconRenderer getIcon() { diff --git a/src/main/java/io/github/gaming32/worldhost/gui/widget/WHPlayerSkinWidget.java b/src/main/java/io/github/gaming32/worldhost/gui/widget/WHPlayerSkinWidget.java index 3e6a3e6..f3016fa 100644 --- a/src/main/java/io/github/gaming32/worldhost/gui/widget/WHPlayerSkinWidget.java +++ b/src/main/java/io/github/gaming32/worldhost/gui/widget/WHPlayerSkinWidget.java @@ -3,7 +3,6 @@ import com.mojang.blaze3d.platform.Lighting; import com.mojang.blaze3d.vertex.VertexConsumer; import io.github.gaming32.worldhost.WHPlayerSkin; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.client.model.PlayerModel; @@ -14,6 +13,7 @@ import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.sounds.SoundManager; +import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import java.util.function.BooleanSupplier; @@ -56,7 +56,7 @@ public WHPlayerSkinWidget( Supplier skin, BooleanSupplier isDeadmau5, EntityModelSet models ) { - super(x, y, width, height, Components.empty()); + super(x, y, width, height, Component.empty()); this.skin = skin; this.isDeadmau5 = isDeadmau5; diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MinecraftAccessor.java b/src/main/java/io/github/gaming32/worldhost/mixin/MinecraftAccessor.java index 0e7cad0..2a079e9 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MinecraftAccessor.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MinecraftAccessor.java @@ -7,8 +7,6 @@ @Mixin(Minecraft.class) public interface MinecraftAccessor { - //#if MC >= 1.19.2 @Accessor YggdrasilAuthenticationService getAuthenticationService(); - //#endif } diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinConnectScreen_1.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinConnectScreen_1.java index 332c44e..1c754ff 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinConnectScreen_1.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinConnectScreen_1.java @@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -//#if MC > 1.18.2 && MC < 1.19.4 +//#if MC < 1.19.4 //$$ import java.util.concurrent.CompletableFuture; //#endif diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java index 914af03..ff697bb 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinIntegratedServer.java @@ -1,15 +1,16 @@ package io.github.gaming32.worldhost.mixin; import com.mojang.datafixers.DataFixer; +import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.proxy.ProxyChannels; import io.github.gaming32.worldhost.proxy.ProxyClient; -import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.versions.Components; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.server.IntegratedServer; import net.minecraft.network.chat.Component; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.Services; import net.minecraft.server.WorldStem; import net.minecraft.server.level.progress.ChunkProgressListenerFactory; import net.minecraft.server.packs.repository.PackRepository; @@ -26,20 +27,9 @@ import java.net.Proxy; -//#if MC > 1.18.2 -import net.minecraft.server.Services; -//#else -//$$ import com.mojang.authlib.GameProfileRepository; -//$$ import com.mojang.authlib.minecraft.MinecraftSessionService; -//$$ import net.minecraft.Util; -//$$ import net.minecraft.network.chat.ChatType; -//$$ import net.minecraft.server.players.GameProfileCache; -//#endif - @Mixin(IntegratedServer.class) public abstract class MixinIntegratedServer extends MinecraftServer { public MixinIntegratedServer( - //#if MC > 1.18.2 Thread thread, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, @@ -48,24 +38,8 @@ public MixinIntegratedServer( DataFixer dataFixer, Services services, ChunkProgressListenerFactory chunkProgressListenerFactory - //#else - //$$ Thread thread, - //$$ LevelStorageSource.LevelStorageAccess levelStorageAccess, - //$$ PackRepository packRepository, - //$$ WorldStem worldStem, - //$$ Proxy proxy, - //$$ DataFixer dataFixer, - //$$ MinecraftSessionService minecraftSessionService, - //$$ GameProfileRepository gameProfileRepository, - //$$ GameProfileCache gameProfileCache, - //$$ ChunkProgressListenerFactory chunkProgressListenerFactory - //#endif ) { - //#if MC > 1.18.2 super(thread, levelStorageAccess, packRepository, worldStem, proxy, dataFixer, services, chunkProgressListenerFactory); - //#else - //$$ super(thread, levelStorageAccess, packRepository, worldStem, proxy, dataFixer, minecraftSessionService, gameProfileRepository, gameProfileCache, chunkProgressListenerFactory); - //#endif } @Shadow @Final private Minecraft minecraft; @@ -101,26 +75,22 @@ private void shareWorldOnLoad(CallbackInfo ci) { if (publishServer(worldData.getGameType(), allowCommands, HttpUtil.getAvailablePort())) { message = wh$getOpenedMessage(); } else { - message = Components.translatable("world-host.share_world.failed").withStyle(ChatFormatting.RED); + message = Component.translatable("world-host.share_world.failed").withStyle(ChatFormatting.RED); } - //#if MC > 1.18.2 minecraft.getChatListener().handleSystemMessage(message, false); - //#else - //$$ minecraft.gui.handleChat(ChatType.SYSTEM, message, Util.NIL_UUID); - //#endif } @Unique private Component wh$getOpenedMessage() { final Component port = Components.copyOnClickText(publishedPort); if (WorldHost.CONFIG.isEnableFriends()) { - return Components.translatable("world-host.lan_opened.friends", port); + return Component.translatable("world-host.lan_opened.friends", port); } final String externalIp = WorldHost.getExternalIp(); if (externalIp == null) { - return Components.translatable("commands.publish.started", port); + return Component.translatable("commands.publish.started", port); } - return Components.translatable( + return Component.translatable( "world-host.lan_opened.no_friends", Components.copyOnClickText(externalIp), port ); diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinPublishCommand.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinPublishCommand.java index ccbb3da..f0811f0 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinPublishCommand.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinPublishCommand.java @@ -2,6 +2,7 @@ import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.versions.Components; +import net.minecraft.network.chat.Component; import net.minecraft.server.commands.PublishCommand; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -20,7 +21,7 @@ public class MixinPublishCommand { @Inject(method = "getSuccessMessage", at = @At("HEAD"), cancellable = true) private static void getSuccessMessage(int port, CallbackInfoReturnable cir) { if (WorldHost.CONFIG.isEnableFriends()) { - cir.setReturnValue(Components.translatable( + cir.setReturnValue(Component.translatable( "world-host.lan_opened.friends", Components.copyOnClickText(port) )); @@ -28,7 +29,7 @@ private static void getSuccessMessage(int port, CallbackInfoReturnable= 1.19.2 - //$$ "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;" - //#else - //$$ "Lnet/minecraft/network/chat/TranslatableComponent;(Ljava/lang/String;[Ljava/lang/Object;)V" - //#endif + //$$ target = "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;" //$$ ) //$$ ) //$$ private static String getSuccessMessage(String key) { @@ -62,12 +58,7 @@ private static void getSuccessMessage(int port, CallbackInfoReturnable= 1.19.2 - //$$ "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;" - //#else - //$$ "Lnet/minecraft/network/chat/TranslatableComponent;(Ljava/lang/String;[Ljava/lang/Object;)V" - //#endif + //$$ target = "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;" //$$ ) //$$ ) //$$ private static Object[] getSuccessMessage(Object[] args) { diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java index 3bdd0b0..fde7216 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinSelectWorldScreen.java @@ -4,7 +4,6 @@ import io.github.gaming32.worldhost.WorldHostComponents; import io.github.gaming32.worldhost.ext.SelectWorldScreenExt; import io.github.gaming32.worldhost.gui.screen.WorldHostScreen; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.worldselection.SelectWorldScreen; @@ -74,7 +73,7 @@ private void addShareWorldButton(CallbackInfo ci) { return; } wh$shareButton = addRenderableWidget( - WorldHostScreen.button(Components.translatable("world-host.share_world"), b -> + WorldHostScreen.button(Component.translatable("world-host.share_world"), b -> list.getSelectedOpt().ifPresent(worldListEntry -> { wh$shareButtonPressed = true; worldListEntry.joinWorld(); @@ -124,9 +123,7 @@ private void updateShareButtonStatus(LevelSummary levelSummary, CallbackInfo ci) //#else //$$ private void updateShareButtonStatus( //$$ boolean active, - //#if MC > 1.19.2 - //$$ boolean bl2, - //#endif + //$$ boolean bl2, //$$ CallbackInfo ci //$$ ) { //$$ if (wh$shareButton != null) { diff --git a/src/main/java/io/github/gaming32/worldhost/mixin/MixinShareToLanScreen.java b/src/main/java/io/github/gaming32/worldhost/mixin/MixinShareToLanScreen.java index 8012ce3..081e0a2 100644 --- a/src/main/java/io/github/gaming32/worldhost/mixin/MixinShareToLanScreen.java +++ b/src/main/java/io/github/gaming32/worldhost/mixin/MixinShareToLanScreen.java @@ -29,12 +29,7 @@ private String changeLabelI2(String constant) { //$$ method = "lambda$init$2", //$$ at = @At( //$$ value = "INVOKE", - //$$ target = - //#if MC >= 1.19.2 - //$$ "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;" - //#else - //$$ "Lnet/minecraft/network/chat/TranslatableComponent;(Ljava/lang/String;[Ljava/lang/Object;)V" - //#endif + //$$ target = "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;" //$$ ) //$$ ) //$$ private String changeSuccessMessage(String key) { @@ -49,12 +44,7 @@ private String changeLabelI2(String constant) { //$$ method = "lambda$init$2", //$$ at = @At( //$$ value = "INVOKE", - //$$ target = - //#if MC >= 1.19.2 - //$$ "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;" - //#else - //$$ "Lnet/minecraft/network/chat/TranslatableComponent;(Ljava/lang/String;[Ljava/lang/Object;)V" - //#endif + //$$ target = "Lnet/minecraft/network/chat/Component;translatable(Ljava/lang/String;[Ljava/lang/Object;)Lnet/minecraft/network/chat/MutableComponent;" //$$ ) //$$ ) //$$ private Object[] changeSuccessMessage(Object[] args) { diff --git a/src/main/java/io/github/gaming32/worldhost/plugin/vanilla/WorldHostFriendAdder.java b/src/main/java/io/github/gaming32/worldhost/plugin/vanilla/WorldHostFriendAdder.java index 414c452..512e7b4 100644 --- a/src/main/java/io/github/gaming32/worldhost/plugin/vanilla/WorldHostFriendAdder.java +++ b/src/main/java/io/github/gaming32/worldhost/plugin/vanilla/WorldHostFriendAdder.java @@ -4,10 +4,9 @@ import io.github.gaming32.worldhost.WorldHost; import io.github.gaming32.worldhost.plugin.FriendAdder; import io.github.gaming32.worldhost.plugin.FriendListFriend; -import io.github.gaming32.worldhost.versions.Components; +import net.minecraft.core.UUIDUtil; import net.minecraft.network.chat.Component; -import java.nio.charset.StandardCharsets; import java.util.UUID; import java.util.function.Consumer; import java.util.regex.Pattern; @@ -18,7 +17,7 @@ public class WorldHostFriendAdder implements FriendAdder { @Override public Component label() { - return Components.literal("World Host"); + return Component.literal("World Host"); } @Override @@ -32,9 +31,9 @@ public void searchFriends(String name, int maxResults, Consumer= 1.19.1 -import com.mojang.authlib.exceptions.UserBannedException; -//#endif - public final class ProtocolClient implements AutoCloseable, ProxyPassthrough { private static final Thread.Builder CONNECTION_THREAD_BUILDER = Thread.ofVirtual().name("WH-ConnectionThread-", 1); private static final Thread.Builder SEND_THREAD_BUILDER = Thread.ofVirtual().name("WH-SendThread-", 1); @@ -298,7 +295,6 @@ private static String authenticateServer( } catch (InsufficientPrivilegesException e) { return I18n.get("disconnect.loginFailedInfo.insufficientPrivileges"); } catch (AuthenticationException e) { - //#if MC >= 1.19.1 if ( //#if MC >= 1.20.2 e instanceof ForcedUsernameChangeException || @@ -307,7 +303,6 @@ private static String authenticateServer( ) { return I18n.get("disconnect.loginFailedInfo.userBanned"); } - //#endif return e.getMessage(); } } diff --git a/src/main/java/io/github/gaming32/worldhost/protocol/WorldHostS2CMessage.java b/src/main/java/io/github/gaming32/worldhost/protocol/WorldHostS2CMessage.java index c3b169f..e6dec0e 100644 --- a/src/main/java/io/github/gaming32/worldhost/protocol/WorldHostS2CMessage.java +++ b/src/main/java/io/github/gaming32/worldhost/protocol/WorldHostS2CMessage.java @@ -16,12 +16,12 @@ import io.github.gaming32.worldhost.protocol.punch.PunchManager; import io.github.gaming32.worldhost.protocol.punch.PunchReason; import io.github.gaming32.worldhost.toast.WHToast; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.DisconnectedScreen; import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.client.resources.language.I18n; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.status.ServerStatus; import java.io.DataInputStream; @@ -67,7 +67,7 @@ public static Error decode(DataInputStream dis) throws IOException { public void handle(ProtocolClient client) { if (critical) { WHToast.builder("world-host.protocol_error_occurred") - .description(Components.literal(message)) + .description(Component.literal(message)) .show(); throw new RuntimeException(message); } else { @@ -371,7 +371,7 @@ public void handle(ProtocolClient client) { if (version.isEmpty()) return; final String updateLink = WorldHostUpdateChecker.formatUpdateLink(version.get()); WHToast.builder("world-host.outdated_world_host") - .description(Components.translatable( + .description(Component.translatable( "world-host.outdated_world_host.desc", currentVersion, version.get() )) @@ -401,8 +401,8 @@ public void handle(ProtocolClient client) { } minecraft.setScreen(new DisconnectedScreen( parentScreen, - Components.translatable("world-host.connection_not_found"), - Components.translatable("world-host.connection_not_found.desc", WorldHost.connectionIdToString(connectionId)) + Component.translatable("world-host.connection_not_found"), + Component.translatable("world-host.connection_not_found.desc", WorldHost.connectionIdToString(connectionId)) )); }); } @@ -443,8 +443,8 @@ public static Warning decode(DataInputStream dis) throws IOException { @Override public void handle(ProtocolClient client) { WorldHost.LOGGER.warn("Warning from WH server (important: {}): {}", important, message); - WHToast.builder(Components.translatable("world-host.protocol_warning_occurred")) - .description(Components.literal(message)) + WHToast.builder(Component.translatable("world-host.protocol_warning_occurred")) + .description(Component.literal(message)) .important(important) .show(); } diff --git a/src/main/java/io/github/gaming32/worldhost/testing/MinecraftApi.java b/src/main/java/io/github/gaming32/worldhost/testing/MinecraftApi.java index 140d542..42f80c2 100644 --- a/src/main/java/io/github/gaming32/worldhost/testing/MinecraftApi.java +++ b/src/main/java/io/github/gaming32/worldhost/testing/MinecraftApi.java @@ -8,18 +8,13 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.contents.TranslatableContents; import org.intellij.lang.annotations.RegExp; import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Stream; -//#if MC >= 1.19.2 -import net.minecraft.network.chat.contents.TranslatableContents; -//#else -//$$ import net.minecraft.network.chat.TranslatableComponent; -//#endif - public class MinecraftApi { private static final Thread.Builder SLEEP_BUILDER = Thread.ofVirtual().name("WH-TestingSleeper-", 1); @@ -83,11 +78,7 @@ public static AbstractWidget findWidgetByString(Predicate messageMatcher public static AbstractWidget findWidgetByTranslation(String translation) { return findWidget( - //#if MC >= 1.19.2 c -> c.getContents() instanceof TranslatableContents translatable && translatable.getKey().equals(translation), - //#else - //$$ c -> c instanceof TranslatableComponent translatable && translatable.getKey().equals(translation), - //#endif "Could not find widget with translation key \"" + translation + "\"" ); } diff --git a/src/main/java/io/github/gaming32/worldhost/toast/ToastInstance.java b/src/main/java/io/github/gaming32/worldhost/toast/ToastInstance.java index 25d727f..f1bc803 100644 --- a/src/main/java/io/github/gaming32/worldhost/toast/ToastInstance.java +++ b/src/main/java/io/github/gaming32/worldhost/toast/ToastInstance.java @@ -5,6 +5,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.network.chat.Component; +import net.minecraft.util.FormattedCharSequence; import net.minecraft.util.Mth; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -19,8 +20,6 @@ import net.minecraft.client.gui.GuiGraphics; //#endif -import net.minecraft.util.FormattedCharSequence; - class ToastInstance { private static final int TEXT_WIDTH = 200; private static final int BORDER_SIZE = 5; diff --git a/src/main/java/io/github/gaming32/worldhost/toast/WHToast.java b/src/main/java/io/github/gaming32/worldhost/toast/WHToast.java index e8327b8..e591558 100644 --- a/src/main/java/io/github/gaming32/worldhost/toast/WHToast.java +++ b/src/main/java/io/github/gaming32/worldhost/toast/WHToast.java @@ -5,7 +5,6 @@ import io.github.gaming32.worldhost.ResourceLocations; import io.github.gaming32.worldhost.gui.screen.WorldHostScreen; import io.github.gaming32.worldhost.testing.WorldHostTesting; -import io.github.gaming32.worldhost.versions.Components; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; @@ -36,7 +35,7 @@ public static ToastBuilder builder(@NotNull Component title) { } public static ToastBuilder builder(@NotNull @Translatable String titleKey) { - return new ToastBuilder(Components.translatable(titleKey)); + return new ToastBuilder(Component.translatable(titleKey)); } public static void ready() { diff --git a/src/main/java/io/github/gaming32/worldhost/versions/Components.java b/src/main/java/io/github/gaming32/worldhost/versions/Components.java index 7a53052..a7e7c76 100644 --- a/src/main/java/io/github/gaming32/worldhost/versions/Components.java +++ b/src/main/java/io/github/gaming32/worldhost/versions/Components.java @@ -1,63 +1,21 @@ package io.github.gaming32.worldhost.versions; -import com.demonwav.mcdev.annotations.Translatable; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.ClickEvent; -import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentUtils; import net.minecraft.network.chat.HoverEvent; import net.minecraft.network.chat.MutableComponent; -//#if MC < 1.19.2 -//$$ import net.minecraft.network.chat.TextComponent; -//$$ import net.minecraft.network.chat.TranslatableComponent; -//#endif - public class Components { - //#if MC >= 1.19.2 - public static final Component EMPTY = CommonComponents.EMPTY; - //#else - //$$ public static final Component EMPTY = TextComponent.EMPTY; - //#endif - - public static MutableComponent literal(String text) { - //#if MC >= 1.19.1 - return Component.literal(text); - //#else - //$$ return new TextComponent(text); - //#endif - } - - public static MutableComponent translatable(@Translatable(foldMethod = true) String key) { - //#if MC >= 1.19.1 - return Component.translatable(key); - //#else - //$$ return new TranslatableComponent(key); - //#endif - } - - public static MutableComponent translatable(@Translatable(foldMethod = true) String key, Object... args) { - //#if MC >= 1.19.1 - return Component.translatable(key, args); - //#else - //$$ return new TranslatableComponent(key, args); - //#endif - } - - // TODO: Remove when 1.19.2 becomes the minimum - public static MutableComponent empty() { - return EMPTY.copy(); - } - // TODO: Remove when 1.19.4 becomes the minimum public static MutableComponent copyOnClickText(Object obj) { final String text = obj.toString(); return ComponentUtils.wrapInSquareBrackets( - literal(text).withStyle(style -> style + Component.literal(text).withStyle(style -> style .withColor(ChatFormatting.GREEN) .withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, text)) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, translatable("chat.copy.click"))) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("chat.copy.click"))) .withInsertion(text) ) ); diff --git a/version.gradle.kts b/version.gradle.kts index 7c8243b..4e61865 100644 --- a/version.gradle.kts +++ b/version.gradle.kts @@ -98,12 +98,6 @@ unimined.minecraft { parchment(it.substringBefore(":"), it.substringAfter(":")) } - if (mcVersion <= 1_19_00) { - stub.withMappings("searge", listOf("mojmap")) { - c("net/minecraft/client/gui/chat/NarratorChatListener", "net/minecraft/client/GameNarrator") - } - } - devFallbackNamespace("official") } @@ -116,7 +110,6 @@ unimined.minecraft { 1_20_01 -> "47.1.3" 1_19_04 -> "45.1.0" 1_19_02 -> "43.2.0" - 1_18_02 -> "40.2.0" else -> throw IllegalStateException("Unknown Forge version for $mcVersionString") }) mixinConfig("world-host.mixins.json") @@ -281,7 +274,6 @@ dependencies { 1_20_01 -> "7.2.2" 1_19_04 -> "6.3.1" 1_19_02 -> "4.2.0-beta.2" - 1_18_02 -> "3.2.5" else -> null }?.let { modImplementation("com.terraformersmc:modmenu:$it") @@ -303,7 +295,6 @@ dependencies { 1_20_01 -> "0.92.2+1.20.1" 1_19_04 -> "0.87.2+1.19.4" 1_19_02 -> "0.77.0+1.19.2" - 1_18_02 -> "0.77.0+1.18.2" else -> null }?.let { fapiVersion -> val resourceLoader = fabricApi.fabricModule("fabric-resource-loader-v0", fapiVersion) @@ -339,7 +330,6 @@ dependencies { 1_20_01 -> "2.5.20" 1_19_04 -> "2.5.12" 1_19_02 -> "2.5.20" - 1_18_02 -> "2.5.20" else -> null }?.let { modCompileOnly("maven.modrinth:simple-voice-chat:$loaderName-$mcVersionString-$it")