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

28 lines
1 KiB
Java
Raw Normal View History

package de.ellpeck.actuallyadditions.mod.util;
2024-03-02 21:23:08 +01:00
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk;
public final class VanillaPacketDispatcher {
2019-02-27 19:53:05 +01:00
//Don't call from the client.
2024-03-02 21:23:08 +01:00
public static void dispatchTEToNearbyPlayers(BlockEntity blockEntity) {
ServerLevel serverLevel = (ServerLevel) blockEntity.getLevel();
LevelChunk chunk = serverLevel.getChunk(blockEntity.getBlockPos().getX() >> 4, blockEntity.getBlockPos().getZ() >> 4);
2024-03-02 21:23:08 +01:00
serverLevel.getChunkSource().chunkMap.getPlayers(chunk.getPos(), false).forEach(e -> {
e.connection.send(blockEntity.getUpdatePacket());
});
2019-02-27 19:53:05 +01:00
}
2024-03-02 21:23:08 +01:00
public static void dispatchTEToNearbyPlayers(Level level, BlockPos pos) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity != null) {
dispatchTEToNearbyPlayers(blockEntity);
2021-02-26 22:15:48 +01:00
}
2019-02-27 19:53:05 +01:00
}
}