Skip to content

Commit

Permalink
Tidy up updating worldspawn
Browse files Browse the repository at this point in the history
  • Loading branch information
irtimaled committed Aug 9, 2019
1 parent 3ac7773 commit 146372e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}

0 comments on commit 146372e

Please sign in to comment.