ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/common/util/VanillaPacketDispatcher.java
Michael Hillcox 3e61998ca8
Utils porting
2020-10-31 21:31:04 +00:00

27 lines
982 B
Java

package de.ellpeck.actuallyadditions.common.util;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
public final class VanillaPacketDispatcher {
//Don't call from the client.
public static void dispatchTEToNearbyPlayers(TileEntity tile) {
ServerWorld world = (ServerWorld) tile.getWorld();
PlayerChunkMapEntry entry = world.getPlayerChunkMap().getEntry(tile.getPos().getX() >> 4, tile.getPos().getZ() >> 4);
if (entry == null) return;
for (ServerPlayerEntity player : entry.getWatchingPlayers())
player.connection.sendPacket(tile.getUpdatePacket());
}
public static void dispatchTEToNearbyPlayers(World world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (tile != null) dispatchTEToNearbyPlayers(tile);
}
}