Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fabric 1.21 Support #874

Merged
merged 12 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buildSrc/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[versions]
shadow = "8.1.1"
shadow = "8.1.8"
jetbrains-annotations = "23.0.0"
via-nbt = "4.1.0"
fast-util = "8.5.6"
gson = "2.8.9"
java-diff-utils = "4.12"

[libraries]
shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "shadow" }
shadow = { group = "io.github.goooler.shadow", name = "shadow-gradle-plugin", version.ref = "shadow" }
jetbrains-annotations = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrains-annotations" }
via-nbt = { group = "com.viaversion", name = "nbt", version.ref = "via-nbt" }
fast-util = { group = "it.unimi.dsi", name = "fastutil", version.ref = "fast-util" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
maven("https://oss.sonatype.org/content/groups/public/")
}

val isShadow = project.pluginManager.hasPlugin("com.github.johnrengelman.shadow")
val isShadow = project.pluginManager.hasPlugin("io.github.goooler.shadow")

dependencies {
compileOnly("org.jetbrains:annotations:23.0.0")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
`java-library`
com.github.johnrengelman.shadow
io.github.goooler.shadow
}

group = rootProject.group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
java
com.github.johnrengelman.shadow
io.github.goooler.shadow
}

tasks {
Expand Down
24 changes: 4 additions & 20 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
plugins {
packetevents.`library-conventions`
alias(libs.plugins.fabric)
alias(libs.plugins.fabric.loom)
}

repositories {
mavenCentral()
maven("https://repo.codemc.io/repository/maven-snapshots/")
maven {
name = "ParchmentMC"
url = uri("https://maven.parchmentmc.org")
}
}

val includeAll: Configuration by configurations.creating

val minecraft_version: String by project
val parchment_minecraft_version: String by project
val parchment_mappings: String by project
Expand All @@ -25,12 +22,12 @@ dependencies {
api(project(":api", "shadow"))
api(project(":netty-common"))

include(libs.bundles.adventure)
include(project(":api", "shadow"))
include(project(":netty-common"))

// To change the versions see the gradle.properties file
// To change the versions, see the gradle.properties file
minecraft("com.mojang:minecraft:$minecraft_version")

mappings(loom.layered {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-$parchment_minecraft_version:$parchment_mappings")
Expand All @@ -42,22 +39,9 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabric_version")
}

val targetJavaVersion = 17
tasks {
processResources {
inputs.property("version", project.version)
filteringCharset = Charsets.UTF_8.name()

filesMatching("fabric.mod.json") {
expand(mapOf("version" to project.version))
}
}

withType<JavaCompile> {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
val targetJavaVersion = 17
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible) {
options.release = targetJavaVersion
}
Expand Down
17 changes: 8 additions & 9 deletions fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20
parchment_mappings=2023.03.12
parchment_minecraft_version=1.19.3
# check these on https://fabricmc.net/develop
minecraft_version=1.21
parchment_mappings=2024.06.23
parchment_minecraft_version=1.21
loader_version=0.15.11
# Mod Properties
mod_version=2.3.0
maven_group=io.github.retrooper
archives_base_name=packetevents

# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.83.0+1.20
fabric_version=0.100.7+1.21
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.contents.LiteralContents;
import net.minecraft.network.chat.contents.PlainTextContents;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -25,23 +25,8 @@ public class PacketEventsMod implements PreLaunchEntrypoint, ModInitializer {
@Override
public void onPreLaunch() {
PacketEvents.setAPI(FabricPacketEventsBuilder.build("packetevents"));
PacketEvents.getAPI().getSettings().debug(true);
//PacketEvents.getAPI().getSettings().debug(true);
PacketEvents.getAPI().load();
/*PacketEvents.getAPI().getEventManager().registerListener(new PacketListenerAbstract() {
@Override
public void onPacketSend(PacketSendEvent event) {
if (event.getPacketType() == PacketType.Play.Server.KEEP_ALIVE) {
WrapperPlayServerKeepAlive kp = new WrapperPlayServerKeepAlive(event);
Minecraft.getInstance().gui.getChat().addMessage(MutableComponent.create(new LiteralContents("keep alive: " + kp.getId())));
LOGGER.info("debug Keep alive: " + kp.getId());
}
}

@Override
public void onUserDisconnect(UserDisconnectEvent event) {
LOGGER.info("DISCONNECTED PACKETEVENTS");
}
});*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToMessageDecoder;
import net.minecraft.client.player.LocalPlayer;

Expand All @@ -31,7 +32,6 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)
ByteBuf outputBuffer = ctx.alloc().buffer().writeBytes(msg);
boolean recompress = handleCompression(ctx, outputBuffer);
PacketEventsImplHelper.handleClientBoundPacket(ctx.channel(), user, player, outputBuffer, false);
//TODO hasTasksAfter
if (outputBuffer.isReadable()) {
if (recompress) {
recompress(ctx, outputBuffer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package io.github.retrooper.packetevents.handler;

import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.util.EventCreationUtil;
import com.github.retrooper.packetevents.util.PacketEventsImplHelper;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
Expand Down Expand Up @@ -61,8 +57,8 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
@Override
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
if (msg.isReadable()) {
PacketEventsImplHelper.handleServerBoundPacket(ctx.channel(), user, player, msg, false);
out.writeBytes(msg);
ByteBuf buffer = (ByteBuf) PacketEventsImplHelper.handleServerBoundPacket(ctx.channel(), user, player, msg, false);
out.writeBytes(buffer.retain());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelPipeline;
import net.minecraft.network.BandwidthDebugMonitor;
import net.minecraft.network.protocol.PacketFlow;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Arrays;


@Mixin(net.minecraft.network.Connection.class)
public class PacketEventsInjectorMixin {
@Inject(method = "configureSerialization", at = @At("TAIL"))
private static void configureSerialization(ChannelPipeline cp, PacketFlow pf, CallbackInfo info) throws Exception {
PacketEventsMod.LOGGER.info("Connected!");
Channel channel = cp.channel();
private static void configureSerialization(ChannelPipeline pipeline, PacketFlow flow, boolean memoryOnly, BandwidthDebugMonitor bandwithDebugMonitor, CallbackInfo ci) throws Exception {
PacketEvents.getAPI().getLogManager().debug("Game connected!");
Channel channel = pipeline.channel();
User user = new User(channel, ConnectionState.HANDSHAKING, ClientVersion.getLatest(),
new UserProfile(null, null));
ProtocolManager.USERS.put(channel, user);
Expand Down
5 changes: 2 additions & 3 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "${version}",
"name": "PacketEvents",
"description": "",
"authors": [],
"authors": ["retrooper"],
"contact": {},
"license": "GPL-3.0",
"icon": "assets/packetevents/icon.png",
Expand All @@ -22,7 +22,6 @@
],
"depends": {
"fabricloader": ">=0.15.11",
"fabric": "*",
"minecraft": "1.20"
"fabric-api": "*"
}
}
8 changes: 6 additions & 2 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[versions]
adventure = "4.17.0"
examination = "1.3.0"
netty = "4.1.72.Final"
jetbrains-annotations = "23.0.0"
via-version = "4.5.0"
Expand All @@ -12,6 +13,9 @@ run-paper = "2.3.0"
[libraries]
adventure-api = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" }
adventure-nbt = { group = "net.kyori", name = "adventure-nbt", version.ref = "adventure" }
adventure-key = { group = "net.kyori", name = "adventure-key", version.ref = "adventure" }
adventure-examination-api = { group = "net.kyori", name = "examination-api", version.ref = "examination" }
adventure-examination-string = { group = "net.kyori", name = "examination-string", version.ref = "examination" }
adventure-text-serializer-gson = { group = "net.kyori", name = "adventure-text-serializer-gson", version.ref = "adventure" }
adventure-text-serializer-legacy = { group = "net.kyori", name = "adventure-text-serializer-legacy", version.ref = "adventure" }
adventure-text-serializer-json-legacy = { group = "net.kyori", name = "adventure-text-serializer-json-legacy-impl", version.ref = "adventure" }
Expand All @@ -25,10 +29,10 @@ bungeecord = { group = "net.md-5", name = "bungeecord-api", version.ref = "bunge
velocity = { group = "com.velocitypowered", name = "velocity-api", version.ref = "velocity" }

[bundles]
adventure = [ "adventure-api", "adventure-nbt" ]
adventure = [ "adventure-api", "adventure-nbt", "adventure-key", "adventure-examination-api", "adventure-examination-string" ]
adventure-serializers = [ "adventure-text-serializer-gson", "adventure-text-serializer-json-legacy", "adventure-text-serializer-legacy" ]

[plugins]
run-paper = { id = "xyz.jpenilla.run-paper", version.ref = "run-paper" }
run-velocity = { id = "xyz.jpenilla.run-velocity", version.ref = "run-paper" }
fabric = { id = "fabric-loom", version = "0.11-SNAPSHOT" }
fabric-loom = { id = "fabric-loom", version = "1.7.2" }