#Zombiefied Piglin automatically attack players off spawn

1 messages · Page 1 of 1 (latest)

sick summit
#

Here is some code to modify spawn properties of zombiefied piglin's to spawn with armor and effects, I want to add it to make them angry at the players off spawn. I currently have code for this, but it does not work. any alternatives?

            
            
            
            PigZombie zombifiedpiglin = (PigZombie) event.getEntity();
            
            
            zombifiedpiglin.getEquipment().setHelmet(new ItemStack(Material.DIAMOND_HELMET));
            zombifiedpiglin.getEquipment().setChestplate(new ItemStack(Material.DIAMOND_CHESTPLATE));
            zombifiedpiglin.getEquipment().setLeggings(new ItemStack(Material.DIAMOND_LEGGINGS));
            zombifiedpiglin.getEquipment().setBoots(new ItemStack(Material.DIAMOND_BOOTS));
            
            zombifiedpiglin.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 999999999, 2));
            zombifiedpiglin.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 999999999, 5));
            
            
            zombifiedpiglin.setAngry(true);
                    
                    
            
        };

the current code is zombifiedpiglin.setAngry(true);

runic kernel
#

There is a second method to set how long they should be angry

sick summit
runic kernel
#

Integer.MAX_VALUE

sick summit
#

okay, let me test it

sick summit
#
            zombifiedpiglin.setAnger(Integer.MAX_VALUE);```
stray otter
#

are they spawnign with the armour?

sick summit
stray otter
#

reverse teh methods

#

set the duration before you set angry

sick summit
#

ill test it

sick summit
stray otter
#

you are not doing anything silly like cancelling the angry event?

sick summit
#

i have no idea, here is the current code

stray otter
#

do you listen to teh PigZombieAngerEvent?

sick summit
#

no

stray otter
#

good

sick summit
#

im listening to creaturespawnevent

stray otter
#

is that code you showed in the spawn event?

#

k

#

as the event is cancelable you might try setting the anger in a runnable delayed a couple of ticks

sick summit
#

how would i do that?

stray otter
#

in the main chat type ?scheduling

#

Scheduling a delayed task with BukkitRunnable

sick summit
stray otter
#

and run it

#

just a few ticks shoudl be enough

#

say 5

sick summit
stray otter
#

add a constructor to yoru Listener Class that accepts an instance of yrou main class as an arg

sick summit
#

like this? where would I add this code to the listener class? public class Other { private final Main plugin = Main.getPlugin(Main.class); }

stray otter
#

no

#
JavaPlugin plugin;
public Other(JavaPlugin plugin) {
    this.plugin = plugin;
}```
sick summit
#

do I put this in the main class?

stray otter
#

that is in yoru Listener class

sick summit
#

okay

stray otter
#

then in your Main when you call new Other() you change it to new Other(this)

sick summit
sick summit
stray otter
#

other is whatever yoru listener class is

#

This is basic Java

sick summit
#

oh

#

sorry, this is somewhat a learning experience for me

sick summit
stray otter
#

no

#

where do you call registerEvents( ?

sick summit
stray otter
#

change it to new Listeners(this)