Skip to content

Commit

Permalink
Merge pull request #149 from Gaming32/port/1.21.4
Browse files Browse the repository at this point in the history
Port to 1.21.4
  • Loading branch information
Gaming32 authored Dec 4, 2024
2 parents fa42594 + 1403e66 commit 8d95265
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 53 deletions.
50 changes: 28 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("io.github.gaming32.gradle.preprocess-root") version "0.4.4"
id("dev.architectury.loom") version "1.7.415" apply false
id("dev.architectury.loom") version "1.7.416" apply false
id("com.modrinth.minotaur") version "2.8.7" apply false
id("xyz.wagyourtail.jvmdowngrader") version "1.2.1" apply false
}
Expand All @@ -10,34 +10,40 @@ 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")
val neoforge12006 = createNode("1.20.6-neoforge", 1_20_06, "yarn")
val fabric12004 = createNode("1.20.4-fabric", 1_20_04, "yarn")
val neoforge12004 = createNode("1.20.4-neoforge", 1_20_04, "yarn")
fun createNode(project: String, mcVersion: Int) = createNode(project, mcVersion, "yarn")

val fabric12104 = createNode("1.21.4-fabric", 1_21_04)
val neoforge12104 = createNode("1.21.4-neoforge", 1_21_04)
val fabric12103 = createNode("1.21.3-fabric", 1_21_03)
val neoforge12103 = createNode("1.21.3-neoforge", 1_21_03)
val fabric12101 = createNode("1.21.1-fabric", 1_21_01)
val neoforge12101 = createNode("1.21.1-neoforge", 1_21_01)
val fabric12006 = createNode("1.20.6-fabric", 1_20_06)
val neoforge12006 = createNode("1.20.6-neoforge", 1_20_06)
val fabric12004 = createNode("1.20.4-fabric", 1_20_04)
val neoforge12004 = createNode("1.20.4-neoforge", 1_20_04)
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")
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")

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)
fabric12104.link(neoforge12104)
neoforge12104.link(neoforge12103)
neoforge12103.link(fabric12103)
fabric12103.link(fabric12101)
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)
}

subprojects {
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ listOf(
"1.21.1-fabric",
"1.21.3-neoforge",
"1.21.3-fabric",
"1.21.4-neoforge",
"1.21.4-fabric",
).forEach { version ->
include(":$version")
project(":$version").apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ protected void init() {
.build()
);

maxFriends = (cancelY - 90) / 24;
//#if MC >= 1.21.4
maxFriends = 25;
//#else
//$$ maxFriends = (cancelY - 94) / 24;
//#endif

userList = addRenderableWidget(new UserListWidget(
font,
widgetsX, 90, widgetsWidth, cancelY - 90,
widgetsX, 90, widgetsWidth, cancelY - 94,
this::getActions,
userList
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,12 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return (entry != null && entry.keyPressed(keyCode, scanCode, modifiers)) || super.keyPressed(keyCode, scanCode, modifiers);
}

@Override
protected int getScrollbarPosition() {
return super.getScrollbarPosition() + 30;
}
//#if MC < 1.21.4
//$$ @Override
//$$ protected int getScrollbarPosition() {
//$$ return super.getScrollbarPosition() + 30;
//$$ }
//#endif

@Override
public int getRowWidth() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.gaming32.worldhost.gui.widget;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import io.github.gaming32.worldhost.WorldHost;
import io.github.gaming32.worldhost.gui.screen.WorldHostScreen;
Expand All @@ -23,6 +24,8 @@
import java.util.List;
import java.util.function.Function;

import static io.github.gaming32.worldhost.gui.screen.WorldHostScreen.*;

//#if MC >= 1.20.0
import net.minecraft.client.gui.GuiGraphics;
//#else
Expand All @@ -46,7 +49,8 @@ public final class UserListWidget
//#endif
{
private final List<UserInfo> users = new ArrayList<>();
private final List<Button> actionButtons = new ArrayList<>();
private final List<ActionButtonWrapper> actionButtons = new ArrayList<>();
private final List<? extends GuiEventListener> children = Lists.transform(actionButtons, ActionButtonWrapper::button);
private final Font font;
private final Function<FriendListFriend, List<Action>> getApplicableActions;

Expand Down Expand Up @@ -91,6 +95,13 @@ public void renderWidget(
//#endif
int mouseX, int mouseY, float partialTick
) {
pose(context).pushPose();

//#if MC >= 1.21.4
context.enableScissor(getX(), getY(), getX() + width, getY() + height);
pose(context).translate(0, -scrollAmount(), 0);
//#endif

final int textYOffset = 10 - font.lineHeight / 2;
final int x = getX();
int y = getY();
Expand Down Expand Up @@ -120,9 +131,22 @@ public void renderWidget(
}
y += 24;
}
for (final Button button : actionButtons) {
button.render(context, mouseX, mouseY, partialTick);
pose(context).popPose();

for (final var button : actionButtons) {
//#if MC >= 1.21.4
button.button.setPosition(
button.baseX - (scrollbarVisible() ? 10 : 0),
button.baseY - (int)scrollAmount()
);
//#endif
button.button.render(context, mouseX, mouseY, partialTick);
}

//#if MC >= 1.21.4
context.disableScissor();
renderScrollbar(context);
//#endif
}

//#if MC >= 1.19.4
Expand Down Expand Up @@ -169,27 +193,44 @@ private void addButtons(int fromI) {
final UserInfo user = users.get(i);
int x = getRight() - 24 * user.actions.size() + 4;
for (final Action action : user.actions) {
actionButtons.add(
WorldHostScreen.button(action.text, b -> action.apply.run())
actionButtons.add(new ActionButtonWrapper(
button(action.text, b -> action.apply.run())
.tooltip(action.tooltip)
.pos(x, y)
.size(20, 20)
.build()
);
.build(),
x, y
));
x += 24;
}
y += 24;
}
}

public int getVisibleCount() {
return Math.min(users.size(), getHeight() / 24);
//#if MC >= 1.21.4
return users.size();
//#else
//$$ return Math.min(users.size(), getHeight() / 24);
//#endif
}

@Override
public @NotNull List<? extends GuiEventListener> children() {
return actionButtons;
return children;
}

//#if MC >= 1.21.4
@Override
protected int contentHeight() {
return 24 * users.size();
}

@Override
protected double scrollRate() {
return 12.0;
}
//#endif

//#if MC < 1.19.4
//$$ private int getX() {
Expand Down Expand Up @@ -296,4 +337,7 @@ public Action(Component text, Runnable apply) {
this(text, null, apply);
}
}

public record ActionButtonWrapper(Button button, int baseX, int baseY) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.util.Crypt;
import net.minecraft.util.CryptException;
import org.apache.commons.io.input.BoundedInputStream;
import org.apache.commons.io.input.CountingInputStream;
import org.jetbrains.annotations.Nullable;

import javax.crypto.Cipher;
Expand All @@ -40,12 +39,16 @@
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;

//#if MC >= 1.20.2
import com.mojang.authlib.exceptions.ForcedUsernameChangeException;
//#endif

//#if MC < 1.20.4
//$$ import com.mojang.authlib.GameProfile;
//#endif

//#if MC >= 1.20.2
import com.mojang.authlib.exceptions.ForcedUsernameChangeException;
//#if MC < 1.21.4
//$$ import org.apache.commons.io.input.CountingInputStream;
//#endif

public final class ProtocolClient implements AutoCloseable, ProxyPassthrough {
Expand Down Expand Up @@ -164,23 +167,31 @@ public ProtocolClient(String host, boolean successToast, boolean failureToast) {
continue;
}
final int typeId = dis.readUnsignedByte();
final BoundedInputStream bis = new BoundedInputStream(dis, length);
bis.setPropagateClose(false);
final var cis = new CountingInputStream(bis);
//#if MC >= 1.21.4
final var is = BoundedInputStream.builder()
.setInputStream(dis)
.setPropagateClose(false)
.setMaxCount(length)
.get();
//#else
//$$ final BoundedInputStream bis = new BoundedInputStream(dis, length);
//$$ bis.setPropagateClose(false);
//$$ final var is = new CountingInputStream(bis); // TODO: Remove when 1.20.2+ becomes the minimum
//#endif
WorldHostS2CMessage message = null;
try {
message = WorldHostS2CMessage.decode(typeId, new DataInputStream(cis));
message = WorldHostS2CMessage.decode(typeId, new DataInputStream(is));
} catch (EOFException e) {
WorldHost.LOGGER.error("Message decoder for message {} read past end (length {})!", typeId, length);
} catch (Exception e) {
WorldHost.LOGGER.error("Error decoding WH message", e);
}
if (cis.getCount() < length) {
if (is.getCount() < length) {
WorldHost.LOGGER.warn(
"Didn't read entire message (read: {}, total: {}, message: {})",
cis.getCount(), length, message
is.getCount(), length, message
);
dis.skipNBytes(length - cis.getCount());
dis.skipNBytes(length - is.getCount()); // TODO: getRemaining when 1.21.4+ becomes the minimum
}
if (message == null) continue; // An error occurred!
WorldHost.LOGGER.debug("Received {}", message);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ modId = "minecraft"
##elseif MC == 1.21.1
#?? versionRange = "[1.21.0,1.21.2)"
##elseif MC == 1.21.3
versionRange = "[1.21.2,1.21.4)"
#?? versionRange = "[1.21.2,1.21.4)"
##else
#?? versionRange = "[$mc_version]"
versionRange = "[$mc_version]"
##endif
type = "required"
ordering = "NONE"
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
//#elseif MC == 1.21.1
//?? "minecraft": ">=1.21.0 <1.21.2",
//#elseif MC == 1.21.3
"minecraft": ">=1.21.2 <1.21.4",
//?? "minecraft": ">=1.21.2 <1.21.4",
//#else
//?? "minecraft": "$mc_version",
"minecraft": "$mc_version",
//#endif
"fabric-resource-loader-v0": "*"
},
Expand Down
7 changes: 6 additions & 1 deletion version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ dependencies {
})

when {
isFabric -> modImplementation("net.fabricmc:fabric-loader:0.16.7")
isFabric -> modImplementation("net.fabricmc:fabric-loader:0.16.9")
isForge ->
when (mcVersion) {
1_20_01 -> "47.1.3"
Expand All @@ -174,6 +174,7 @@ dependencies {
}.let { "forge"("net.minecraftforge:forge:$mcVersionString-$it") }
isNeoForge ->
when (mcVersion) {
1_21_04 -> "21.4.1-beta"
1_21_03 -> "21.3.56"
1_21_01 -> "21.1.1"
1_20_06 -> "20.6.115"
Expand All @@ -189,6 +190,7 @@ dependencies {

if (isFabric) {
when (mcVersion) {
1_21_04 -> "12.0.0-beta.1" // TODO: Use actual version
1_21_03 -> "12.0.0-beta.1"
1_21_01 -> "11.0.1"
1_20_06 -> "10.0.0"
Expand All @@ -211,6 +213,7 @@ dependencies {

if (isFabric) {
when (mcVersion) {
1_21_04 -> "0.110.5+1.21.4"
1_21_03 -> "0.106.1+1.21.3"
1_21_01 -> "0.102.0+1.21.1"
1_20_06 -> "0.100.0+1.20.6"
Expand Down Expand Up @@ -247,6 +250,7 @@ dependencies {

compileOnly("de.maxhenkel.voicechat:voicechat-api:2.5.0")
when (mcVersion) {
1_21_04 -> "2.5.26"
1_21_03 -> "2.5.24"
1_21_01 -> "2.5.20"
1_20_06 -> "2.5.20"
Expand Down Expand Up @@ -330,6 +334,7 @@ tasks.processResources {
// TODO: Remove pack.mcmeta in 1.20.4
filesMatching("pack.mcmeta") {
expand("pack_format" to when {
mcVersion >= 1_21_04 -> 61
mcVersion >= 1_21_02 -> 42
mcVersion >= 1_21_00 -> 34
mcVersion >= 1_20_05 -> 32
Expand Down
2 changes: 1 addition & 1 deletion versions/mainProject
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.21.3-fabric
1.21.4-fabric

0 comments on commit 8d95265

Please sign in to comment.