Search in sources :

Example 1 with SpawnType

use of org.spongepowered.api.event.cause.entity.SpawnType in project SpongeCommon by SpongePowered.

the class TransactionSink method logEntitySpawn.

@SuppressWarnings("ConstantConditions")
default void logEntitySpawn(final PhaseContext<@NonNull ?> current, final TrackedWorldBridge serverWorld, final Entity entityIn) {
    final WeakReference<ServerLevel> worldRef = new WeakReference<>((ServerLevel) serverWorld);
    final Supplier<ServerLevel> worldSupplier = () -> Objects.requireNonNull(worldRef.get(), "ServerWorld dereferenced");
    final Supplier<SpawnType> contextualType = current.getSpawnTypeForTransaction(entityIn);
    final SpawnEntityTransaction transaction = new SpawnEntityTransaction(worldSupplier, entityIn, contextualType);
    this.logTransaction(transaction);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) SpawnType(org.spongepowered.api.event.cause.entity.SpawnType) SpawnEntityTransaction(org.spongepowered.common.event.tracking.context.transaction.world.SpawnEntityTransaction) WeakReference(java.lang.ref.WeakReference)

Aggregations

WeakReference (java.lang.ref.WeakReference)1 ServerLevel (net.minecraft.server.level.ServerLevel)1 SpawnType (org.spongepowered.api.event.cause.entity.SpawnType)1 SpawnEntityTransaction (org.spongepowered.common.event.tracking.context.transaction.world.SpawnEntityTransaction)1