How to make entity jump and explode like this?

Discussion in 'Plugin Development' started by bars96, Jan 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    bars96

    Subject. I don't understand how to realise that:
     
  2. Offline

    zDylann

    Looks like you could just change the mobs velocity to shoot him up and have a delayed task for the AoE explosions around the mobs location.
     
  3. Offline

    xTrollxDudex

    bars96
    Hmm, listen EntityDamageEvent, chrck that it is a fall, and then iterate through a list of locations generated within a radius of the entity (triple nested for loops?) and cause explosions.
     
  4. Offline

    bars96

    How to make it around the mob? And how to make entity jump too far like on this video?
     
  5. Offline

    bars96

    UP! How to make it around the mob?
     
  6. Offline

    bars96

    I tried this code:
    Show Spoiler
    Code:
    public class EntityListener implements Listener {
    private static OnlyMZ plugin;
    private Random rn = new Random();
     
    public static void initialize(OnlyMZ p) {
    plugin = p;
    }
     
    @EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
    private void onEntityExplode(EntityExplodeEvent e) {
    e.blockList().clear();
    }
     
    @EventHandler
    private void onEntityCombust(EntityCombustEvent e) {
    e.setCancelled(true);
    }
     
    @EventHandler(priority=EventPriority.HIGHEST)
    public void onEntityCombustByEntity(EntityCombustByEntityEvent e) {
    e.setCancelled(false);
    }
     
    @EventHandler(priority=EventPriority.HIGHEST)
    public void onEntityCombustByBlock(EntityCombustByBlockEvent e) {
    e.setCancelled(false);
    }
     
    @EventHandler
    private void onEntityTarget(EntityTargetEvent e) {
    if (e.getReason() == TargetReason.CLOSEST_PLAYER) e.setCancelled(true);
    if (e.getEntityType() == EntityType.ZOMBIE) makeFaster((Zombie) e.getEntity());
    }
     
    @EventHandler(priority = EventPriority.HIGHEST)
    private void onCreatureSpawn(CreatureSpawnEvent e) {
    if ((e.getEntityType() != EntityType.ZOMBIE) && (e.getEntityType() != EntityType.PIG_ZOMBIE) && (e.getEntityType() != EntityType.GIANT)) {
    e.setCancelled(true);
    return;
    }
     
    if (e.getEntityType() == EntityType.ZOMBIE) {
    Zombie z = (Zombie) e.getEntity();
    if (z.isVillager()) z.setVillager(false);
     
    if (rn.nextInt(100) == 1 && z.getLocation().getZ() < 0) {
    z.getWorld().spawnEntity(z.getLocation(), EntityType.PIG_ZOMBIE);
    z.remove();
    return;
    }
     
    if (rn.nextInt(200) == 1) {
    z.setBaby(true);
    }
     
    EntityZombie zombie = ((CraftZombie) z).getHandle();
    Field fGoalSelector;
    try {
    fGoalSelector = EntityLiving.class.getDeclaredField("goalSelector");
    fGoalSelector.setAccessible(true);
    PathfinderGoalSelector gs = new PathfinderGoalSelector(((CraftWorld) z.getWorld()).getHandle() != null && ((CraftWorld) z.getWorld()).getHandle().methodProfiler != null ? ((CraftWorld) z.getWorld()).getHandle().methodProfiler : null);
    gs.a(0, new PathfinderGoalFloat(zombie));
    gs.a(1, new PathfinderGoalBreakDoor(zombie));
    gs.a(7, new PathfinderGoalLookAtPlayer(zombie, EntityHuman.class, 5.0F));
    gs.a(7, new PathfinderGoalRandomLookaround(zombie));
    fGoalSelector.set(zombie, gs);
    } catch (NoSuchFieldException ex) {
    ex.printStackTrace();
    } catch (IllegalAccessException ex) {
    ex.printStackTrace();
    }
    return;
    }
     
    if (e.getEntityType() == EntityType.PIG_ZOMBIE) {
    PigZombie pz = (PigZombie) e.getEntity();
    pz.setHealth(1);
    pz.setAngry(true);
    }
    }
     
    @EventHandler
    private void onEntityDamage(EntityDamageEvent e) {
    if (e.getCause() == DamageCause.FALL && (e.getEntity().getType() == EntityType.ZOMBIE || e.getEntity().getType() == EntityType.GIANT)) {
    e.setCancelled(true);
    return;
    }
     
    if (e.getEntity() instanceof Giant) {
    Giant g = (Giant) e.getEntity();
    if (rn.nextInt(10) == 8) {
    giantStomp(g);
    } else {
    final int k = 1 + rn.nextInt(1);
    for (int c = 0; c < k; c++) g.getWorld().spawnEntity(g.getLocation().add(5*(1-rn.nextInt(2)), 10.0D, 5*(1-rn.nextInt(2))), EntityType.ZOMBIE);
    }
    }
    }
     
    @EventHandler
    private void onEntityDeath(EntityDeathEvent e) {
    e.setDroppedExp(0);
    ArrayList<ItemStack> remove = new ArrayList<ItemStack>();
    for (ItemStack d : e.getDrops()) remove.add(d);
    for (ItemStack d : remove) e.getDrops().remove(d);
    if (e.getEntity().getKiller() != null) incrementKills(e.getEntityType(), e.getEntity().getKiller());
    if (e.getEntityType() == EntityType.ZOMBIE) {
    if (rn.nextInt(99) <= 33) e.getDrops().add(new ItemStack(367, 1));
    return;
    }
     
    if (e.getEntityType() == EntityType.PIG_ZOMBIE) {
    e.getEntity().getWorld().createExplosion(e.getEntity().getLocation(), 4.0F, false);
    for (int n = 0; n < 4; n++) {
    Zombie z = (Zombie) e.getEntity().getWorld().spawnEntity(e.getEntity().getLocation(), EntityType.ZOMBIE);
    z.setBaby(true);
    }
    }
    }
     
    private void giantStomp(final Giant g) {
    g.setVelocity(new Vector(0, 0, 0));
    Vector d = g.getLocation().toVector().setY(4.0D).normalize();
    g.setVelocity(d);
    g.getWorld().playSound(g.getLocation(), Sound.ENDERDRAGON_GROWL, 100.0F, 100.0F);
    final int r = 10;
    Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    @Override
    public void run() {
    for (int i = 1; i < 5; i++) {
    giantExplode(g, r * i);
    }
    }
    }
    , 80L);
    }
     
    private void giantExplode(final Giant g, final int ri) {
    final World w = g.getWorld();
    final Location l = g.getLocation();
    Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    @Override
    public void run() {
    w.createExplosion(l.add(ri, 0, ri), 3.5F, false);
    w.createExplosion(l.add(-ri, 0, ri), 3.5F, false);
    w.createExplosion(l.add(ri, 0, -ri), 3.5F, false);
    w.createExplosion(l.add(-ri, 0, -ri), 3.5F, false);
    w.createExplosion(l.add(ri, 0, 0), 3.5F, false);
    w.createExplosion(l.add(-ri, 0, 0), 3.5F, false);
    w.createExplosion(l.add(0, 0, ri), 3.5F, false);
    w.createExplosion(l.add(0, 0, -ri), 3.5F, false);
    for (Entity en : g.getNearbyEntities(ri, 0, ri)) {
    if (en instanceof Player) {
    en.setVelocity(en.getVelocity().add(en.getLocation().toVector().subtract(en.getLocation().toVector()).normalize().multiply(10.0F)));
    }
    }
    }
    }, 40L);
    }
     
    public void makeFaster(Zombie z) {
    float speed = 0.38F;
    EntityZombie zombie = ((CraftZombie) z).getHandle();
    Field fGoalSelector;
    try {
    fGoalSelector = EntityLiving.class.getDeclaredField("goalSelector");
    fGoalSelector.setAccessible(true);
    PathfinderGoalSelector gs = new PathfinderGoalSelector(((CraftWorld) z.getWorld()).getHandle() != null && ((CraftWorld) z.getWorld()).getHandle().methodProfiler != null ? ((CraftWorld) z.getWorld()).getHandle().methodProfiler : null);
    gs.a(2, new PathfinderGoalMeleeAttack(zombie, EntityHuman.class, speed, false));
    gs.a(3, new PathfinderGoalMeleeAttack(zombie, EntityVillager.class, speed, true));
    gs.a(4, new PathfinderGoalMoveTowardsRestriction(zombie, speed));
    gs.a(5, new PathfinderGoalMoveThroughVillage(zombie, speed, false));
    gs.a(6, new PathfinderGoalRandomStroll(zombie, speed));
    fGoalSelector.set(zombie, gs);
    } catch (NoSuchFieldException ex) {
    ex.printStackTrace();
    } catch (IllegalAccessException ex) {
    ex.printStackTrace();
    }
    }
    }


    But it very buggy. How to fix that? YouTube won't to upload my videos :(
     
  7. I would say use new entity velocity(which will allow you to shoot the entity in the air or launch it). Then after say, 1 second, you can do a for loop which gets the entities location and repeats with each one being on another side of the entity.
     
  8. Offline

    bars96

    I have been uploaded video:
     
  9. Offline

    Quackster

    Are you seriously copying MineZ? lol.
     
  10. Offline

    bars96

    Not all. And only for me.
     
  11. Offline

    bennie3211

    Quackster so? MineZ copied DayZ, so maybe he is doing the same as what shotbow has done;)
     
    bars96 likes this.
  12. Offline

    Quackster

    If it has some unique features then go ahead then.
     
  13. Offline

    bars96

    Yes, it has many new features. I like that giant skill.
     
    bennie3211 likes this.
Thread Status:
Not open for further replies.

Share This Page