2018-09-27 21:17:23 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.util;
|
|
|
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2021-11-13 19:30:58 +01:00
|
|
|
import net.minecraft.world.chunk.Chunk;
|
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-08-22 17:09:06 +02:00
|
|
|
ServerWorld world = (ServerWorld) tile.getLevel();
|
2021-11-13 19:30:58 +01:00
|
|
|
Chunk chunk = world.getChunk(tile.getBlockPos().getX() >> 4, tile.getBlockPos().getZ() >> 4);
|
2018-09-27 21:17:23 +02:00
|
|
|
|
2021-11-13 19:30:58 +01:00
|
|
|
world.getChunkSource().chunkMap.getPlayers(chunk.getPos(), false).forEach(e -> {
|
|
|
|
e.connection.send(tile.getUpdatePacket());
|
|
|
|
});
|
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) {
|
2021-08-22 17:09:06 +02:00
|
|
|
TileEntity tile = world.getBlockEntity(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
|
|
|
}
|