Skip to content

Commit

Permalink
Merge pull request #129 from Gaming32/port/1.21.2
Browse files Browse the repository at this point in the history
Port to 1.21.3
  • Loading branch information
Gaming32 authored Oct 25, 2024
2 parents cdb7a4c + 556ed3d commit d1b9357
Show file tree
Hide file tree
Showing 40 changed files with 278 additions and 381 deletions.
30 changes: 15 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ repositories {
}

preprocess {
val fabric12103 = createNode("1.21.3-fabric", 1_21_03, "yarn")
val neoforge12103 = createNode("1.21.3-neoforge", 1_21_03, "yarn")
val fabric12101 = createNode("1.21.1-fabric", 1_21_01, "yarn")
val neoforge12101 = createNode("1.21.1-neoforge", 1_21_01, "yarn")
val fabric12006 = createNode("1.20.6-fabric", 1_20_06, "yarn")
Expand All @@ -20,20 +22,18 @@ 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)
neoforge12006.link(fabric12006)
fabric12006.link(fabric12004)
fabric12004.link(neoforge12004)
neoforge12004.link(forge12001)
forge12001.link(fabric12001)
fabric12001.link(fabric11904)
fabric11904.link(forge11904)
forge11904.link(forge11902)
forge11902.link(fabric11902)
fabric11902.link(fabric11802)
fabric11802.link(forge11802)
fabric12103.link(neoforge12103)
neoforge12103.link(neoforge12101)
neoforge12101.link(fabric12101)
fabric12101.link(fabric12006)
fabric12006.link(neoforge12006)
neoforge12006.link(neoforge12004)
neoforge12004.link(fabric12004)
fabric12004.link(fabric12001)
fabric12001.link(forge12001)
forge12001.link(forge11904)
forge11904.link(fabric11904)
fabric11904.link(fabric11902)
fabric11902.link(forge11902)
}
4 changes: 2 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -33,6 +31,8 @@ listOf(
"1.20.6-fabric",
"1.21.1-neoforge",
"1.21.1-fabric",
"1.21.3-neoforge",
"1.21.3-fabric",
).forEach { version ->
include(":$version")
project(":$version").apply {
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/io/github/gaming32/worldhost/WHPlayerSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand All @@ -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);
//$$ }
Expand Down
42 changes: 14 additions & 28 deletions src/main/java/io/github/gaming32/worldhost/WorldHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
//$$ );
//$$ }
Expand Down Expand Up @@ -301,7 +291,7 @@ private static void init(IOFunction<String, Path> 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)
Expand All @@ -318,11 +308,7 @@ private static void init(IOFunction<String, Path> 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());
Expand Down Expand Up @@ -634,7 +620,7 @@ public static void commandRegistrationHandler(CommandDispatcher<CommandSourceSta
//#if MC >= 1.20.0
() ->
//#endif
Components.translatable(
Component.translatable(
"world-host.worldhost.tempip.success",
Components.copyOnClickText(protoClient.getUserIp() + ':' + port)
),
Expand All @@ -646,9 +632,9 @@ public static void commandRegistrationHandler(CommandDispatcher<CommandSourceSta
} catch (Exception e) {
WorldHost.LOGGER.error("Failed to open UPnP due to exception", e);
}
ctx.getSource().sendFailure(Components.translatable(
ctx.getSource().sendFailure(Component.translatable(
"world-host.worldhost.tempip.failure",
ComponentUtils.wrapInSquareBrackets(Components.literal("/worldhost ip")).withStyle(style -> style
ComponentUtils.wrapInSquareBrackets(Component.literal("/worldhost ip")).withStyle(style -> style
.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/worldhost ip"))
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -974,19 +960,19 @@ public static void connect(Screen parentScreen, long cid, String host, int port)

private static int ipCommand(CommandContext<CommandSourceStack> 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)
),
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,8 +74,8 @@ public Collection<? extends AbstractWidget> createWidgets(int x, int y, int widt
final EnumButton<E> 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())
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,7 +18,7 @@
import java.util.List;

public final class StringOption extends ConfigOption<String> {
private static final Component RESET = Components.translatable("controls.reset");
private static final Component RESET = Component.translatable("controls.reset");

private final String defaultValue;

Expand Down Expand Up @@ -53,8 +52,8 @@ public Collection<? extends AbstractWidget> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -38,8 +38,8 @@ public Collection<? extends AbstractWidget> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<FriendListFriend, Boolean> addAction;
Expand Down
Loading

0 comments on commit d1b9357

Please sign in to comment.