From 146372e9a3d92eae9b96a122ecae52e4bdabce8e Mon Sep 17 00:00:00 2001 From: Irtimaled Date: Fri, 9 Aug 2019 00:04:11 -0700 Subject: [PATCH] Tidy up updating worldspawn --- .../bbor/client/interop/ClientInterop.java | 6 +++ .../server/MixinSPacketCustomPayload.java | 49 ++++++++++--------- .../server/MixinSPacketSpawnPosition.java | 5 +- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/irtimaled/bbor/client/interop/ClientInterop.java b/src/main/java/com/irtimaled/bbor/client/interop/ClientInterop.java index 59c569a2..5fc0f973 100644 --- a/src/main/java/com/irtimaled/bbor/client/interop/ClientInterop.java +++ b/src/main/java/com/irtimaled/bbor/client/interop/ClientInterop.java @@ -4,8 +4,10 @@ import com.irtimaled.bbor.client.events.DisconnectedFromRemoteServer; import com.irtimaled.bbor.client.events.Render; import com.irtimaled.bbor.client.events.SeedCommandTyped; +import com.irtimaled.bbor.client.events.UpdateWorldSpawnReceived; import com.irtimaled.bbor.common.EventBus; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.util.math.BlockPos; public class ClientInterop { public static void disconnectedFromRemoteServer() { @@ -39,4 +41,8 @@ private static Long parseNumericSeed(String argument) { return null; } } + + public static void updateWorldSpawnReceived(BlockPos blockPos) { + EventBus.publish(new UpdateWorldSpawnReceived(blockPos.getX(), blockPos.getZ())); + } } diff --git a/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketCustomPayload.java b/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketCustomPayload.java index adb72e7a..a0ab1d64 100644 --- a/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketCustomPayload.java +++ b/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketCustomPayload.java @@ -19,32 +19,33 @@ public abstract class MixinSPacketCustomPayload { @Redirect(method = "processPacket", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/INetHandlerPlayClient;handleCustomPayload(Lnet/minecraft/network/play/server/SPacketCustomPayload;)V")) private void processPacket(INetHandlerPlayClient netHandlerPlayClient, SPacketCustomPayload packet) { - PacketBuffer data = null; - try { - data = packet.getBufferData(); - PayloadReader reader = new PayloadReader(data); - switch (channel.toString()) { - case InitializeClient.NAME: { - EventBus.publish(InitializeClient.getEvent(reader)); - ((NetHandlerPlayClient) netHandlerPlayClient).sendPacket(SubscribeToServer.getPayload().build()); - break; - } - case AddBoundingBox.NAME: { - EventBus.publish(AddBoundingBox.getEvent(reader)); - break; - } - case RemoveBoundingBox.NAME: { - EventBus.publish(RemoveBoundingBox.getEvent(reader)); - break; - } - default: { - netHandlerPlayClient.handleCustomPayload(packet); - break; + String channelName = channel.toString(); + if (channelName.startsWith("bbor:")) { + PacketBuffer data = null; + try { + data = packet.getBufferData(); + PayloadReader reader = new PayloadReader(data); + switch (channelName) { + case InitializeClient.NAME: { + EventBus.publish(InitializeClient.getEvent(reader)); + ((NetHandlerPlayClient) netHandlerPlayClient).sendPacket(SubscribeToServer.getPayload().build()); + break; + } + case AddBoundingBox.NAME: { + EventBus.publish(AddBoundingBox.getEvent(reader)); + break; + } + case RemoveBoundingBox.NAME: { + EventBus.publish(RemoveBoundingBox.getEvent(reader)); + break; + } } + } finally { + if (data != null) + data.release(); } - } finally { - if (data != null) - data.release(); + } else { + netHandlerPlayClient.handleCustomPayload(packet); } } } diff --git a/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketSpawnPosition.java b/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketSpawnPosition.java index d0b6e868..6fcabe12 100644 --- a/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketSpawnPosition.java +++ b/src/main/java/com/irtimaled/bbor/mixin/network/play/server/MixinSPacketSpawnPosition.java @@ -1,7 +1,6 @@ package com.irtimaled.bbor.mixin.network.play.server; -import com.irtimaled.bbor.client.events.UpdateWorldSpawnReceived; -import com.irtimaled.bbor.common.EventBus; +import com.irtimaled.bbor.client.interop.ClientInterop; import net.minecraft.network.play.server.SPacketSpawnPosition; import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Mixin; @@ -17,6 +16,6 @@ public abstract class MixinSPacketSpawnPosition { @Inject(method = "processPacket", at = @At("RETURN")) private void afterProcessPacket(CallbackInfo ci) { - EventBus.publish(new UpdateWorldSpawnReceived(spawnBlockPos.getX(), spawnBlockPos.getZ())); + ClientInterop.updateWorldSpawnReceived(spawnBlockPos); } }