本文整理汇总了Java中org.spongepowered.api.effect.potion.PotionEffect类的典型用法代码示例。如果您正苦于以下问题:Java PotionEffect类的具体用法?Java PotionEffect怎么用?Java PotionEffect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PotionEffect类属于org.spongepowered.api.effect.potion包,在下文中一共展示了PotionEffect类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removePotion
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
public boolean removePotion(PotionEffect effect){
if (this.user.get(Keys.POTION_EFFECTS).isPresent()){
List<PotionEffect> effects = this.user.get(Keys.POTION_EFFECTS).get();
boolean check = false;
int cpt = 0;
while(effects.size() > cpt && check == false){
if (effects.get(cpt).equals(effect)){
effects.remove(cpt);
check = true;
}
cpt++;
}
this.user.offer(Keys.POTION_EFFECTS, effects);
return true;
} else {
return false;
}
}
示例2: registerDefaults
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void registerDefaults() {
register(new LanternFish("minecraft", "cod", "item.fish.cod.raw.name", 0,
builder -> builder
.add(foodRestoration(2))
.add(saturation(0.4))));
register(new LanternFish("minecraft", "salmon", "item.fish.salmon.raw.name", 1,
builder -> builder
.add(foodRestoration(2))
.add(saturation(0.4))));
register(new LanternFish("minecraft", "clownfish", "item.fish.clownfish.raw.name", 2,
builder -> builder
.add(foodRestoration(1))
.add(saturation(0.2))));
register(new LanternFish("minecraft", "pufferfish", "item.fish.pufferfish.raw.name", 3,
builder -> builder
.add(foodRestoration(1))
.add(saturation(0.2))
.add(applicableEffects(
PotionEffect.of(PotionEffectTypes.POISON, 3, 1200),
PotionEffect.of(PotionEffectTypes.HUNGER, 2, 300),
PotionEffect.of(PotionEffectTypes.NAUSEA, 1, 300)))));
}
示例3: get
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public Collection<PotionEffect> get(ItemType itemType, @Nullable ItemStack itemStack) {
if (itemStack == null) {
return Collections.emptyList();
}
final PotionType potionType = itemStack.get(LanternKeys.POTION_TYPE).orElse(null);
List<PotionEffect> potionEffects = null;
if (potionType != null) {
potionEffects = potionType.getEffects();
}
final List<PotionEffect> extraPotionEffects = itemStack.get(Keys.POTION_EFFECTS).orElse(null);
if (extraPotionEffects != null) {
if (potionEffects != null) {
potionEffects = PotionEffectHelper.merge(potionEffects, extraPotionEffects);
} else {
potionEffects = extraPotionEffects;
}
}
return potionEffects == null ? ImmutableSet.of() : ImmutableSet.copyOf(potionEffects);
}
示例4: serialize
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
public static DataView serialize(PotionEffect potionEffect) {
final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
dataView.set(AMPLIFIER, (byte) potionEffect.getAmplifier());
dataView.set(DURATION, potionEffect.getDuration());
dataView.set(AMBIENT, (byte) (potionEffect.isAmbient() ? 1 : 0));
if (potionEffect.getShowParticles()) {
dataView.set(SHOW_PARTICLES, (byte) 1);
}
final LanternPotionEffectType potionEffectType = (LanternPotionEffectType) potionEffect.getType();
final int internalId = potionEffectType.getInternalId();
if (internalId > 0xff) {
dataView.set(IDENTIFIER, internalId);
} else {
dataView.set(IDENTIFIER, (byte) internalId);
}
return dataView;
}
示例5: buildContent
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
protected Optional<PotionEffect> buildContent(DataView container) throws InvalidDataException {
checkNotNull(container);
if (!container.contains(DataQueries.POTION_TYPE) || !container.contains(DataQueries.POTION_DURATION)
|| !container.contains(DataQueries.POTION_AMPLIFIER) || !container.contains(DataQueries.POTION_AMBIANCE)
|| !container.contains(DataQueries.POTION_SHOWS_PARTICLES)) {
return Optional.empty();
}
String effectName = container.getString(DataQueries.POTION_TYPE).get();
Optional<PotionEffectType> optional = Sponge.getRegistry().getType(PotionEffectType.class, effectName);
if (!optional.isPresent()) {
throw new InvalidDataException("The container has an invalid potion type name: " + effectName);
}
int duration = container.getInt(DataQueries.POTION_DURATION).get();
int amplifier = container.getInt(DataQueries.POTION_AMPLIFIER).get();
boolean ambient = container.getBoolean(DataQueries.POTION_AMBIANCE).get();
boolean showParticles = container.getBoolean(DataQueries.POTION_SHOWS_PARTICLES).get();
return Optional.of(new LanternPotionEffect(optional.get(), duration, amplifier, ambient, showParticles));
}
示例6: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run() {
PotionEffect speedEffect = PotionEffect.builder()
.duration(3 * 20)
.amplifier(5)
.particles(false)
.potionType(PotionEffectTypes.SPEED)
.build();
for (World world : getWorlds()) {
for (Entity entity : world.getEntities(p -> p.getType().equals(EntityTypes.PLAYER))) {
if (entity.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) != GameModes.SURVIVAL) {
continue;
}
List<PotionEffect> potionEffects = entity.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
potionEffects.add(speedEffect);
entity.offer(Keys.POTION_EFFECTS, potionEffects);
}
}
}
示例7: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
int duration = (int) (EntityHealthUtil.getHealth(owner) * 20);
Optional<PotionEffectData> optPotionEffectData = target.getOrCreate(PotionEffectData.class);
if (optPotionEffectData.isPresent()) {
PotionEffectData potionEffectData = optPotionEffectData.get();
potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.BLINDNESS, 1, duration));
target.offer(potionEffectData);
}
target.offer(Keys.FIRE_TICKS, duration);
notify(owner, Text.of(TextColors.YELLOW, "Your sword releases a deadly blaze."));
}
示例8: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
int duration = (int) Math.min(20 * 60 * 5, EntityHealthUtil.getHealth(owner) * 18);
Optional<PotionEffectData> optOwnerPotionEffectData = owner.getOrCreate(PotionEffectData.class);
if (optOwnerPotionEffectData.isPresent()) {
PotionEffectData ownerPotionEffectData = optOwnerPotionEffectData.get();
ownerPotionEffectData.addElement(PotionEffect.of(PotionEffectTypes.SPEED, 2, duration));
owner.offer(ownerPotionEffectData);
}
Optional<PotionEffectData> optTargetPotionEffectData = target.getOrCreate(PotionEffectData.class);
if (optTargetPotionEffectData.isPresent()) {
PotionEffectData targetPotionEffectData = optTargetPotionEffectData.get();
targetPotionEffectData.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 2, duration));
target.offer(targetPotionEffectData);
}
if (optOwnerPotionEffectData.isPresent() || optTargetPotionEffectData.isPresent()) {
notify(owner, Text.of(TextColors.YELLOW, "You gain an agile advantage over your opponent."));
}
}
示例9: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
Optional<PotionEffectData> optPotionEffectData = target.getOrCreate(PotionEffectData.class);
if (!optPotionEffectData.isPresent()) {
return;
}
PotionEffectData potionEffectData = optPotionEffectData.get();
int duration = (int) (EntityHealthUtil.getHealth(owner) * 18);
potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 2, duration));
potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.WEAKNESS, 2, duration));
target.offer(potionEffectData);
notify(owner, Text.of(TextColors.YELLOW, "Your bow slows its victim."));
}
示例10: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
Optional<PotionEffectData> optPotionEffectData = owner.getOrCreate(PotionEffectData.class);
if (!optPotionEffectData.isPresent()) {
return;
}
PotionEffectData potionEffectData = optPotionEffectData.get();
int duration = (int) (EntityHealthUtil.getHealth(target) * 10);
potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.REGENERATION, 2, duration));
owner.offer(potionEffectData);
notify(owner, Text.of(TextColors.YELLOW, "You gain a healing aura."));
}
示例11: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
Optional<PotionEffectData> optPotionEffectData = target.getOrCreate(PotionEffectData.class);
if (!optPotionEffectData.isPresent()) {
return;
}
PotionEffectData potionEffectData = optPotionEffectData.get();
int duration = (int) (EntityHealthUtil.getHealth(target) * 10);
potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 9, duration));
if (target instanceof Player) {
potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.BLINDNESS, 0, 20 * 4));
}
target.offer(potionEffectData);
target.getWorld().playSound(SoundTypes.ENTITY_GHAST_SCREAM, target.getLocation().getPosition(), 1, .02F);
notify(owner, Text.of(TextColors.YELLOW, "Your weapon traps your foe in their own sins."));
}
示例12: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
Optional<PotionEffectData> optPotionEffectData = target.getOrCreate(PotionEffectData.class);
if (!optPotionEffectData.isPresent()) {
return;
}
PotionEffectData potionEffectData = optPotionEffectData.get();
int duration = (int) Math.min(20 * 60 * 5, EntityHealthUtil.getHealth(owner) * 24);
potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.WITHER, 2, duration));
target.offer(potionEffectData);
notify(owner, Text.of(TextColors.YELLOW, "Your weapon curses its victim."));
}
示例13: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
Optional<PotionEffectData> optPotionEffectData = target.getOrCreate(PotionEffectData.class);
if (!optPotionEffectData.isPresent()) {
return;
}
PotionEffectData potionEffectData = optPotionEffectData.get();
int duration = (int) Math.min(1200, EntityHealthUtil.getHealth(owner) * 18);
potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.NAUSEA, 1, duration));
target.offer(potionEffectData);
notify(owner, Text.of(TextColors.YELLOW, "Your sword confuses its victim."));
}
示例14: run
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
int duration = (int) Math.min(20 * 60 * 5, EntityHealthUtil.getHealth(owner) * 18);
Optional<PotionEffectData> optOwnerPotionEffectData = owner.getOrCreate(PotionEffectData.class);
if (optOwnerPotionEffectData.isPresent()) {
PotionEffectData ownerPotionEffectData = optOwnerPotionEffectData.get();
ownerPotionEffectData.addElement(PotionEffect.of(PotionEffectTypes.STRENGTH, 1, duration));
owner.offer(ownerPotionEffectData);
}
Optional<PotionEffectData> optTargetPotionEffectData = target.getOrCreate(PotionEffectData.class);
if (optTargetPotionEffectData.isPresent()) {
PotionEffectData targetPotionEffectData = optTargetPotionEffectData.get();
targetPotionEffectData.addElement(PotionEffect.of(PotionEffectTypes.WEAKNESS, 1, duration));
target.offer(targetPotionEffectData);
}
if (optOwnerPotionEffectData.isPresent() || optTargetPotionEffectData.isPresent()) {
notify(owner, Text.of(TextColors.YELLOW, "Your sword leaches strength from its victim."));
}
}
示例15: runFrimus
import org.spongepowered.api.effect.potion.PotionEffect; //导入依赖的package包/类
private void runFrimus() {
createWall(
getRegion(FreakyFourBoss.FRIMUS),
type -> type == BlockTypes.AIR,
type -> type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA,
BlockTypes.AIR,
BlockTypes.LAVA,
config.frimusWallDensity,
-1
);
for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
List<PotionEffect> oldPotions = player.get(Keys.POTION_EFFECTS).orElse(new ArrayList<>());
List<PotionEffect> newPotions = oldPotions.stream().filter(
effect -> effect.getType() != PotionEffectTypes.FIRE_RESISTANCE
).collect(Collectors.toList());
if (oldPotions.size() != newPotions.size()) {
player.offer(Keys.POTION_EFFECTS, newPotions);
}
}
}