Skip to content

Commit

Permalink
1.20.2 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Sep 23, 2023
1 parent 95705dd commit 27d90d5
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 269 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repositories {
}

preprocess {
val fabric12002 = createNode("1.20.2-fabric", 1_20_02, "yarn")
val fabric12001 = createNode("1.20.1-fabric", 1_20_01, "yarn")
val forge12001 = createNode("1.20.1-forge", 1_20_01, "srg")
val fabric11904 = createNode("1.19.4-fabric", 1_19_04, "yarn")
Expand All @@ -23,6 +24,7 @@ preprocess {
val forge11605 = createNode("1.16.5-forge", 1_16_05, "srg")
val fabric11601 = createNode("1.16.1-fabric", 1_16_01, "yarn")

fabric12002.link(fabric12001)
fabric12001.link(forge12001)
forge12001.link(forge11904)
forge11904.link(fabric11904)
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ listOf(
"1.19.4-fabric",
"1.20.1-forge",
"1.20.1-fabric",
"1.20.2-fabric",
).forEach { version ->
include(":$version")
project(":$version").apply {
Expand Down
60 changes: 46 additions & 14 deletions src/main/java/io/github/gaming32/worldhost/WorldHost.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.gaming32.worldhost;

import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
Expand Down Expand Up @@ -71,6 +72,10 @@
//$$ import net.minecraft.world.entity.player.Player;
//#endif

//#if MC >= 1.20.2
//$$ import com.mojang.authlib.yggdrasil.ProfileResult;
//#endif

//#if FABRIC
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -427,7 +432,7 @@ public static void reconnect(boolean successToast, boolean failureToast) {
proxyProtocolClient.close();
proxyProtocolClient = null;
}
final UUID uuid = Minecraft.getInstance().getUser().getGameProfile().getId();
final UUID uuid = Minecraft.getInstance().getUser().getProfileId();
if (uuid == null) {
LOGGER.warn("Failed to get player UUID. Unable to use World Host.");
if (failureToast) {
Expand Down Expand Up @@ -456,7 +461,9 @@ public static GameProfileCache getProfileCache() {

public static ResourceLocation getInsecureSkinLocation(GameProfile gameProfile) {
final SkinManager skinManager = Minecraft.getInstance().getSkinManager();
//#if MC >= 1.19.2
//#if MC >= 1.20.2
//$$ return skinManager.getInsecureSkin(gameProfile).texture();
//#elseif MC >= 1.19.2
return skinManager.getInsecureSkinLocation(gameProfile);
//#else
//$$ final MinecraftProfileTexture texture = skinManager.getInsecureSkinInformation(gameProfile)
Expand All @@ -468,13 +475,35 @@ public static ResourceLocation getInsecureSkinLocation(GameProfile gameProfile)
}

public static void getMaybeAsync(GameProfileCache cache, String name, Consumer<Optional<GameProfile>> action) {
//#if MC > 1.16.5
//#if MC >= 1.20.2
//$$ cache.getAsync(name).thenAccept(action);
//#elseif MC > 1.16.5
cache.getAsync(name, action);
//#else
//$$ action.accept(Optional.ofNullable(cache.get(name)));
//#endif
}

public static GameProfile fetchProfile(MinecraftSessionService sessionService, UUID uuid, GameProfile fallback) {
//#if MC < 1.20.2
return sessionService.fillProfileProperties(fallback != null ? fallback : new GameProfile(uuid, null), false);
//#else
//$$ final ProfileResult result = sessionService.fetchProfile(uuid, false);
//$$ if (result == null) {
//$$ return fallback != null ? fallback : new GameProfile(uuid, null);
//$$ }
//$$ return result.profile();
//#endif
}

public static GameProfile fetchProfile(MinecraftSessionService sessionService, UUID uuid) {
return fetchProfile(sessionService, uuid, null);
}

public static GameProfile fetchProfile(MinecraftSessionService sessionService, GameProfile profile) {
return fetchProfile(sessionService, profile.getId(), profile);
}

public static void texture(ResourceLocation texture) {
//#if MC > 1.16.5
RenderSystem.setShaderTexture(0, texture);
Expand All @@ -487,13 +516,11 @@ public static void texture(ResourceLocation texture) {
//$$ @SuppressWarnings("deprecation")
//#endif
public static void color(float r, float g, float b, float a) {
RenderSystem.
//#if MC > 1.16.5
setShaderColor
//#else
//$$ color4f
//#endif
(r, g, b, a);
//#if MC > 1.16.5
RenderSystem.setShaderColor(r, g, b, a);
//#else
//$$ RenderSystem.color4f(r, g, b, a);
//#endif
}

public static boolean isFriend(UUID user) {
Expand All @@ -502,9 +529,7 @@ public static boolean isFriend(UUID user) {

public static void showFriendOrOnlineToast(UUID user, String title, String description, int ticks, Runnable clickAction) {
Util.backgroundExecutor().execute(() -> {
final GameProfile profile = Minecraft.getInstance()
.getMinecraftSessionService()
.fillProfileProperties(new GameProfile(user, null), false);
final GameProfile profile = fetchProfile(Minecraft.getInstance().getMinecraftSessionService(), user);
Minecraft.getInstance().execute(() -> {
final ResourceLocation skinTexture = getInsecureSkinLocation(profile);
WHToast.builder(Components.translatable(title, getName(profile)))
Expand Down Expand Up @@ -649,7 +674,14 @@ public static void connect(Screen parentScreen, long cid, String host, int port)
//#if MC < 1.20.0
//$$ null
//#else
new ServerData(WorldHost.connectionIdToString(cid), serverAddress.toString(), false), false
new ServerData(
WorldHost.connectionIdToString(cid), serverAddress.toString(),
//#if MC < 1.20.2
false
//#else
//$$ ServerData.Type.OTHER
//#endif
), false
//#endif
);
//#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public AddFriendScreen(Screen parent, Component title, UUID prefilledUser, Consu
this.parent = parent;
this.addAction = addAction;
if (prefilledUser != null) {
friendProfile = Minecraft.getInstance().getMinecraftSessionService()
.fillProfileProperties(new GameProfile(prefilledUser, null), false);
friendProfile = WorldHost.fetchProfile(Minecraft.getInstance().getMinecraftSessionService(), prefilledUser);
}
}

Expand Down Expand Up @@ -129,15 +128,17 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {

@Override
public void tick() {
//#if MC < 1.20.2
usernameField.tick();
//#endif
if (Util.getMillis() - 300 > lastTyping && usernameUpdate) {
usernameUpdate = false;
final String username = usernameField.getValue();
if (VALID_USERNAME.matcher(username).matches()) {
WorldHost.getMaybeAsync(WorldHost.getProfileCache(), username, p -> {
if (p.isPresent()) {
assert minecraft != null;
friendProfile = minecraft.getMinecraftSessionService().fillProfileProperties(p.get(), false);
friendProfile = WorldHost.fetchProfile(minecraft.getMinecraftSessionService(), p.get());
addFriendButton.active = true;
} else {
friendProfile = null;
Expand All @@ -164,7 +165,11 @@ public void render(
//#endif
int mouseX, int mouseY, float delta
) {
//#if MC < 1.20.2
renderBackground(context);
//#else
//$$ renderBackground(context, mouseX, mouseY, delta);
//#endif
drawCenteredString(context, font, title, width / 2, 20, 0xffffff);
drawString(context, font, FRIEND_USERNAME_TEXT, width / 2 - 100, 50, 0xa0a0a0);
usernameField.render(context, mouseX, mouseY, delta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ public void render(
//#endif
int mouseX, int mouseY, float delta
) {
//#if MC < 1.20.2
renderBackground(context);
//#else
//$$ renderBackground(context, mouseX, mouseY, delta);
//#endif
list.render(context, mouseX, mouseY, delta);
drawCenteredString(context, font, title, width / 2, 15, 0xffffff);
if (WorldHost.BEDROCK_SUPPORT) {
Expand Down Expand Up @@ -199,7 +203,7 @@ public FriendsEntry(GameProfile profile) {
minecraft = Minecraft.getInstance();
this.profile = profile;
Util.backgroundExecutor().execute(
() -> this.profile = minecraft.getMinecraftSessionService().fillProfileProperties(profile, false)
() -> this.profile = WorldHost.fetchProfile(minecraft.getMinecraftSessionService(), profile)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ public void render(
//#else
GuiGraphics context,
//#endif
int mouseX, int mouseY, float partialTick
int mouseX, int mouseY, float delta
) {
//#if MC < 1.20.2
renderBackground(context);
//#else
//$$ renderBackground(context, mouseX, mouseY, delta);
//#endif
drawCenteredString(context, font, status, width / 2, height / 2 - 50, 0xffffff);
super.render(context, mouseX, mouseY, partialTick);
super.render(context, mouseX, mouseY, delta);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@

//#if MC >= 1.19.4 && FABRIC
import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
import de.florianmichael.viafabricplus.screen.impl.base.ProtocolSelectionScreen;
import io.github.gaming32.worldhost.versions.ButtonBuilder;
import net.fabricmc.loader.api.FabricLoader;
//#if MC >= 1.20.1
import de.florianmichael.viafabricplus.screen.base.ProtocolSelectionScreen;
//#else
//$$ import de.florianmichael.viafabricplus.screen.impl.base.ProtocolSelectionScreen;
//#endif
//#endif

public class OnlineFriendsScreen extends WorldHostScreen implements FriendsListUpdate {
Expand Down Expand Up @@ -129,7 +133,11 @@ private void vfpInit() {
b -> ProtocolSelectionScreen.INSTANCE.open(this)
);

switch (GeneralSettings.INSTANCE.mainButtonOrientation.getIndex()) {
//#if MC >= 1.20.1
switch (GeneralSettings.INSTANCE.multiplayerScreenButtonOrientation.getIndex()) {
//#else
//$$ switch (GeneralSettings.INSTANCE.mainButtonOrientation.getIndex()) {
//#endif
case 0 -> builder.pos(5, 5);
case 1 -> builder.pos(width - 98 - 5, 5);
case 2 -> builder.pos(5, height - 20 - 5);
Expand Down Expand Up @@ -178,7 +186,11 @@ public void render(
int mouseX, int mouseY, float delta
) {
tooltip = null;
//#if MC < 1.20.1
renderBackground(context);
//#else
//$$ renderBackground(context, mouseX, mouseY, delta);
//#endif
list.render(context, mouseX, mouseY, delta);
drawCenteredString(context, font, title, width / 2, 15, 0xffffff);
super.render(context, mouseX, mouseY, delta);
Expand Down Expand Up @@ -268,7 +280,14 @@ protected int getRowTop(int index) {

public class OnlineFriendsListEntry extends ObjectSelectionList.Entry<OnlineFriendsListEntry> {
private final Minecraft minecraft;
private final ServerData serverInfo = new ServerData("", "", false);
private final ServerData serverInfo = new ServerData(
"", "",
//#if MC < 1.20.2
false
//#else
//$$ ServerData.Type.OTHER
//#endif
);
private final long connectionId;
private GameProfile profile;

Expand All @@ -288,7 +307,7 @@ public OnlineFriendsListEntry(UUID friendUuid, long connectionId) {
this.connectionId = connectionId;
profile = new GameProfile(friendUuid, null);
Util.backgroundExecutor().execute(
() -> profile = minecraft.getMinecraftSessionService().fillProfileProperties(profile, false)
() -> profile = WorldHost.fetchProfile(minecraft.getMinecraftSessionService(), profile)
);
iconTextureId = new ResourceLocation(WorldHost.MOD_ID, "servers/" + friendUuid + "/icon");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,14 @@ public void render(
//#else
GuiGraphics context,
//#endif
int mouseX, int mouseY, float partialTick
int mouseX, int mouseY, float delta
) {
//#if MC < 1.20.2
renderBackground(context);
super.render(context, mouseX, mouseY, partialTick);
//#else
//$$ renderBackground(context, mouseX, mouseY, delta);
//#endif
super.render(context, mouseX, mouseY, delta);
drawCenteredString(context, font, title, width / 2, 15, 0xffffff);

final int yOffset = height / 6 + 10 - font.lineHeight / 2;
Expand All @@ -167,10 +171,12 @@ public void removed() {
}
}

//#if MC < 1.20.2
@Override
public void tick() {
serverIpBox.tick();
}
//#endif

private interface ConfigOption {
Button createButton(int x, int y, int width, int height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public OnlineStatusButton(int alignedX, int y, int height, boolean rightAlign, F
private void updateX() {
//#if MC >= 1.19.4
setX(
//#else
//$$ x = (
//#endif
//#else
//$$ x = (
//#endif
rightAlign ? alignedX - getWidth() : alignedX
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.gaming32.worldhost.gui.screen.FriendsScreen;
import io.github.gaming32.worldhost.gui.screen.JoiningWorldHostScreen;
import io.github.gaming32.worldhost.protocol.proxy.ProxyProtocolClient;
import io.github.gaming32.worldhost.protocol.punch.PunchClient;
import io.github.gaming32.worldhost.toast.WHToast;
import io.github.gaming32.worldhost.upnp.UPnPErrors;
import io.github.gaming32.worldhost.versions.Components;
Expand Down Expand Up @@ -71,13 +70,7 @@ public void handle(ProtocolClient client) {
parentScreen = joinScreen.parent;
}
if (isPunchProtocol) {
new PunchClient(
client.getOriginalHost(),
client.getPunchPort(),
false,
client.getConnectionId(),
ownerCid
).start();
WorldHost.LOGGER.error("Punch is not supported!");
} else {
WorldHost.connect(parentScreen, ownerCid, host, port);
}
Expand Down
Loading

0 comments on commit 27d90d5

Please sign in to comment.