Commit 485c80e8 by Jonathan Thomas

Support all 3 worlds when broadcasting messages to players for an entityId

parent d3eed475
Pipeline #11655 passed with stage
in 20 seconds
package com.owlmaddie; package com.owlmaddie;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance; import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects; import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import io.netty.buffer.Unpooled; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -89,8 +90,8 @@ public class ModInit implements ModInitializer { ...@@ -89,8 +90,8 @@ public class ModInit implements ModInitializer {
// Send new message to all connected players // Send new message to all connected players
public static void BroadcastPacketMessage(ChatDataManager.EntityChatData chatData) { public static void BroadcastPacketMessage(ChatDataManager.EntityChatData chatData) {
// TODO: Fix static OVERWORLD reference for (ServerWorld world : serverInstance.getWorlds()) {
Entity entity = serverInstance.getOverworld().getEntityById(chatData.entityId); Entity entity = world.getEntityById(chatData.entityId);
if (entity != null) { if (entity != null) {
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
...@@ -105,6 +106,8 @@ public class ModInit implements ModInitializer { ...@@ -105,6 +106,8 @@ public class ModInit implements ModInitializer {
LOGGER.info("Server send message packet to player: " + player.getName().getString()); LOGGER.info("Server send message packet to player: " + player.getName().getString());
ServerPlayNetworking.send(player, PACKET_S2C_MESSAGE, buffer); ServerPlayNetworking.send(player, PACKET_S2C_MESSAGE, buffer);
} }
break;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment