Search in sources :

Example 1 with GlowMetaPotion

use of net.glowstone.inventory.GlowMetaPotion in project Glowstone by GlowstoneMC.

the class AreaEffectCloudStore method save.

@Override
public void save(GlowAreaEffectCloud entity, CompoundTag tag) {
    super.save(entity, tag);
    tag.putInt("Age", entity.getTicksLived());
    Color color = entity.getColor();
    if (color != null) {
        tag.putInt(COLOR, color.asRGB());
    }
    tag.putInt(DURATION, entity.getDuration());
    tag.putInt(REAPPLICATION_DELAY, entity.getReapplicationDelay());
    tag.putInt(WAIT_TIME, entity.getWaitTime());
    ProjectileSource source = entity.getSource();
    if (source instanceof Entity) {
        UUID uuid = ((Entity) source).getUniqueId();
        tag.putLong(OWNER_UUID_LEAST, uuid.getLeastSignificantBits());
        tag.putLong(OWNER_UUID_MOST, uuid.getMostSignificantBits());
    }
    tag.putInt(DURATION_ON_USE, entity.getDurationOnUse());
    tag.putFloat(RADIUS, entity.getRadius());
    tag.putFloat(RADIUS_ON_USE, entity.getRadiusOnUse());
    tag.putFloat(RADIUS_PER_TICK, entity.getRadiusPerTick());
    Particle particle = entity.getParticle();
    if (particle != null) {
        tag.putString(PARTICLE, particle.toString());
    }
    PotionData potion = entity.getBasePotionData();
    if (potion != null) {
        tag.putString(POTION, GlowMetaPotion.dataToString(potion));
    }
    tag.putCompoundList(EFFECTS, entity.getCustomEffects().stream().map(GlowMetaPotion::toNbt).collect(Collectors.toList()));
// TODO: Are ParticleParam1 and ParticleParam2 unused?
}
Also used : Particle(org.bukkit.Particle) Entity(org.bukkit.entity.Entity) PotionData(org.bukkit.potion.PotionData) GlowMetaPotion(net.glowstone.inventory.GlowMetaPotion) Color(org.bukkit.Color) ProjectileSource(org.bukkit.projectiles.ProjectileSource) UUID(java.util.UUID)

Example 2 with GlowMetaPotion

use of net.glowstone.inventory.GlowMetaPotion in project Glowstone by GlowstoneMC.

the class ItemBowTest method testTippedArrow.

@Test
public void testTippedArrow() {
    ItemStack arrow = new ItemStack(Material.TIPPED_ARROW, 1);
    GlowMetaPotion potion = new GlowMetaPotion(arrow.getItemMeta());
    potion.setColor(Color.PURPLE);
    final PotionData potionData = new PotionData(PotionType.FIRE_RESISTANCE);
    potion.setBasePotionData(potionData);
    final PotionEffect effect = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 10, 1);
    potion.addCustomEffect(effect, false);
    assertTrue(arrow.setItemMeta(potion));
    inventory.addItem(arrow);
    // Should now be able to start shooting
    bow.startUse(player, bowItemStack);
    verify(player, times(1)).setUsageItem(bowItemStack);
    verify(player, times(1)).setUsageTime(anyInt());
    when(player.getUsageTime()).thenReturn(10);
    // Finish shooting
    bow.endUse(player, bowItemStack);
    verify(player, times(1)).launchProjectile(TippedArrow.class);
    verify(launchedTippedArrow, times(1)).setColor(Color.PURPLE);
    verify(launchedTippedArrow, times(1)).setBasePotionData(potionData);
    verify(launchedTippedArrow, times(1)).addCustomEffect(eq(effect), anyBoolean());
    verify(player, times(1)).setUsageItem(null);
    verify(player, times(1)).setUsageTime(0);
    checkInventory(inventory, 1, BOW_WITH_DAMAGE_1);
    checkInventory(inventory, 0, BOW_WITH_DAMAGE_NOT_1);
    checkInventory(inventory, 0, item -> ARROW_TYPES.contains(item.getType()));
}
Also used : PotionData(org.bukkit.potion.PotionData) GlowMetaPotion(net.glowstone.inventory.GlowMetaPotion) PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.jupiter.api.Test)

Example 3 with GlowMetaPotion

use of net.glowstone.inventory.GlowMetaPotion in project Glowstone by GlowstoneMC.

the class NormalTippedArrowStore method save.

@Override
public void save(GlowArrow entity, CompoundTag tag) {
    super.save(entity, tag);
    if (entity instanceof TippedArrow) {
        PotionData potion = ((TippedArrow) entity).getBasePotionData();
        if (potion != null) {
            tag.putString(POTION, GlowMetaPotion.dataToString(potion));
        }
        tag.putCompoundList(CUSTOM_POTION_EFFECTS, ((TippedArrow) entity).getCustomEffects().stream().map(GlowMetaPotion::toNbt).collect(Collectors.toList()));
    }
}
Also used : PotionData(org.bukkit.potion.PotionData) TippedArrow(org.bukkit.entity.TippedArrow) GlowTippedArrow(net.glowstone.entity.projectile.GlowTippedArrow) GlowMetaPotion(net.glowstone.inventory.GlowMetaPotion)

Example 4 with GlowMetaPotion

use of net.glowstone.inventory.GlowMetaPotion in project Glowstone by GlowstoneMC.

the class NormalTippedArrowStore method load.

@Override
public void load(GlowArrow entity, CompoundTag tag) {
    super.load(entity, tag);
    if (entity instanceof TippedArrow) {
        TippedArrow tippedArrow = (TippedArrow) entity;
        tag.readInt(COLOR, rgb -> tippedArrow.setColor(Color.fromRGB(rgb)));
        // TODO: POTION
        tag.readCompoundList(CUSTOM_POTION_EFFECTS, list -> list.stream().map(GlowMetaPotion::fromNbt).forEach(effect -> tippedArrow.addCustomEffect(effect, false)));
    }
}
Also used : CompoundTag(net.glowstone.util.nbt.CompoundTag) Location(org.bukkit.Location) TippedArrow(org.bukkit.entity.TippedArrow) GlowTippedArrow(net.glowstone.entity.projectile.GlowTippedArrow) GlowMetaPotion(net.glowstone.inventory.GlowMetaPotion) Color(org.bukkit.Color) Collectors(java.util.stream.Collectors) PotionData(org.bukkit.potion.PotionData) GlowArrow(net.glowstone.entity.projectile.GlowArrow) TippedArrow(org.bukkit.entity.TippedArrow) GlowTippedArrow(net.glowstone.entity.projectile.GlowTippedArrow) GlowMetaPotion(net.glowstone.inventory.GlowMetaPotion)

Aggregations

GlowMetaPotion (net.glowstone.inventory.GlowMetaPotion)4 PotionData (org.bukkit.potion.PotionData)4 GlowTippedArrow (net.glowstone.entity.projectile.GlowTippedArrow)2 Color (org.bukkit.Color)2 TippedArrow (org.bukkit.entity.TippedArrow)2 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 GlowArrow (net.glowstone.entity.projectile.GlowArrow)1 CompoundTag (net.glowstone.util.nbt.CompoundTag)1 Location (org.bukkit.Location)1 Particle (org.bukkit.Particle)1 Entity (org.bukkit.entity.Entity)1 ItemStack (org.bukkit.inventory.ItemStack)1 PotionEffect (org.bukkit.potion.PotionEffect)1 ProjectileSource (org.bukkit.projectiles.ProjectileSource)1 Test (org.junit.jupiter.api.Test)1