use of net.minecraft.network.protocol.game.ClientboundAddPaintingPacket in project SpongeCommon by SpongePowered.
the class PaintingData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(Painting.class).create(Keys.ART_TYPE).get(h -> (ArtType) h.motive).setAnd((h, v) -> {
if (!h.level.isClientSide) {
final Motive oldArt = h.motive;
h.motive = (Motive) v;
((HangingEntityAccessor) h).invoker$setDirection(h.getDirection());
if (!h.survives()) {
h.motive = oldArt;
((HangingEntityAccessor) h).invoker$setDirection(h.getDirection());
return false;
}
final ChunkMapAccessor chunkManager = (ChunkMapAccessor) ((ServerLevel) h.level).getChunkSource().chunkMap;
final ChunkMap_TrackedEntityAccessor paintingTracker = chunkManager.accessor$entityMap().get(h.getId());
if (paintingTracker == null) {
return true;
}
final List<ServerPlayer> players = new ArrayList<>();
for (final ServerPlayer player : paintingTracker.accessor$seenBy()) {
final ClientboundRemoveEntitiesPacket packet = new ClientboundRemoveEntitiesPacket(h.getId());
player.connection.send(packet);
players.add(player);
}
for (final ServerPlayer player : players) {
SpongeCommon.serverScheduler().submit(Task.builder().plugin(Launch.instance().commonPlugin()).delay(new SpongeTicks(SpongeGameConfigs.getForWorld(h.level).get().entity.painting.respawnDelay)).execute(() -> {
final ClientboundAddPaintingPacket packet = new ClientboundAddPaintingPacket(h);
player.connection.send(packet);
}).build());
}
return true;
}
return true;
});
}
Aggregations