-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: XyperCode <xypercode@ultreon.dev>
- Loading branch information
Showing
51 changed files
with
857 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
common/src/main/java/dev/ultreon/mods/xinexlib/dev/commands/DevSendMessageCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dev.ultreon.mods.xinexlib.dev.commands; | ||
|
||
public class DevSendMessageCommand { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
common/src/main/java/dev/ultreon/mods/xinexlib/dev/network/handler/DevClientPlayHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.ultreon.mods.xinexlib.dev.network.handler; | ||
|
||
import dev.ultreon.mods.xinexlib.dev.network.packets.PacketToClient; | ||
|
||
public abstract class DevClientPlayHandler { | ||
public abstract void handle(PacketToClient packet); | ||
} |
13 changes: 13 additions & 0 deletions
13
...src/main/java/dev/ultreon/mods/xinexlib/dev/network/handler/DevClientPlayHandlerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.ultreon.mods.xinexlib.dev.network.handler; | ||
|
||
import dev.ultreon.mods.xinexlib.dev.network.packets.PacketToClient; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.chat.Component; | ||
|
||
public class DevClientPlayHandlerImpl extends DevClientPlayHandler { | ||
@Override | ||
public void handle(PacketToClient packet) { | ||
String message = packet.message(); | ||
Minecraft.getInstance().player.displayClientMessage(Component.literal(message), true); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
common/src/main/java/dev/ultreon/mods/xinexlib/dev/network/handler/DevServerPlayHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.ultreon.mods.xinexlib.dev.network.handler; | ||
|
||
import dev.ultreon.mods.xinexlib.dev.network.packets.PacketToServer; | ||
import dev.ultreon.mods.xinexlib.network.PacketInfo; | ||
import net.minecraft.network.chat.Component; | ||
|
||
import java.util.UUID; | ||
|
||
public class DevServerPlayHandler { | ||
public void handle(PacketToServer packet, PacketInfo packetInfo) { | ||
UUID uuid = packet.uuid(); | ||
packetInfo.sender().sendSystemMessage(Component.nullToEmpty("Hello, the UUID is: " + uuid)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
common/src/main/java/dev/ultreon/mods/xinexlib/dev/network/packets/PacketToClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dev.ultreon.mods.xinexlib.dev.network.packets; | ||
|
||
import dev.ultreon.mods.xinexlib.network.INetworker; | ||
import dev.ultreon.mods.xinexlib.network.packet.IPacketToClient; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.chat.Component; | ||
|
||
public record PacketToClient( | ||
String message | ||
) implements IPacketToClient<PacketToClient> { | ||
|
||
public static PacketToClient read(RegistryFriendlyByteBuf buf) { | ||
Thread.dumpStack(); | ||
return new PacketToClient(buf.readUtf()); | ||
} | ||
|
||
public void write(RegistryFriendlyByteBuf buf) { | ||
buf.writeUtf(message); | ||
} | ||
|
||
@Override | ||
public void handle(INetworker networker) { | ||
Minecraft.getInstance().player.displayClientMessage(Component.literal(message), true); | ||
System.out.println(message); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
common/src/main/java/dev/ultreon/mods/xinexlib/dev/network/packets/PacketToServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.ultreon.mods.xinexlib.dev.network.packets; | ||
|
||
import dev.ultreon.mods.xinexlib.network.INetworker; | ||
import dev.ultreon.mods.xinexlib.network.packet.IPacketToServer; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
import java.util.UUID; | ||
|
||
public record PacketToServer( | ||
UUID uuid | ||
) implements IPacketToServer<PacketToServer> { | ||
public static PacketToServer read(RegistryFriendlyByteBuf buf) { | ||
return new PacketToServer(buf.readUUID()); | ||
} | ||
|
||
public void write(RegistryFriendlyByteBuf buf) { | ||
buf.writeUUID(uuid); | ||
} | ||
|
||
@Override | ||
public void handle(INetworker connection, ServerPlayer player) { | ||
player.sendSystemMessage(Component.nullToEmpty("Hello, the UUID is: " + uuid)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
common/src/main/java/dev/ultreon/mods/xinexlib/mixin/MixinClientConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dev.ultreon.mods.xinexlib.mixin; | ||
|
||
import dev.ultreon.mods.xinexlib.client.ClientClass; | ||
import net.minecraft.network.Connection; | ||
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; | ||
|
||
/// @author XyperCode | ||
/// @since 0.1.0 (December 10, 2024) | ||
@Mixin(Connection.class) | ||
public abstract class MixinClientConnection { | ||
|
||
@Inject(at = @At("HEAD"), method = "channelInactive") | ||
private void channelInactive(CallbackInfo ci) { | ||
ClientClass.onDisconnect(); | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "disconnect(Lnet/minecraft/network/DisconnectionDetails;)V") | ||
private void runTick$return(CallbackInfo ci) { | ||
ClientClass.onDisconnect(); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
common/src/main/java/dev/ultreon/mods/xinexlib/mixin/MixinConnection.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
common/src/main/java/dev/ultreon/mods/xinexlib/network/INetworkRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.ultreon.mods.xinexlib.network; | ||
|
||
import dev.ultreon.mods.xinexlib.network.endpoint.IClientEndpoint; | ||
import dev.ultreon.mods.xinexlib.network.endpoint.IServerEndpoint; | ||
import dev.ultreon.mods.xinexlib.network.packet.IPacket; | ||
|
||
public interface INetworkRegistry { | ||
<T extends IPacket<T> & IClientEndpoint> void registerClient(String name, Class<T> clazz, IPacketReader<T> reader); | ||
|
||
<T extends IPacket<T> & IServerEndpoint> void registerServer(String name, Class<T> clazz, IPacketReader<T> reader); | ||
|
||
<T extends IPacket<T> & IServerEndpoint & IClientEndpoint> void registerBiDirectional(String name, Class<T> clazz, IPacketReader<T> reader); | ||
} |
30 changes: 30 additions & 0 deletions
30
common/src/main/java/dev/ultreon/mods/xinexlib/network/INetworker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package dev.ultreon.mods.xinexlib.network; | ||
|
||
import dev.ultreon.mods.xinexlib.network.endpoint.IClientEndpoint; | ||
import dev.ultreon.mods.xinexlib.network.endpoint.IServerEndpoint; | ||
import dev.ultreon.mods.xinexlib.network.packet.IPacket; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public interface INetworker { | ||
<T extends IPacket<T> & IServerEndpoint> void sendToServer(T payload); | ||
|
||
<T extends IPacket<T> & IClientEndpoint> void sendToClient(T payload, ServerPlayer player); | ||
|
||
default <T extends IPacket<T> & IClientEndpoint> void sendToClients(T payload, ServerPlayer... players) { | ||
for (ServerPlayer player : players) { | ||
sendToClient(payload, player); | ||
} | ||
} | ||
|
||
default <T extends IPacket<T> & IClientEndpoint> void sendToClients(T payload, Iterable<ServerPlayer> players) { | ||
for (ServerPlayer player : players) { | ||
sendToClient(payload, player); | ||
} | ||
} | ||
|
||
default <T extends IPacket<T> & IClientEndpoint> void sendToClients(T payload, Stream<ServerPlayer> players) { | ||
players.forEach(player -> sendToClient(payload, player)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
common/src/main/java/dev/ultreon/mods/xinexlib/network/IPacketReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.ultreon.mods.xinexlib.network; | ||
|
||
import dev.ultreon.mods.xinexlib.network.packet.IPacket; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
|
||
@FunctionalInterface | ||
public interface IPacketReader<T extends IPacket<?>> { | ||
T read(RegistryFriendlyByteBuf buffer); | ||
} |
12 changes: 12 additions & 0 deletions
12
common/src/main/java/dev/ultreon/mods/xinexlib/network/PacketInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.ultreon.mods.xinexlib.network; | ||
|
||
import net.minecraft.server.level.ServerPlayer; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public record PacketInfo( | ||
@Nullable ServerPlayer sender | ||
) { | ||
public PacketInfo() { | ||
this(null); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
common/src/main/java/dev/ultreon/mods/xinexlib/network/PayloadWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package dev.ultreon.mods.xinexlib.network; | ||
|
||
import dev.ultreon.mods.xinexlib.network.packet.IPacket; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
|
||
class PayloadWrapper<T extends IPacket<?>> implements CustomPacketPayload { | ||
private final Type<PayloadWrapper<T>> type; | ||
T packet; | ||
|
||
PayloadWrapper(Type<PayloadWrapper<T>> type) { | ||
this.type = type; | ||
} | ||
|
||
PayloadWrapper(Type<PayloadWrapper<T>> type, T packet) { | ||
this.type = type; | ||
this.packet = packet; | ||
} | ||
|
||
@Override | ||
public Type<? extends CustomPacketPayload> type() { | ||
return type; | ||
} | ||
|
||
public void write(RegistryFriendlyByteBuf object) { | ||
packet.write(object); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
common/src/main/java/dev/ultreon/mods/xinexlib/network/endpoint/IClientEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.ultreon.mods.xinexlib.network.endpoint; | ||
|
||
import dev.ultreon.mods.xinexlib.network.INetworker; | ||
|
||
public interface IClientEndpoint { | ||
void handle(INetworker connection); | ||
} |
8 changes: 8 additions & 0 deletions
8
common/src/main/java/dev/ultreon/mods/xinexlib/network/endpoint/IServerEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package dev.ultreon.mods.xinexlib.network.endpoint; | ||
|
||
import dev.ultreon.mods.xinexlib.network.INetworker; | ||
import net.minecraft.server.level.ServerPlayer; | ||
|
||
public interface IServerEndpoint { | ||
void handle(INetworker connection, ServerPlayer player); | ||
} |
7 changes: 7 additions & 0 deletions
7
common/src/main/java/dev/ultreon/mods/xinexlib/network/packet/IPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.ultreon.mods.xinexlib.network.packet; | ||
|
||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
|
||
public interface IPacket<T extends IPacket<T>> { | ||
void write(RegistryFriendlyByteBuf buffer); | ||
} |
7 changes: 7 additions & 0 deletions
7
common/src/main/java/dev/ultreon/mods/xinexlib/network/packet/IPacketToClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.ultreon.mods.xinexlib.network.packet; | ||
|
||
import dev.ultreon.mods.xinexlib.network.endpoint.IClientEndpoint; | ||
|
||
public interface IPacketToClient<T extends IPacket<T>> extends IPacket<T>, IClientEndpoint { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
common/src/main/java/dev/ultreon/mods/xinexlib/network/packet/IPacketToEither.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.ultreon.mods.xinexlib.network.packet; | ||
|
||
import dev.ultreon.mods.xinexlib.network.endpoint.IServerEndpoint; | ||
|
||
public interface IPacketToEither<T extends IPacket<T>> extends IPacket<T>, IServerEndpoint { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
common/src/main/java/dev/ultreon/mods/xinexlib/network/packet/IPacketToServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.ultreon.mods.xinexlib.network.packet; | ||
|
||
import dev.ultreon.mods.xinexlib.network.endpoint.IServerEndpoint; | ||
|
||
public interface IPacketToServer<T extends IPacket<T>> extends IPacket<T>, IServerEndpoint { | ||
|
||
} |
Oops, something went wrong.