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 13, 2024
1 parent c3e2e1c commit 3c853fd
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
## Change
- sync with `sakura-ryoko/servux`
- use BadPackets replace `fabric-networking-api`
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ServuxForged

**This mod requires [BadPackets](https://modrinth.com/mod/badpackets) in 1.20.4 and above.**

Servux unofficial (Neo)Forge port.

ServuxForged is a server-side mod that provides extra support/features for some client-side mods when playing on a server.
Expand Down
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ repositories {
maven { url "https://www.jitpack.io" }
maven { url "https://maven.neoforged.net/releases/" }
maven { url "https://api.modrinth.com/maven" }

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

dependencies {
Expand All @@ -22,7 +29,7 @@ dependencies {
}
neoForge "net.neoforged:neoforge:${project.neoforge_version}"

modImplementation(include("maven.modrinth:neonetwork:0.1.5+mc1.20.6"))
modImplementation "lol.bai:badpackets:neo-${project.badpackets_version}"

implementation "com.google.code.findbugs:jsr305:3.0.2"
}
Expand Down Expand Up @@ -95,7 +102,7 @@ publisher {
setChangelog(file("CHANGELOG.md").getText("UTF-8"))
setVersion("${project.version}")
setDisplayName("${project.version}")
setGameVersions("1.20.5", "1.20.6")
setGameVersions("1.20.6")
setLoaders("neoforge")
setCurseEnvironment("client")
setArtifact(remapJar)
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ mod_id=servux
mod_author=ThinkingStudio

modrinth_id=H9LzoDgA
curseforge_id=1013154
curseforge_id=1013154

badpackets_version=0.7.3
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Objects;
import org.thinkingstudio.fabric.api.networking.v1.PayloadTypeRegistry;
import org.thinkingstudio.fabric.api.networking.v1.ServerPlayNetworking;
//import org.thinkingstudio.fabric.api.networking.v1.PayloadTypeRegistry;
//import org.thinkingstudio.fabric.api.networking.v1.ServerPlayNetworking;
import lol.bai.badpackets.api.PacketReceiver;
import lol.bai.badpackets.api.play.PlayPackets;
import lol.bai.badpackets.api.play.ServerPlayContext;
import lol.bai.badpackets.impl.registry.ChannelRegistry;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf;
Expand All @@ -22,7 +26,7 @@
* Interface for ServerPlayHandler
* @param <T> (Payload Param)
*/
public interface IPluginServerPlayHandler<T extends CustomPayload> extends ServerPlayNetworking.PlayPayloadHandler<T>
public interface IPluginServerPlayHandler<T extends CustomPayload> extends PacketReceiver<ServerPlayContext, T>
{
int FROM_SERVER = 1;
int TO_SERVER = 2;
Expand Down Expand Up @@ -73,12 +77,12 @@ default void registerPlayPayload(@Nonnull CustomPayload.Id<T> id, @Nonnull Packe
{
switch (direction)
{
case TO_SERVER, FROM_CLIENT -> PayloadTypeRegistry.playC2S().register(id, codec);
case FROM_SERVER, TO_CLIENT -> PayloadTypeRegistry.playS2C().register(id, codec);
case TO_SERVER, FROM_CLIENT -> PlayPackets.registerServerChannel(id, codec);
case FROM_SERVER, TO_CLIENT -> PlayPackets.registerClientChannel(id, codec);
default ->
{
PayloadTypeRegistry.playC2S().register(id, codec);
PayloadTypeRegistry.playS2C().register(id, codec);
PlayPackets.registerServerChannel(id, codec);
PlayPackets.registerClientChannel(id, codec);
}
}
}
Expand All @@ -104,13 +108,14 @@ default void registerPlayPayload(@Nonnull CustomPayload.Id<T> id, @Nonnull Packe
* @param receiver (Your Packet Receiver // if null, uses this::receivePlayPayload)
* @return (True / False)
*/
default boolean registerPlayReceiver(@Nonnull CustomPayload.Id<T> id, @Nullable ServerPlayNetworking.PlayPayloadHandler<T> receiver)
default boolean registerPlayReceiver(@Nonnull CustomPayload.Id<T> id, @Nullable PacketReceiver<ServerPlayContext, T> receiver)
{
if (this.isPlayRegistered(this.getPayloadChannel()))
{
try
{
return ServerPlayNetworking.registerGlobalReceiver(id, Objects.requireNonNullElse(receiver, this::receivePlayPayload));
PlayPackets.registerServerReceiver(id, Objects.requireNonNullElse(receiver, this::receivePlayPayload));
return true;
}
catch (IllegalArgumentException e)
{
Expand All @@ -130,7 +135,8 @@ default boolean registerPlayReceiver(@Nonnull CustomPayload.Id<T> id, @Nullable
*/
default void unregisterPlayReceiver()
{
ServerPlayNetworking.unregisterGlobalReceiver(this.getPayloadChannel());
ChannelRegistry.PLAY_S2C.has(this.getPayloadChannel());
//ServerPlayNetworking.unregisterGlobalReceiver(this.getPayloadChannel());
}

/**
Expand All @@ -139,7 +145,7 @@ default void unregisterPlayReceiver()
* @param payload (Payload to decode)
* @param ctx (Fabric Context)
*/
void receivePlayPayload(T payload, ServerPlayNetworking.Context ctx);
void receivePlayPayload(ServerPlayContext ctx, T payload);

/**
* Receive Payload via the legacy "onCustomPayload" from a Network Handler Mixin interface.
Expand Down Expand Up @@ -194,9 +200,9 @@ default boolean sendPlayPayload(@Nonnull ServerPlayerEntity player, @Nonnull T p
{
if (payload.getId().id().equals(this.getPayloadChannel()) && this.isPlayRegistered(this.getPayloadChannel()))
{
if (ServerPlayNetworking.canSend(player, payload.getId()))
if (player.networkHandler.hasChannel(payload.getId()))
{
ServerPlayNetworking.send(player, payload);
player.networkHandler.send(payload);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.util.Map;
import java.util.UUID;
import io.netty.buffer.Unpooled;
import org.thinkingstudio.fabric.api.networking.v1.ServerPlayNetworking;
//import org.thinkingstudio.fabric.api.networking.v1.ServerPlayNetworking;
import lol.bai.badpackets.api.play.ServerPlayContext;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand All @@ -22,9 +23,9 @@ public abstract class ServuxStructuresHandler<T extends CustomPayload> implement
{
private static final ServuxStructuresHandler<ServuxStructuresPacket.Payload> INSTANCE = new ServuxStructuresHandler<>() {
@Override
public void receive(ServuxStructuresPacket.Payload payload, ServerPlayNetworking.Context context)
public void receive(ServerPlayContext context, ServuxStructuresPacket.Payload payload)
{
ServuxStructuresHandler.INSTANCE.receivePlayPayload(payload, context);
ServuxStructuresHandler.INSTANCE.receivePlayPayload(context, payload);
}
};
public static ServuxStructuresHandler<ServuxStructuresPacket.Payload> getInstance() { return INSTANCE; }
Expand Down Expand Up @@ -104,7 +105,7 @@ public void resetFailures(Identifier channel, ServerPlayerEntity player)
}

@Override
public void receivePlayPayload(T payload, ServerPlayNetworking.Context ctx)
public void receivePlayPayload(ServerPlayContext ctx, T payload)
{
if (payload.getId().id().equals(CHANNEL_ID))
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ ordering = "NONE"
side = "SERVER"

[[dependencies.servux]]
modId = "neonetwork"
modId = "badpackets"
type = "required"
versionRange = "*"
ordering = "NONE"
Expand Down

0 comments on commit 3c853fd

Please sign in to comment.