Efektler

Uyarı

These docs were written for SpongeAPI 7 and are likely out of date. If you feel like you can help update them, please submit a PR!

Sponge’daki efekt API’sini kullanarak, bir sunucuda kullanılacak özel efektler oluşturabilirsiniz. Bir: javadoc: `izleyici ‘kullanarak, sunucudaki sesleri çalar veya parçacık üretebiliriz.

Çalınan sesler

Verilen herhangi bir “Görüntüleyici” ile, sadece bir yerde bir ses çalabiliriz:

import org.spongepowered.api.effect.Viewer;
import org.spongepowered.api.effect.sound.SoundTypes;

import com.flowpowered.math.vector.Vector3d;

viewer.playSound(SoundTypes.ENTITY_CREEPER_PRIMED, new Vector3d(1, 65, 1), 1);

Now let’s break this down. First, the SoundType specifies the sound that will be played. Next, we have a Vector3d position. This position can be constructed, or it can be retrieved from a Location using the Location#getPosition() method. In the example above, the sound will be played at the coordinates 1, 65, 1. Lastly, we have the volume that the sound will be played at. The volume is a double that ranges from zero to two.

Şimdi temel sesleri çalabiliyoruz, daha derinlemesine seslerimizle gidebiliriz.Diyelim ki, sesi belirli bir aralıkla çalmak istedik.Sahayı belirli bir nota modüle etmek için sınıf SoundCategory kullanacağız.

import org.spongepowered.api.effect.sound.PitchModulation;
import org.spongepowered.api.effect.sound.SoundCategories;

viewer.playSound(SoundTypes.ENTITY_CREEPER_PRIMED, SoundCategories.HOSTILE,
    new Vector3d(1, 65, 1), 1, PitchModulation.AFLAT0);

Bir ses çalınırken `` SoundCategory`` belirtilmemişse, SoundCategories#MASTER kullanılacak.

Yumurtlayan parçacıklar

Benzer şekilde, sesler arasında, dünyadaki parçacıkları yumurtlamak için “Görüntüleyici” sınıfını kullanabiliriz:

import org.spongepowered.api.effect.particle.ParticleEffect;
import org.spongepowered.api.effect.particle.ParticleTypes;

ParticleEffect effect = ParticleEffect.builder()
        .type(ParticleTypes.LAVA)
        .quantity(50)
        .build();
viewer.spawnParticles(effect, position);

:javadoc:`ParticleEffect.Builder`kullanın,biz yumurtlamak istediğiniz parçacığın türünü belirtebiliriz.Bununla birlikte, elli partikülün parçacık efektinde olacağını da belirttik.

Now if we wanted to make a more specific particle, say the particle of a block, then we can use one of the several types found in the ParticleTypes class. For example, let’s say we wanted to spawn particles of a cracking block of sand, ParticleTypes#BLOCK_CRACK. We would need to use the ParticleOptions#BLOCK_STATE option and specify that we would like to use a sand block. This can be done like so:

import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.effect.particle.ParticleOptions;

ParticleEffect particle = ParticleEffect.builder()
        .type(ParticleTypes.BLOCK_CRACK)
        .option(ParticleOptions.BLOCK_STATE, BlockTypes.SAND.getDefaultState())
        .build();
viewer.spawnParticles(particle, position);

Potion Effects

Parçacıklara ve seslere benzer şekilde, iksir etkisi yaratmak için bir yapıcı kullanmamız gerekir:

import org.spongepowered.api.effect.potion.PotionEffect;
import org.spongepowered.api.effect.potion.PotionEffectTypes;

PotionEffect potion = PotionEffect.builder()
        .potionType(PotionEffectTypes.HASTE)
        .duration(10)
        .amplifier(5)
        .build();

Bunu kullanarak on işaretleme kadar sürecek ve beş kat güçlendiriciye sahip olacak PotionEffect ivmesi oluşturabiliriz.Partiküller ve seslerin aksine iksirler ``Viewer``a uygulanamaz. Bunun yerine bir oyuncu gibi :javadoc:`PotionEffectData`kodunu destekleyen bir varlığa ihtiyacımız vardır.

import org.spongepowered.api.data.manipulator.mutable.PotionEffectData;
import org.spongepowered.api.entity.living.player.Player;

PotionEffectData effects = player.getOrCreate(PotionEffectData.class).get();
effects.addElement(potion);
player.offer(effects);

Bu, bir oyuncudan bir “PotionEffectData” alacak veya yaratacak.