Skip to content

Commit

Permalink
use BadPackets replace fabric-networking-api
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Jul 14, 2024
1 parent 8f3b49f commit 5418093
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ logs/
.project
build.number
/.idea/
/run/
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## Change
- port to NeoForge
- use BadPackets replace `fabric-networking-api`
30 changes: 13 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@ plugins {
id "com.hypherionmc.modutils.modpublisher" version "2.+"
}

sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17

group = project.maven_group
archivesBaseName = project.archives_base_name
base.archivesName = project.archives_base_name
version = "${project.mod_version}-mc${project.minecraft_version}"

repositories {
maven { url "https://www.jitpack.io" }
maven { url "https://maven.neoforged.net/releases/" }

maven {
url "https://maven2.bai.lol"
content {
includeGroup "lol.bai"
}
}
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
neoForge "net.neoforged:neoforge:${project.neoforge_version}"

modApi(include("com.github.ThinkingStudios:ForgedNetworkingAPI:0.1.0-mc1.20.4"))
modImplementation "lol.bai:badpackets:neo-${project.badpackets_version}"

implementation "com.google.code.findbugs:jsr305:3.0.2"
}
Expand All @@ -45,20 +50,9 @@ tasks.withType(JavaCompile).configureEach {

java {
withSourcesJar()
}

jar {
manifest {
attributes([
"Specification-Title" : project.mod_id,
"Specification-Vendor" : project.mod_author,
"Specification-Version" : "1",
"Implementation-Title" : project.name,
"Implementation-Version" : version,
"Implementation-Vendor" : project.mod_author,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

// configure the maven publication
Expand Down Expand Up @@ -95,4 +89,6 @@ publisher {
setCurseEnvironment("client")
setArtifact(remapJar)
addAdditionalFile(sourcesJar)
modrinthDepends.required("badpackets")
curseDepends.required("badpackets")
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ mod_id=servux
mod_author=ThinkingStudio

modrinth_id=H9LzoDgA
curseforge_id=1013154
curseforge_id=1013154

badpackets_version=0.6.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fi.dy.masa.servux.network;

import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking.PlayChannelHandler;
import lol.bai.badpackets.api.play.ServerPlayPacketReceiver;
//import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking.PlayChannelHandler;

import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
Expand All @@ -11,7 +12,7 @@ public interface IPluginChannelHandler
{
Identifier getChannel();

default PlayChannelHandler getServerPacketHandler()
default ServerPlayPacketReceiver<PacketByteBuf> getServerPacketHandler()
{
if (this.usePacketSplitter())
{
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/fi/dy/masa/servux/network/PacketSplitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.util.Map;
import javax.annotation.Nullable;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
//import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import lol.bai.badpackets.api.PacketSender;
import org.apache.commons.lang3.tuple.Pair;

import net.minecraft.nbt.NbtCompound;
Expand Down Expand Up @@ -49,7 +50,8 @@ private static void send(Identifier channel, PacketByteBuf packet, int payloadLi

buf.writeBytes(packet, thisLen);

ServerPlayNetworking.send(player, channel, buf);
PacketSender.s2c(player).send(channel, buf);
//ServerPlayNetworking.send(player, channel, buf);
}

packet.release();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package fi.dy.masa.servux.network;

import java.util.HashMap;
import net.fabricmc.fabric.api.networking.v1.S2CPlayChannelEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;

import lol.bai.badpackets.api.play.PlayPackets;
//import net.fabricmc.fabric.api.networking.v1.S2CPlayChannelEvents;
//import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;

import lol.bai.badpackets.impl.registry.ChannelRegistry;
import net.minecraft.util.Identifier;

public class ServerPacketChannelHandler
Expand All @@ -28,19 +31,37 @@ public void registerServerChannelHandler(IPluginChannelHandler handler)

if (handler.isSubscribable())
{
S2CPlayChannelEvents.REGISTER.register((net, server, sender, channels) -> {
PlayPackets.registerServerReadyCallback((net, sender, server) -> {
var channels = ChannelRegistry.PLAY_S2C.getChannels();

if (channels.contains(channel))
{
handler.subscribe(net);
}
});
S2CPlayChannelEvents.UNREGISTER.register((net, server, sender, channels) -> {

PlayPackets.registerServerReadyCallback((net, sender, server) -> {
var channels = ChannelRegistry.PLAY_S2C.getChannels();

if (channels.contains(channel))
{
handler.unsubscribe(net);
}
});
ServerPlayNetworking.registerGlobalReceiver(channel, handler.getServerPacketHandler());
// S2CPlayChannelEvents.REGISTER.register((net, server, sender, channels) -> {
// if (channels.contains(channel))
// {
// handler.subscribe(net);
// }
// });
// S2CPlayChannelEvents.UNREGISTER.register((net, server, sender, channels) -> {
// if (channels.contains(channel))
// {
// handler.unsubscribe(net);
// }
// });
PlayPackets.registerServerReceiver(channel, handler.getServerPacketHandler());
//ServerPlayNetworking.registerGlobalReceiver(channel, handler.getServerPacketHandler());
}
}
}
Expand All @@ -54,7 +75,8 @@ public void unregisterServerChannelHandler(IPluginChannelHandler handler)

if (this.handlers.remove(channel, handler))
{
ServerPlayNetworking.unregisterGlobalReceiver(channel);
ChannelRegistry.PLAY_S2C.getChannels().remove(channel);
//ServerPlayNetworking.unregisterGlobalReceiver(channel);
}
}
}
Expand Down

0 comments on commit 5418093

Please sign in to comment.