use of org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor in project SpongeCommon by SpongePowered.
the class EntityMixin method impl$updateVanishState.
@SuppressWarnings({ "ConstantConditions", "RedundantCast" })
@Inject(method = "tick", at = @At("RETURN"))
private void impl$updateVanishState(final CallbackInfo callbackInfo) {
if (this.impl$pendingVisibilityUpdate && !this.level.isClientSide) {
final ChunkMap_TrackedEntityAccessor trackerAccessor = ((ChunkMapAccessor) ((ServerWorld) this.level).chunkManager()).accessor$entityMap().get(this.shadow$getId());
if (trackerAccessor != null && this.impl$visibilityTicks % 4 == 0) {
if (this.bridge$vanishState().invisible()) {
for (final ServerPlayer entityPlayerMP : trackerAccessor.accessor$seenBy()) {
entityPlayerMP.connection.send(new ClientboundRemoveEntitiesPacket(this.shadow$getId()));
if ((Entity) (Object) this instanceof ServerPlayer) {
entityPlayerMP.connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, (ServerPlayer) (Object) this));
}
}
} else {
this.impl$visibilityTicks = 1;
this.impl$pendingVisibilityUpdate = false;
for (final ServerPlayer entityPlayerMP : SpongeCommon.server().getPlayerList().getPlayers()) {
if ((Entity) (Object) this == entityPlayerMP) {
continue;
}
if ((Entity) (Object) this instanceof ServerPlayer) {
final Packet<?> packet = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, (ServerPlayer) (Object) this);
entityPlayerMP.connection.send(packet);
}
trackerAccessor.accessor$updatePlayer(entityPlayerMP);
}
}
}
if (this.impl$visibilityTicks > 0) {
this.impl$visibilityTicks--;
} else {
this.impl$pendingVisibilityUpdate = false;
}
}
}
use of org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor 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