Search in sources :

Example 1 with ServerLevelAccessor

use of org.spongepowered.common.accessor.server.level.ServerLevelAccessor in project SpongeCommon by SpongePowered.

the class SpawnEntityTransaction method restore.

@Override
public void restore(final PhaseContext<@NonNull ?> context, final SpawnEntityEvent event) {
    final ServerLevel serverWorld = this.worldSupplier.get();
    if (((ServerLevelAccessor) serverWorld).accessor$tickingEntities()) {
        // More than likely we could also be needing to remove the entity from both the entities to add
        // and the chunk.
        ((ServerLevelAccessor) serverWorld).accessor$toAddAfterTick().remove(this.entityToSpawn);
        ((ServerLevelAccessor) serverWorld).invoker$removeFromChunk(this.entityToSpawn);
    } else {
        serverWorld.despawn(this.entityToSpawn);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerLevelAccessor(org.spongepowered.common.accessor.server.level.ServerLevelAccessor)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)1 ServerLevelAccessor (org.spongepowered.common.accessor.server.level.ServerLevelAccessor)1