use of net.minecraft.core.BlockSourceImpl in project SpongeCommon by SpongePowered.
the class DispenserSourceLogic method launch.
@SuppressWarnings("unchecked")
private <P extends Projectile> Optional<P> launch(final DispenserBlockEntity dispenser, final EntityType<P> projectileType, final Item item) {
final DispenseItemBehavior behavior = DispenserBlockAccessor.accessor$DISPENSER_REGISTRY().get(item);
final ServerLevel world = (ServerLevel) dispenser.getLevel();
behavior.dispense(new BlockSourceImpl(world, dispenser.getBlockPos()), new ItemStack(item));
final List<Entity> entities = world.getEntities((net.minecraft.world.entity.EntityType<?>) projectileType, entity -> true);
if (entities.isEmpty()) {
return Optional.empty();
}
// Hack - get the projectile that was spawned from dispense()
return Optional.of((P) entities.get(entities.size() - 1));
}
Aggregations