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

27 lines
982 B
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.common.util;
2020-10-31 22:31:04 +01:00
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2020-10-31 22:31:04 +01:00
import net.minecraft.world.server.ServerWorld;
public final class VanillaPacketDispatcher {
2019-02-27 19:53:05 +01:00
//Don't call from the client.
public static void dispatchTEToNearbyPlayers(TileEntity tile) {
2020-10-31 22:31:04 +01:00
ServerWorld world = (ServerWorld) tile.getWorld();
2019-02-27 19:53:05 +01:00
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;
2020-10-31 22:31:04 +01:00
for (ServerPlayerEntity player : entry.getWatchingPlayers())
2019-02-27 19:53:05 +01:00
player.connection.sendPacket(tile.getUpdatePacket());
}
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);
}
}