• Es freut uns dass du in unser Minecraft Forum gefunden hast. Hier kannst du mit über 130.000 Minecraft Fans über Minecraft diskutieren, Fragen stellen und anderen helfen. In diesem Minecraft Forum kannst du auch nach Teammitgliedern, Administratoren, Moderatoren , Supporter oder Sponsoren suchen. Gerne kannst du im Offtopic Bereich unseres Minecraft Forums auch über nicht Minecraft spezifische Themen reden. Wir hoffen dir gefällt es in unserem Minecraft Forum!

ThrownPotion einen Effekt geben?

HardSoul

Ehemaliges Teammitglied
Ehem. Teammitglied
Registriert
2 August 2012
Beiträge
759
Diamanten
251
Minecraft
HardS0ul
Hi Leute,
seit neustem arbeite ich an eigenen Traits für Citizens.
Soweit klappt auch alles, nur eine Sache bekomme ich nicht hin.
Einige NPC sollen Potions werfen, die einen Effekt haben, nur mein jetziger Code funktioniert nich:

Javascript:
    public static void throwPotion(Entity e, NPC npc){
       
       
        Location nloc = npc.getEntity().getLocation();
        Location eloc = e.getLocation();
       
        Vector v = nloc.toVector().subtract(eloc.toVector()).multiply(-1);
        v.multiply(0.3);
       
        LivingEntity ne = (LivingEntity) npc.getEntity();
       
        ThrownPotion tp = ne.launchProjectile(ThrownPotion.class, v);
        tp.getEffects().clear();
        tp.getEffects().add(new PotionEffect(PotionEffectType.CONFUSION, 200, 1));
    }

Wo liegt mein Fehler?
Oder geht das auch anders?
 

HardSoul

Ehemaliges Teammitglied
Ehem. Teammitglied
Registriert
2 August 2012
Beiträge
759
Diamanten
251
Minecraft
HardS0ul
Ich habe es jetzt dem Link angepasst, aber es spawnt nun garnicht mehr, und Fehler in der Konsole gibt es auch nicht.

Hier mal der neue Code:
Javascript:
    @SuppressWarnings("deprecation")
    public static void throwPotion(Entity e, NPC npc){
       
       
        Location nloc = npc.getEntity().getLocation();
        Location eloc = e.getLocation();
       
        Vector v = nloc.toVector().subtract(eloc.toVector()).multiply(-1);
        v.multiply(0.3);
       
        LivingEntity ne = (LivingEntity) npc.getEntity();
       
        World w = ne.getLocation().getWorld();
        PotionEffect pe = new PotionEffect(PotionEffectType.CONFUSION, 200, 1);
        PotionType pt = PotionType.getByEffect(pe.getType());
        Potion po = new Potion(pt);
        int data = po.toDamageValue();
       
       
        nloc.setY(nloc.getY()+1);
       
        net.minecraft.server.v1_8_R3.World nmsw = ((CraftWorld) w).getHandle();
       
        EntityPotion ent = new EntityPotion(nmsw);
        ent.setLocation(nloc.getX(), nloc.getY(), nloc.getZ(), 0, 0);
       
        NBTTagCompound nbt = new NBTTagCompound();
       
        ent.b(nbt);

        NBTTagCompound potionTag = nbt.getCompound("Potion");
        NBTTagCompound tagTag = new NBTTagCompound();
        if(potionTag == null){
            potionTag = new NBTTagCompound();
            potionTag.setShort("id", (short) 373);
            potionTag.setShort("Damage", (short) data);
            potionTag.setByte("Count", (byte) 1);
            tagTag.set("CustomPotionEffects", makePotion(pe));
        }else{
            tagTag = potionTag.getCompound("tag");

            tagTag.set("CustomPotionEffects", makePotion(pe));


        }
       
       
        potionTag.set("tag", tagTag);
        nbt.set("Potion", potionTag);
       
        ent.a(nbt);
       
        nmsw.addEntity(ent);
       
        Entity te = ent.getBukkitEntity();
       
        te.setVelocity(v);   
    }
   
    @SuppressWarnings("deprecation")
    public static NBTTagList makePotion(PotionEffect effect) {

        NBTTagList list = new NBTTagList();

        NBTTagCompound potionType = new NBTTagCompound();

        potionType.setByte("Id", (byte) effect.getType().getId());

        potionType.setByte("Amplifier", (byte) effect.getAmplifier());

        potionType.setInt("Duration", effect.getDuration());

        potionType.setByte("Ambient", (byte) 0); //Not ambient

        list.add(potionType);

        return list;

        }
 
Oben