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;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffectInstance;
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.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.LoggerFactory;
......@@ -89,8 +90,8 @@ public class ModInit implements ModInitializer {
// Send new message to all connected players
public static void BroadcastPacketMessage(ChatDataManager.EntityChatData chatData) {
// TODO: Fix static OVERWORLD reference
Entity entity = serverInstance.getOverworld().getEntityById(chatData.entityId);
for (ServerWorld world : serverInstance.getWorlds()) {
Entity entity = world.getEntityById(chatData.entityId);
if (entity != null) {
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
......@@ -105,6 +106,8 @@ public class ModInit implements ModInitializer {
LOGGER.info("Server send message packet to player: " + player.getName().getString());
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