2018-09-27 21:17:23 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.util;
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
2018-09-27 21:17:23 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2021-03-01 17:25:30 +01:00
|
|
|
import net.minecraft.world.server.ServerWorld;
|
2018-09-27 21:17:23 +02:00
|
|
|
|
|
|
|
public final class VanillaPacketDispatcher {
|
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
//Don't call from the client.
|
|
|
|
public static void dispatchTEToNearbyPlayers(TileEntity tile) {
|
2021-03-01 17:25:30 +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);
|
2018-09-27 21:17:23 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
if (entry == null) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-27 21:17:23 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
for (ServerPlayerEntity player : entry.getWatchingPlayers()) {
|
2019-02-27 19:53:05 +01:00
|
|
|
player.connection.sendPacket(tile.getUpdatePacket());
|
2021-02-26 22:15:48 +01:00
|
|
|
}
|
2018-09-27 21:17:23 +02:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
}
|
2018-09-27 21:17:23 +02:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
public static void dispatchTEToNearbyPlayers(World world, BlockPos pos) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
2021-02-26 22:15:48 +01:00
|
|
|
if (tile != null) {
|
|
|
|
dispatchTEToNearbyPlayers(tile);
|
|
|
|
}
|
2019-02-27 19:53:05 +01:00
|
|
|
}
|
2018-09-27 21:17:23 +02:00
|
|
|
}
|