ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/util/VanillaPacketDispatcher.java

29 lines
1 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.mod.util;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.management.PlayerChunkMapEntry;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
public final class VanillaPacketDispatcher {
2019-02-27 19:53:05 +01:00
//Don't call from the client.
public static void dispatchTEToNearbyPlayers(TileEntity tile) {
WorldServer world = (WorldServer) tile.getWorld();
PlayerChunkMapEntry entry = world.getPlayerChunkMap().getEntry(tile.getPos().getX() >> 4, tile.getPos().getZ() >> 4);
2019-02-27 19:53:05 +01:00
if (entry == null) return;
2019-02-27 19:53:05 +01:00
for (EntityPlayerMP player : entry.getWatchingPlayers())
player.connection.sendPacket(tile.getUpdatePacket());
2019-02-27 19:53:05 +01:00
}
2019-02-27 19:53:05 +01:00
public static void dispatchTEToNearbyPlayers(World world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (tile != null) dispatchTEToNearbyPlayers(tile);
}
}