diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRoll.java b/common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRoll.java index 9ad8786c..83c27405 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRoll.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRoll.java @@ -3,13 +3,6 @@ import io.netty.buffer.Unpooled; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.Identifier; -import nl.enjarai.doabarrelroll.api.event.ServerEvents; -import nl.enjarai.doabarrelroll.config.ModConfigServer; -import nl.enjarai.doabarrelroll.net.HandshakeServer; -import nl.enjarai.doabarrelroll.net.register.RollSyncServer; -import nl.enjarai.doabarrelroll.net.ServerConfigHolder; -import nl.enjarai.doabarrelroll.net.register.HandshakeServerRegister; -import nl.enjarai.doabarrelroll.net.register.ServerConfigUpdaterRegister; import nl.enjarai.doabarrelroll.platform.Services; import org.slf4j.Logger; @@ -29,18 +22,6 @@ public static Identifier id(String path) { public static void init() { var configFile = Path.of("config"); - - Services.PLATFORM.registerNetworkChannels(HANDSHAKE_CHANNEL, SERVER_CONFIG_UPDATE_CHANNEL, ROLL_CHANNEL); - - CONFIG_HOLDER = new ServerConfigHolder<>(configFile, - ModConfigServer.CODEC, ModConfigServer.DEFAULT, ServerEvents::updateServerConfig); - HANDSHAKE_SERVER = new HandshakeServer(CONFIG_HOLDER, player -> !ModConfigServer.canModify(player)); - - // Register server-side listeners for config syncing, this is done on - // both client and server to ensure everything works in LAN worlds as well. - RollSyncServer.init(); - HandshakeServerRegister.init(); - ServerConfigUpdaterRegister.init(); } public static PacketByteBuf createBuf() { diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollClient.java b/common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollClient.java index 798a96fa..c024a4c2 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollClient.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollClient.java @@ -8,10 +8,8 @@ import nl.enjarai.doabarrelroll.config.ActivationBehaviour; import nl.enjarai.doabarrelroll.config.LimitedModConfigServer; import nl.enjarai.doabarrelroll.config.ModConfig; -import nl.enjarai.doabarrelroll.config.ModConfigServer; -import nl.enjarai.doabarrelroll.net.register.HandshakeClientRegister; import nl.enjarai.doabarrelroll.flight.RotationModifiers; -import nl.enjarai.doabarrelroll.net.HandshakeClient; +import nl.enjarai.doabarrelroll.platform.Services; import nl.enjarai.doabarrelroll.util.MixinHooks; import nl.enjarai.doabarrelroll.util.StarFoxUtil; @@ -49,7 +47,6 @@ public static void init() { ClientEvents.SERVER_CONFIG_UPDATE.register(ModConfig.INSTANCE::notifyPlayerOfServerConfig); ModConfig.touch(); - HandshakeClientRegister.init(); // Init barrel rollery. StarFoxUtil.register(); @@ -63,7 +60,7 @@ public static void clearValues() { } public static boolean isFallFlying() { - if (!HANDSHAKE_CLIENT.getConfig().map(LimitedModConfigServer::forceEnabled).orElse(false)) { + if (!Services.CLIENT_NET.getHandshakeClient().getConfig().map(LimitedModConfigServer::forceEnabled).orElse(false)) { var hybrid = ModConfig.INSTANCE.getActivationBehaviour() == ActivationBehaviour.HYBRID || ModConfig.INSTANCE.getActivationBehaviour() == ActivationBehaviour.HYBRID_TOGGLE; if (hybrid && !MixinHooks.thirdJump) { diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/EventCallbacks.java b/common/src/main/java/nl/enjarai/doabarrelroll/EventCallbacks.java deleted file mode 100644 index 5f8a655b..00000000 --- a/common/src/main/java/nl/enjarai/doabarrelroll/EventCallbacks.java +++ /dev/null @@ -1,14 +0,0 @@ -package nl.enjarai.doabarrelroll; - -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayNetworkHandler; - -public class EventCallbacks { - public static void serverTick(MinecraftServer server) { - DoABarrelRoll.HANDSHAKE_SERVER.tick(server); - } - - public static void playerDisconnected(ServerPlayNetworkHandler handler) { - DoABarrelRoll.HANDSHAKE_SERVER.playerDisconnected(handler); - } -} diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/EventCallbacksClient.java b/common/src/main/java/nl/enjarai/doabarrelroll/EventCallbacksClient.java index f474e4cd..38b535ae 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/EventCallbacksClient.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/EventCallbacksClient.java @@ -24,10 +24,6 @@ public static void clientTick(MinecraftClient client) { StarFoxUtil.clientTick(client); } - public static void clientDisconnect() { - DoABarrelRollClient.HANDSHAKE_CLIENT.reset(); - } - public static void onRenderCrosshair(DrawContext context, float tickDelta, int scaledWidth, int scaledHeight) { if (!DoABarrelRollClient.isFallFlying()) return; diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/ModKeybindings.java b/common/src/main/java/nl/enjarai/doabarrelroll/ModKeybindings.java index 75215a36..35af4375 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/ModKeybindings.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/ModKeybindings.java @@ -8,6 +8,7 @@ import nl.enjarai.doabarrelroll.config.LimitedModConfigServer; import nl.enjarai.doabarrelroll.config.ModConfig; import nl.enjarai.doabarrelroll.config.ModConfigScreen; +import nl.enjarai.doabarrelroll.platform.Services; import org.lwjgl.glfw.GLFW; import java.util.List; @@ -114,7 +115,7 @@ public class ModKeybindings { public static void clientTick(MinecraftClient client) { while (TOGGLE_ENABLED.wasPressed()) { - if (!DoABarrelRollClient.HANDSHAKE_CLIENT.getConfig().map(LimitedModConfigServer::forceEnabled).orElse(false)) { + if (!Services.CLIENT_NET.getHandshakeClient().getConfig().map(LimitedModConfigServer::forceEnabled).orElse(false)) { ModConfig.INSTANCE.setModEnabled(!ModConfig.INSTANCE.getModEnabled()); ModConfig.INSTANCE.save(); @@ -137,7 +138,7 @@ public static void clientTick(MinecraftClient client) { } } while (TOGGLE_THRUST.wasPressed()) { - if (DoABarrelRollClient.HANDSHAKE_CLIENT.getConfig().map(LimitedModConfigServer::allowThrusting).orElse(false)) { + if (Services.CLIENT_NET.getHandshakeClient().getConfig().map(LimitedModConfigServer::allowThrusting).orElse(false)) { ModConfig.INSTANCE.setEnableThrust(!ModConfig.INSTANCE.getEnableThrust()); ModConfig.INSTANCE.save(); diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/compat/yacl/YACLImplementation.java b/common/src/main/java/nl/enjarai/doabarrelroll/compat/yacl/YACLImplementation.java index 6c837412..ff4c1eaa 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/compat/yacl/YACLImplementation.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/compat/yacl/YACLImplementation.java @@ -36,7 +36,7 @@ public static Screen generateConfigScreen(Screen parent) { ClientPlayerEntity player; var onRealms = DoABarrelRollClient.isConnectedToRealms() && (player = MinecraftClient.getInstance().player) != null && player.hasPermissionLevel(2); - var serverConfig = DoABarrelRollClient.HANDSHAKE_CLIENT.getConfig(); + var serverConfig = Services.CLIENT_NET.getHandshakeClient().getConfig(); var thrustingAllowed = new Dependable(serverConfig.map(LimitedModConfigServer::allowThrusting).orElse(!inWorld || onRealms)); var allowDisabled = new Dependable(!serverConfig.map(LimitedModConfigServer::forceEnabled).orElse(false)); @@ -234,8 +234,8 @@ public static Screen generateConfigScreen(Screen parent) { // If we're in a world, use the synced config, otherwise, grab our local one. var fullServerConfig = inWorld - ? DoABarrelRollClient.HANDSHAKE_CLIENT.getFullConfig() - : Optional.of(DoABarrelRoll.CONFIG_HOLDER.instance); + ? Services.CLIENT_NET.getHandshakeClient().getFullConfig() + : Optional.of(Services.SERVER_NET.getServerConfigHolder().instance); MutableConfigServer mut; if (fullServerConfig.isPresent()) { mut = new MutableConfigServer(fullServerConfig.get()); @@ -285,13 +285,13 @@ public static Screen generateConfigScreen(Screen parent) { if (mut != null) { if (MinecraftClient.getInstance().world == null) { - DoABarrelRoll.CONFIG_HOLDER.instance = mut.toImmutable(); + Services.SERVER_NET.getServerConfigHolder().instance = mut.toImmutable(); } else { - var original = DoABarrelRollClient.HANDSHAKE_CLIENT.getConfig(); + var original = Services.CLIENT_NET.getHandshakeClient().getConfig(); if (original.isPresent()){ var imut = mut.toImmutable(); if (!imut.equals(original.get())) { - ServerConfigUpdateClient.prepUpdatePacket(imut); + Services.CLIENT_NET.sendConfigUpdatePacket(imut); configListener.accept(imut); } } diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/config/ModConfig.java b/common/src/main/java/nl/enjarai/doabarrelroll/config/ModConfig.java index d9a4f75d..c83b23a3 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/config/ModConfig.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/config/ModConfig.java @@ -10,6 +10,7 @@ import nl.enjarai.doabarrelroll.api.rotation.RotationInstant; import nl.enjarai.doabarrelroll.config.serialization.ExpressionParserTypeAdapter; import nl.enjarai.doabarrelroll.math.ExpressionParser; +import nl.enjarai.doabarrelroll.platform.Services; import nl.enjarai.doabarrelroll.util.ToastUtil; import java.io.*; @@ -168,7 +169,7 @@ public boolean getEnableThrust() { return true; } - return DoABarrelRollClient.HANDSHAKE_CLIENT.getConfig() + return Services.CLIENT_NET.getHandshakeClient().getConfig() .map(LimitedModConfigServer::allowThrusting) .orElse(false); } diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/mixin/LivingEntityMixin.java b/common/src/main/java/nl/enjarai/doabarrelroll/mixin/LivingEntityMixin.java index 4430251e..59fb5c06 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/mixin/LivingEntityMixin.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/mixin/LivingEntityMixin.java @@ -2,6 +2,7 @@ import net.minecraft.entity.LivingEntity; import nl.enjarai.doabarrelroll.DoABarrelRoll; +import nl.enjarai.doabarrelroll.platform.Services; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; @@ -23,7 +24,7 @@ public abstract class LivingEntityMixin { require = 0 // We let this mixin fail if it needs to as a temporary workaround to be compatible with Connector. ) private float doABarrelRoll$modifyKineticDamage(float original) { - var damageType = DoABarrelRoll.CONFIG_HOLDER.instance.kineticDamage(); + var damageType = Services.SERVER_NET.getServerConfigHolder().instance.kineticDamage(); return switch (damageType) { case VANILLA -> original; diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/mixin/client/roll/entity/ClientPlayerEntityMixin.java b/common/src/main/java/nl/enjarai/doabarrelroll/mixin/client/roll/entity/ClientPlayerEntityMixin.java index c46c15f7..f3a68d8d 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/mixin/client/roll/entity/ClientPlayerEntityMixin.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/mixin/client/roll/entity/ClientPlayerEntityMixin.java @@ -8,7 +8,7 @@ import nl.enjarai.doabarrelroll.flight.RotationModifiers; import nl.enjarai.doabarrelroll.math.MagicNumbers; import nl.enjarai.doabarrelroll.mixin.roll.entity.PlayerEntityMixin; -import nl.enjarai.doabarrelroll.net.register.RollSyncClient; +import nl.enjarai.doabarrelroll.platform.Services; import org.joml.Vector3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -35,7 +35,7 @@ public abstract class ClientPlayerEntityMixin extends PlayerEntityMixin { var isRolling = doABarrelRoll$isRolling(); var rollDiff = doABarrelRoll$getRoll() - lastSentRoll; if (isRolling != lastSentIsRolling || rollDiff != 0.0f) { - RollSyncClient.sendUpdate(this); + Services.CLIENT_NET.sendRollUpdate(this); lastSentIsRolling = isRolling; lastSentRoll = doABarrelRoll$getRoll(); diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/mixin/roll/EntityTrackerEntryMixin.java b/common/src/main/java/nl/enjarai/doabarrelroll/mixin/roll/EntityTrackerEntryMixin.java index f9f90aea..76e89922 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/mixin/roll/EntityTrackerEntryMixin.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/mixin/roll/EntityTrackerEntryMixin.java @@ -3,7 +3,7 @@ import net.minecraft.entity.Entity; import net.minecraft.server.network.EntityTrackerEntry; import nl.enjarai.doabarrelroll.api.RollEntity; -import nl.enjarai.doabarrelroll.net.register.RollSyncServer; +import nl.enjarai.doabarrelroll.platform.Services; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -31,7 +31,7 @@ public abstract class EntityTrackerEntryMixin { var roll = rollEntity.doABarrelRoll$getRoll(); if (isRolling != lastIsRolling || roll != lastRoll) { - RollSyncServer.sendUpdates(entity); + Services.SERVER_NET.sendRollUpdates(entity); lastIsRolling = isRolling; lastRoll = roll; diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeClient.java b/common/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeClient.java index 2961de62..094b5139 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeClient.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeClient.java @@ -10,14 +10,14 @@ import java.util.function.BiFunction; import java.util.function.Consumer; -public class HandshakeClient { - private final BiFunction responseConstructor; +public class HandshakeClient

{ + private final BiFunction responseConstructor; private final Consumer updateCallback; private LimitedModConfigServer serverConfig = null; private ModConfigServer fullServerConfig = null; private boolean hasConnected = false; - public HandshakeClient(BiFunction responseConstructor, Consumer updateCallback) { + public HandshakeClient(BiFunction responseConstructor, Consumer updateCallback) { this.responseConstructor = responseConstructor; this.updateCallback = updateCallback; } @@ -44,7 +44,7 @@ public boolean hasConnected() { return hasConnected; } - public ConfigResponseC2SPacket handleConfigSync(ConfigSyncS2CPacket packet) { + public P handleConfigSync(ConfigSyncS2CPacket packet) { serverConfig = null; fullServerConfig = null; diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeServer.java b/common/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeServer.java index 9cf422a0..f6a311eb 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeServer.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeServer.java @@ -17,10 +17,10 @@ import java.util.WeakHashMap; import java.util.function.Function; -public class HandshakeServer { +public class HandshakeServer

{ public static final int PROTOCOL_VERSION = 4; - private final PacketConstructor packetConstructor; + private final PacketConstructor

packetConstructor; private final ServerConfigHolder configHolder; private final Map syncStates = new WeakHashMap<>(); private final Map scheduledKicks = new WeakHashMap<>(); @@ -28,7 +28,7 @@ public class HandshakeServer { private final Codec transferCodec = ModConfigServer.CODEC; private final Codec limitedTransferCodec = LimitedModConfigServer.getCodec(); - public HandshakeServer(PacketConstructor packetConstructor, ServerConfigHolder configHolder, Function getsLimitedCheck) { + public HandshakeServer(PacketConstructor

packetConstructor, ServerConfigHolder configHolder, Function getsLimitedCheck) { this.packetConstructor = packetConstructor; this.configHolder = configHolder; this.getsLimitedCheck = getsLimitedCheck; @@ -54,7 +54,7 @@ public ClientInfo getHandshakeState(ServerPlayNetworkHandler handler) { return syncStates.computeIfAbsent(handler, key -> new ClientInfo(HandshakeState.NOT_SENT, PROTOCOL_VERSION, true)); } - public ConfigSyncS2CPacket initiateConfigSync(ServerPlayNetworkHandler handler) { + public P initiateConfigSync(ServerPlayNetworkHandler handler) { var isLimited = getsLimitedCheck.apply(handler); getHandshakeState(handler).isLimited = isLimited; var config = configHolder.instance; @@ -128,8 +128,8 @@ public ClientInfo(HandshakeState state, int protocolVersion, boolean isLimited) } } - public interface PacketConstructor { - ConfigSyncS2CPacket construct(int protocolVersion, LimitedModConfigServer applicableConfig, boolean isLimited, ModConfigServer fullConfig); + public interface PacketConstructor

{ + P construct(int protocolVersion, LimitedModConfigServer applicableConfig, boolean isLimited, ModConfigServer fullConfig); } public enum HandshakeState { diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigHolder.java b/common/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigHolder.java index 35a78a5e..846c17e1 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigHolder.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigHolder.java @@ -22,17 +22,17 @@ import java.nio.file.StandardOpenOption; import java.util.function.BiConsumer; -public class ServerConfigHolder { +public class ServerConfigHolder

{ private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public final Path configFile; public final Codec codec; - private final PacketConstructor packetConstructor; - private BiConsumer updateCallback; - private HandshakeServer handshakeServer; + private final PacketConstructor

packetConstructor; + private final BiConsumer updateCallback; + private HandshakeServer handshakeServer; public ModConfigServer instance; - public ServerConfigHolder(Path configFile, Codec codec, PacketConstructor packetConstructor, BiConsumer updateCallback) { + public ServerConfigHolder(Path configFile, Codec codec, PacketConstructor

packetConstructor, BiConsumer updateCallback) { this.configFile = configFile; this.codec = codec; this.packetConstructor = packetConstructor; @@ -83,7 +83,7 @@ public void save() { } } - public ConfigUpdateAckS2CPacket clientSendsUpdate(ServerPlayerEntity player, ConfigUpdateC2SPacket packet) { + public P clientSendsUpdate(ServerPlayerEntity player, ConfigUpdateC2SPacket packet) { var info = handshakeServer.getHandshakeState(player); var accepted = info.state == HandshakeServer.HandshakeState.ACCEPTED; var hasPermission = ModConfigServer.canModify(player.networkHandler); @@ -133,11 +133,11 @@ public ConfigUpdateAckS2CPacket clientSendsUpdate(ServerPlayerEntity player, Con } } - public void setHandshakeServer(HandshakeServer handshakeServer) { + public void setHandshakeServer(HandshakeServer handshakeServer) { this.handshakeServer = handshakeServer; } - public interface PacketConstructor { - ConfigUpdateAckS2CPacket construct(int protocolVersion, boolean success); + public interface PacketConstructor

{ + P construct(int protocolVersion, boolean success); } } diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdateClient.java b/common/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdateClient.java index 76ab7864..6eb6f1e0 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdateClient.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdateClient.java @@ -1,21 +1,20 @@ package nl.enjarai.doabarrelroll.net; -import net.minecraft.network.PacketByteBuf; import nl.enjarai.doabarrelroll.DoABarrelRoll; import nl.enjarai.doabarrelroll.config.ModConfigServer; import nl.enjarai.doabarrelroll.net.packet.ConfigUpdateAckS2CPacket; import nl.enjarai.doabarrelroll.net.packet.ConfigUpdateC2SPacket; import nl.enjarai.doabarrelroll.util.ToastUtil; -public class ServerConfigUpdateClient { - private final PacketConstructor packetConstructor; +public class ServerConfigUpdateClient

{ + private final PacketConstructor

packetConstructor; private boolean waitingForAck = false; - public ServerConfigUpdateClient(PacketConstructor packetConstructor) { + public ServerConfigUpdateClient(PacketConstructor

packetConstructor) { this.packetConstructor = packetConstructor; } - public ConfigUpdateC2SPacket prepUpdatePacket(ModConfigServer config) { + public P prepUpdatePacket(ModConfigServer config) { waitingForAck = true; return packetConstructor.construct(HandshakeServer.PROTOCOL_VERSION, config); } @@ -43,7 +42,7 @@ public void updateAcknowledged(ConfigUpdateAckS2CPacket packet) { } } - public interface PacketConstructor { - ConfigUpdateC2SPacket construct(int protocolVersion, ModConfigServer config); + public interface PacketConstructor

{ + P construct(int protocolVersion, ModConfigServer config); } } diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/platform/services/ClientNetworkUtils.java b/common/src/main/java/nl/enjarai/doabarrelroll/platform/services/ClientNetworkUtils.java index 45f881c5..83bc56df 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/platform/services/ClientNetworkUtils.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/platform/services/ClientNetworkUtils.java @@ -1,16 +1,13 @@ package nl.enjarai.doabarrelroll.platform.services; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; - -import java.util.function.Consumer; +import nl.enjarai.doabarrelroll.api.RollEntity; +import nl.enjarai.doabarrelroll.config.ModConfigServer; +import nl.enjarai.doabarrelroll.net.HandshakeClient; public interface ClientNetworkUtils { - void sendPacket(Identifier channel, PacketByteBuf buf); + void sendRollUpdate(RollEntity entity); - void registerListener(Identifier channel, PacketListener listener); + void sendConfigUpdatePacket(ModConfigServer config); - interface PacketListener { - void accept(PacketByteBuf buf, Consumer responseSender); - } + HandshakeClient getHandshakeClient(); } diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/platform/services/ServerNetworkUtils.java b/common/src/main/java/nl/enjarai/doabarrelroll/platform/services/ServerNetworkUtils.java index 4bcca7d1..90ddf4bd 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/platform/services/ServerNetworkUtils.java +++ b/common/src/main/java/nl/enjarai/doabarrelroll/platform/services/ServerNetworkUtils.java @@ -5,18 +5,13 @@ import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; +import nl.enjarai.doabarrelroll.net.ServerConfigHolder; import java.util.function.Consumer; import java.util.function.Predicate; public interface ServerNetworkUtils { - void sendPacket(ServerPlayNetworkHandler handler, Identifier channel, PacketByteBuf buf); + void sendRollUpdates(Entity entity); - void sendPacketsToTracking(Entity entity, Predicate predicate, Identifier channel, PacketByteBuf buf); - - void registerListener(Identifier channel, PacketListener listener); - - interface PacketListener { - void accept(ServerPlayNetworkHandler source, PacketByteBuf buf, Consumer responseSender); - } + ServerConfigHolder getServerConfigHolder(); } diff --git a/common/src/main/resources/do_a_barrel_roll.mixins.json b/common/src/main/resources/do_a_barrel_roll.mixins.json index 1ce8b1eb..e8b11efd 100644 --- a/common/src/main/resources/do_a_barrel_roll.mixins.json +++ b/common/src/main/resources/do_a_barrel_roll.mixins.json @@ -5,7 +5,7 @@ "refmap": "${mod_id}.refmap.json", "compatibilityLevel": "JAVA_17", "mixins": [ - "CommandManagerMixin", + "fabric.CommandManagerMixin", "LivingEntityMixin", "roll.EntityTrackerEntryMixin", "roll.entity.EntityMixin", diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollFabric.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollFabric.java index 8cf994d1..db6b19de 100644 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollFabric.java +++ b/fabric/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollFabric.java @@ -3,6 +3,7 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; +import nl.enjarai.doabarrelroll.net.ServerNetworking; public class DoABarrelRollFabric implements ModInitializer { @Override @@ -10,9 +11,6 @@ public void onInitialize() { // Init server and client common code. DoABarrelRoll.init(); - ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> { - EventCallbacks.playerDisconnected(handler); - }); - ServerTickEvents.END_SERVER_TICK.register(EventCallbacks::serverTick); + ServerNetworking.init(); } } diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollFabricClient.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollFabricClient.java index c15caf73..e5260e12 100644 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollFabricClient.java +++ b/fabric/src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollFabricClient.java @@ -4,14 +4,16 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import nl.enjarai.doabarrelroll.net.ClientNetworking; public class DoABarrelRollFabricClient implements ClientModInitializer { @Override public void onInitializeClient() { DoABarrelRollClient.init(); + ClientNetworking.init(); + ClientTickEvents.END_CLIENT_TICK.register(EventCallbacksClient::clientTick); - ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> EventCallbacksClient.clientDisconnect()); // Register keybindings on fabric ModKeybindings.ALL.forEach(KeyBindingHelper::registerKeyBinding); diff --git a/common/src/main/java/nl/enjarai/doabarrelroll/mixin/CommandManagerMixin.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/mixin/fabric/CommandManagerMixin.java similarity index 82% rename from common/src/main/java/nl/enjarai/doabarrelroll/mixin/CommandManagerMixin.java rename to fabric/src/main/java/nl/enjarai/doabarrelroll/mixin/fabric/CommandManagerMixin.java index 7e015846..9580f747 100644 --- a/common/src/main/java/nl/enjarai/doabarrelroll/mixin/CommandManagerMixin.java +++ b/fabric/src/main/java/nl/enjarai/doabarrelroll/mixin/fabric/CommandManagerMixin.java @@ -1,8 +1,8 @@ -package nl.enjarai.doabarrelroll.mixin; +package nl.enjarai.doabarrelroll.mixin.fabric; import net.minecraft.server.command.CommandManager; import net.minecraft.server.network.ServerPlayerEntity; -import nl.enjarai.doabarrelroll.net.register.HandshakeServerRegister; +import nl.enjarai.doabarrelroll.net.ServerNetworking; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,6 +17,6 @@ public abstract class CommandManagerMixin { private void doABarrelRoll$doHandshake(ServerPlayerEntity player, CallbackInfo ci) { // We do the handshake here since, aside from on join, this method will most likely also trigger // in any situation where the player's permissions change - HandshakeServerRegister.sendHandshake(player); + ServerNetworking.sendHandshake(player); } } diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ClientNetworking.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ClientNetworking.java index 54eb9040..1a205ba6 100644 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ClientNetworking.java +++ b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ClientNetworking.java @@ -1,16 +1,25 @@ package nl.enjarai.doabarrelroll.net; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.client.MinecraftClient; +import net.minecraft.util.math.MathHelper; +import nl.enjarai.doabarrelroll.DoABarrelRoll; import nl.enjarai.doabarrelroll.DoABarrelRollClient; +import nl.enjarai.doabarrelroll.api.RollEntity; import nl.enjarai.doabarrelroll.api.event.ClientEvents; -import nl.enjarai.doabarrelroll.net.packet.ConfigResponseC2SPacketImpl; -import nl.enjarai.doabarrelroll.net.packet.ConfigSyncS2CPacketImpl; +import nl.enjarai.doabarrelroll.config.ModConfigServer; +import nl.enjarai.doabarrelroll.net.packet.*; +import nl.enjarai.doabarrelroll.platform.Services; public class ClientNetworking { - public static final HandshakeClient HANDSHAKE_CLIENT = new HandshakeClient( + public static final HandshakeClient HANDSHAKE_CLIENT = new HandshakeClient<>( ConfigResponseC2SPacketImpl::new, ClientEvents::updateServerConfig ); + public static final ServerConfigUpdateClient CONFIG_UPDATE_CLIENT = new ServerConfigUpdateClient<>( + ConfigUpdateC2SPacketImpl::new + ); public static void init() { ClientPlayNetworking.registerGlobalReceiver(ConfigSyncS2CPacketImpl.PACKET_ID, (payload, context) -> { @@ -18,9 +27,43 @@ public static void init() { context.responseSender().sendPacket(response); if (HANDSHAKE_CLIENT.hasConnected()) { - RollSyncClient.init(); - ServerConfigUpdateClientRegister.startListening(); + // Initialize roll sync + ClientPlayNetworking.registerReceiver(RollSyncS2CPacketImpl.PACKET_ID, (payload1, context1) -> { + var client = MinecraftClient.getInstance(); + if (client.world == null) { + return; + } + + var entity = client.world.getEntityById(payload1.entityId()); + if (entity == null) { + return; + } + var rollEntity = (RollEntity) entity; + + rollEntity.doABarrelRoll$setRolling(payload1.rolling()); + rollEntity.doABarrelRoll$setRoll(MathHelper.wrapDegrees(payload1.roll())); + }); + + // Initialize config update ack listener + ClientPlayNetworking.registerReceiver(ConfigUpdateAckS2CPacketImpl.PACKET_ID, (payload1, context1) -> { + CONFIG_UPDATE_CLIENT.updateAcknowledged(payload1); + }); } }); + + ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> HANDSHAKE_CLIENT.reset()); + } + + public static void sendRollUpdate(RollEntity entity) { + if (HANDSHAKE_CLIENT.hasConnected()) { + boolean rolling = entity.doABarrelRoll$isRolling(); + float roll = entity.doABarrelRoll$getRoll(); + + ClientPlayNetworking.send(new RollSyncC2SPacketImpl(rolling, roll)); + } + } + + public static void sendConfigUpdatePacket(ModConfigServer config) { + ClientPlayNetworking.send(CONFIG_UPDATE_CLIENT.prepUpdatePacket(config)); } } diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeClientRegister.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeClientRegister.java deleted file mode 100644 index f43213f5..00000000 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeClientRegister.java +++ /dev/null @@ -1,19 +0,0 @@ -package nl.enjarai.doabarrelroll.net; - -import nl.enjarai.doabarrelroll.DoABarrelRoll; -import nl.enjarai.doabarrelroll.DoABarrelRollClient; -import nl.enjarai.doabarrelroll.platform.Services; - -public class HandshakeClientRegister { - public static void init() { - Services.CLIENT_NET.registerListener(DoABarrelRoll.HANDSHAKE_CHANNEL, (buf, responseSender) -> { - var returnBuf = DoABarrelRollClient.HANDSHAKE_CLIENT.handleConfigSync(buf); - responseSender.accept(returnBuf); - - if (DoABarrelRollClient.HANDSHAKE_CLIENT.hasConnected()) { - RollSyncClient.init(); - ServerConfigUpdateClientRegister.startListening(); - } - }); - } -} diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeServerRegister.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeServerRegister.java deleted file mode 100644 index 006d0650..00000000 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/HandshakeServerRegister.java +++ /dev/null @@ -1,33 +0,0 @@ -package nl.enjarai.doabarrelroll.net; - -import net.minecraft.server.network.ServerPlayerEntity; -import nl.enjarai.doabarrelroll.DoABarrelRoll; -import nl.enjarai.doabarrelroll.api.event.ServerEvents; -import nl.enjarai.doabarrelroll.net.HandshakeServer; -import nl.enjarai.doabarrelroll.platform.Services; - -public class HandshakeServerRegister { - public static void init() { - Services.SERVER_NET.registerListener(DoABarrelRoll.HANDSHAKE_CHANNEL, (handler, buf, responseSender) -> { - var reply = DoABarrelRoll.HANDSHAKE_SERVER.clientReplied(handler, buf); - if (reply == HandshakeServer.HandshakeState.RESEND) { - // Resending can happen when the client has a different protocol version than expected. - sendHandshake(handler.getPlayer()); - } - }); - // The initial handshake is sent in the CommandManagerMixin. - - ServerEvents.SERVER_CONFIG_UPDATE.register((server, config) -> { - for (var player : server.getPlayerManager().getPlayerList()) { - sendHandshake(player); - } - }); - } - - public static void sendHandshake(ServerPlayerEntity player) { - Services.SERVER_NET.sendPacket(player.networkHandler, DoABarrelRoll.HANDSHAKE_CHANNEL, - DoABarrelRoll.HANDSHAKE_SERVER.getConfigSyncBuf(player.networkHandler)); - - DoABarrelRoll.HANDSHAKE_SERVER.configSentToClient(player.networkHandler); - } -} diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/RollSyncClient.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/RollSyncClient.java deleted file mode 100644 index 8d11a2b2..00000000 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/RollSyncClient.java +++ /dev/null @@ -1,45 +0,0 @@ -package nl.enjarai.doabarrelroll.net; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.util.math.MathHelper; -import nl.enjarai.doabarrelroll.DoABarrelRoll; -import nl.enjarai.doabarrelroll.DoABarrelRollClient; -import nl.enjarai.doabarrelroll.api.RollEntity; -import nl.enjarai.doabarrelroll.platform.Services; - -public class RollSyncClient { - public static void init() { - Services.CLIENT_NET.registerListener(DoABarrelRoll.ROLL_CHANNEL, (buf, responseSender) -> { - var client = MinecraftClient.getInstance(); - if (client.world == null) { - return; - } - - int entityId = buf.readInt(); - var isRolling = buf.readBoolean(); - var roll = buf.readFloat(); - - var entity = client.world.getEntityById(entityId); - if (entity == null) { - return; - } - var rollEntity = (RollEntity) entity; - - rollEntity.doABarrelRoll$setRolling(isRolling); - rollEntity.doABarrelRoll$setRoll(MathHelper.wrapDegrees(roll)); - }); - } - - public static void sendUpdate(RollEntity entity) { - if (DoABarrelRollClient.HANDSHAKE_CLIENT.hasConnected()) { - boolean rolling = entity.doABarrelRoll$isRolling(); - float roll = entity.doABarrelRoll$getRoll(); - - var buf = DoABarrelRoll.createBuf(); - buf.writeBoolean(rolling); - buf.writeFloat(roll); - - Services.CLIENT_NET.sendPacket(DoABarrelRoll.ROLL_CHANNEL, buf); - } - } -} diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/RollSyncServer.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/RollSyncServer.java deleted file mode 100644 index 9892fecd..00000000 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/RollSyncServer.java +++ /dev/null @@ -1,39 +0,0 @@ -package nl.enjarai.doabarrelroll.net; - -import net.minecraft.entity.Entity; -import net.minecraft.util.math.MathHelper; -import nl.enjarai.doabarrelroll.DoABarrelRoll; -import nl.enjarai.doabarrelroll.api.RollEntity; -import nl.enjarai.doabarrelroll.net.HandshakeServer; -import nl.enjarai.doabarrelroll.platform.Services; - -public class RollSyncServer { - public static void init() { - Services.SERVER_NET.registerListener(DoABarrelRoll.ROLL_CHANNEL, (handler, buf, responseSender) -> { - var rollPlayer = (RollEntity) handler.getPlayer(); - - var isRolling = buf.readBoolean(); - var roll = buf.readFloat(); - - rollPlayer.doABarrelRoll$setRolling(isRolling); - rollPlayer.doABarrelRoll$setRoll(isRolling ? MathHelper.wrapDegrees(roll) : 0); - }); - } - - public static void sendUpdates(Entity entity) { - var rollEntity = (RollEntity) entity; - var isRolling = rollEntity.doABarrelRoll$isRolling(); - var roll = rollEntity.doABarrelRoll$getRoll(); - - var buf = DoABarrelRoll.createBuf(); - buf.writeInt(entity.getId()); - buf.writeBoolean(isRolling); - buf.writeFloat(roll); - - Services.SERVER_NET.sendPacketsToTracking( - entity, - player -> DoABarrelRoll.HANDSHAKE_SERVER.getHandshakeState(player).state == HandshakeServer.HandshakeState.ACCEPTED, - DoABarrelRoll.ROLL_CHANNEL, buf - ); - } -} diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdateClientRegister.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdateClientRegister.java deleted file mode 100644 index 3a062cba..00000000 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdateClientRegister.java +++ /dev/null @@ -1,13 +0,0 @@ -package nl.enjarai.doabarrelroll.net; - -import nl.enjarai.doabarrelroll.DoABarrelRoll; -import nl.enjarai.doabarrelroll.net.ServerConfigUpdateClient; -import nl.enjarai.doabarrelroll.platform.Services; - -public class ServerConfigUpdateClientRegister { - public static void startListening() { - Services.CLIENT_NET.registerListener(DoABarrelRoll.SERVER_CONFIG_UPDATE_CHANNEL, (buf, responseSender) -> { - ServerConfigUpdateClient.updateAcknowledged(buf); - }); - } -} diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdaterRegister.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdaterRegister.java deleted file mode 100644 index dff0fa38..00000000 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerConfigUpdaterRegister.java +++ /dev/null @@ -1,12 +0,0 @@ -package nl.enjarai.doabarrelroll.net; - -import nl.enjarai.doabarrelroll.DoABarrelRoll; -import nl.enjarai.doabarrelroll.platform.Services; - -public class ServerConfigUpdaterRegister { - public static void init() { - Services.SERVER_NET.registerListener(DoABarrelRoll.SERVER_CONFIG_UPDATE_CHANNEL, (handler, buf, responseSender) -> { - responseSender.accept(DoABarrelRoll.CONFIG_HOLDER.clientSendsUpdate(handler.getPlayer(), buf)); - }); - } -} diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerNetworking.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerNetworking.java index e28504ea..01c9ed2f 100644 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerNetworking.java +++ b/fabric/src/main/java/nl/enjarai/doabarrelroll/net/ServerNetworking.java @@ -1,18 +1,27 @@ package nl.enjarai.doabarrelroll.net; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry; +import net.fabricmc.fabric.api.networking.v1.PlayerLookup; +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.entity.Entity; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.MathHelper; import nl.enjarai.doabarrelroll.DoABarrelRoll; +import nl.enjarai.doabarrelroll.api.RollEntity; import nl.enjarai.doabarrelroll.api.event.ServerEvents; import nl.enjarai.doabarrelroll.config.ModConfigServer; import nl.enjarai.doabarrelroll.net.packet.*; +import nl.enjarai.doabarrelroll.platform.Services; public class ServerNetworking { - public static final ServerConfigHolder CONFIG_HOLDER = new ServerConfigHolder( + public static final ServerConfigHolder CONFIG_HOLDER = new ServerConfigHolder<>( FabricLoader.getInstance().getConfigDir().resolve(DoABarrelRoll.MODID + "-server.json"), ModConfigServer.CODEC, ConfigUpdateAckS2CPacketImpl::new, ServerEvents::updateServerConfig ); - public static final HandshakeServer HANDSHAKE_SERVER = new HandshakeServer( + public static final HandshakeServer HANDSHAKE_SERVER = new HandshakeServer<>( ConfigSyncS2CPacketImpl::new, CONFIG_HOLDER, player -> !ModConfigServer.canModify(player)); public static void init() { @@ -25,5 +34,59 @@ public static void init() { PayloadTypeRegistry.playS2C().register(ConfigSyncS2CPacketImpl.PACKET_ID, ConfigSyncS2CPacketImpl.PACKET_CODEC); PayloadTypeRegistry.playS2C().register(ConfigUpdateAckS2CPacketImpl.PACKET_ID, ConfigUpdateAckS2CPacketImpl.PACKET_CODEC); PayloadTypeRegistry.playS2C().register(RollSyncS2CPacketImpl.PACKET_ID, RollSyncS2CPacketImpl.PACKET_CODEC); + + ServerPlayNetworking.registerGlobalReceiver(ConfigResponseC2SPacketImpl.PACKET_ID, (payload, context) -> { + var reply = HANDSHAKE_SERVER.clientReplied(context.player().networkHandler, payload); + if (reply == HandshakeServer.HandshakeState.RESEND) { + // Resending can happen when the client has a different protocol version than expected. + sendHandshake(context.player()); + } else if (reply == HandshakeServer.HandshakeState.ACCEPTED) { + // Init roll syncing + ServerPlayNetworking.registerReceiver(context.player().networkHandler, RollSyncC2SPacketImpl.PACKET_ID, (payload1, context1) -> { + var rollPlayer = (RollEntity) context1.player(); + + var isRolling = payload1.rolling(); + var roll = payload1.roll(); + + rollPlayer.doABarrelRoll$setRolling(isRolling); + rollPlayer.doABarrelRoll$setRoll(isRolling ? MathHelper.wrapDegrees(roll) : 0); + }); + + // Init client -> server config update + ServerPlayNetworking.registerReceiver(context.player().networkHandler, ConfigUpdateC2SPacketImpl.PACKET_ID, (payload1, context1) -> { + context1.responseSender().sendPacket(CONFIG_HOLDER.clientSendsUpdate(context1.player(), payload1)); + }); + } + }); + // The initial handshake is sent in the CommandManagerMixin. + + ServerEvents.SERVER_CONFIG_UPDATE.register((server, config) -> { + for (var player : server.getPlayerManager().getPlayerList()) { + sendHandshake(player); + } + }); + + ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> { + HANDSHAKE_SERVER.playerDisconnected(handler); + }); + ServerTickEvents.END_SERVER_TICK.register(HANDSHAKE_SERVER::tick); + } + + public static void sendHandshake(ServerPlayerEntity player) { + ServerPlayNetworking.send(player, HANDSHAKE_SERVER.initiateConfigSync(player.networkHandler)); + HANDSHAKE_SERVER.configSentToClient(player.networkHandler); + } + + public static void sendRollUpdates(Entity entity) { + var rollEntity = (RollEntity) entity; + var isRolling = rollEntity.doABarrelRoll$isRolling(); + var roll = rollEntity.doABarrelRoll$getRoll(); + + var payload = new RollSyncS2CPacketImpl(entity.getId(), isRolling, roll); + + PlayerLookup.tracking(entity).stream() + .filter(player -> player != entity) + .filter(player -> HANDSHAKE_SERVER.getHandshakeState(player).state == HandshakeServer.HandshakeState.ACCEPTED) + .forEach(player -> ServerPlayNetworking.send(player, payload)); } } diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/platform/FabricClientNetworkUtils.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/platform/FabricClientNetworkUtils.java index 418c30f7..55cb4a25 100644 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/platform/FabricClientNetworkUtils.java +++ b/fabric/src/main/java/nl/enjarai/doabarrelroll/platform/FabricClientNetworkUtils.java @@ -1,20 +1,24 @@ package nl.enjarai.doabarrelroll.platform; -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.util.Identifier; +import nl.enjarai.doabarrelroll.api.RollEntity; +import nl.enjarai.doabarrelroll.config.ModConfigServer; +import nl.enjarai.doabarrelroll.net.ClientNetworking; +import nl.enjarai.doabarrelroll.net.HandshakeClient; import nl.enjarai.doabarrelroll.platform.services.ClientNetworkUtils; public class FabricClientNetworkUtils implements ClientNetworkUtils { @Override - public void sendPacket(Identifier channel, PacketByteBuf buf) { - ClientPlayNetworking.send(channel, buf); + public void sendRollUpdate(RollEntity entity) { + ClientNetworking.sendRollUpdate(entity); } @Override - public void registerListener(Identifier channel, PacketListener listener) { - ClientPlayNetworking.registerGlobalReceiver(channel, (client, handler, buf, responseSender) -> { - listener.accept(buf, replyBuf -> responseSender.sendPacket(channel, replyBuf)); - }); + public void sendConfigUpdatePacket(ModConfigServer config) { + ClientNetworking.sendConfigUpdatePacket(config); + } + + @Override + public HandshakeClient getHandshakeClient() { + return ClientNetworking.HANDSHAKE_CLIENT; } } diff --git a/fabric/src/main/java/nl/enjarai/doabarrelroll/platform/FabricServerNetworkUtils.java b/fabric/src/main/java/nl/enjarai/doabarrelroll/platform/FabricServerNetworkUtils.java index 0268b4e2..407d3b3c 100644 --- a/fabric/src/main/java/nl/enjarai/doabarrelroll/platform/FabricServerNetworkUtils.java +++ b/fabric/src/main/java/nl/enjarai/doabarrelroll/platform/FabricServerNetworkUtils.java @@ -1,35 +1,18 @@ package nl.enjarai.doabarrelroll.platform; -import net.fabricmc.fabric.api.networking.v1.PlayerLookup; -import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.minecraft.entity.Entity; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.server.network.ServerPlayNetworkHandler; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.Identifier; -import nl.enjarai.doabarrelroll.DoABarrelRoll; +import nl.enjarai.doabarrelroll.net.ServerConfigHolder; +import nl.enjarai.doabarrelroll.net.ServerNetworking; import nl.enjarai.doabarrelroll.platform.services.ServerNetworkUtils; -import java.util.function.Predicate; - public class FabricServerNetworkUtils implements ServerNetworkUtils { @Override - public void sendPacket(ServerPlayNetworkHandler handler, Identifier channel, PacketByteBuf buf) { - ServerPlayNetworking.send(handler.getPlayer(), channel, buf); - } - - @Override - public void sendPacketsToTracking(Entity entity, Predicate predicate, Identifier channel, PacketByteBuf buf) { - PlayerLookup.tracking(entity).stream() - .filter(player -> player != entity) - .filter(predicate) - .forEach(player -> ServerPlayNetworking.send(player, DoABarrelRoll.ROLL_CHANNEL, buf)); + public void sendRollUpdates(Entity entity) { + ServerNetworking.sendRollUpdates(entity); } @Override - public void registerListener(Identifier channel, PacketListener listener) { - ServerPlayNetworking.registerGlobalReceiver(channel, (server, player, handler, buf, responseSender) -> { - listener.accept(handler, buf, replyBuf -> responseSender.sendPacket(channel, replyBuf)); - }); + public ServerConfigHolder getServerConfigHolder() { + return ServerNetworking.CONFIG_HOLDER; } } diff --git a/fabric/src/main/resources/do_a_barrel_roll.fabric.mixins.json b/fabric/src/main/resources/do_a_barrel_roll.fabric.mixins.json index f6527df4..9bfd4177 100644 --- a/fabric/src/main/resources/do_a_barrel_roll.fabric.mixins.json +++ b/fabric/src/main/resources/do_a_barrel_roll.fabric.mixins.json @@ -1,10 +1,11 @@ { "required": true, "minVersion": "0.8", - "package": "nl.enjarai.doabarrelroll.mixin", + "package": "nl.enjarai.doabarrelroll.mixin.fabric", "refmap": "${mod_id}.refmap.json", "compatibilityLevel": "JAVA_17", "mixins": [ + "CommandManagerMixin" ], "client": [ ],