Location Help Subtracting 1 from Y

Discussion in 'Plugin Development' started by lewysryan, Jun 29, 2014.

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

    lewysryan

    So Basicly I want to have particles to fly down -Y every ____ ticks. But I tried to see why my code wasn't working with gold blocks (easier to see what's happening) and this is what's happening:


    It's basically meant to start 30 blocks above the players head and continue until it finds a block that's not air.

    Code:
    Code:java
    1. private HashMap<Player, BukkitRunnable> task = new HashMap<Player, BukkitRunnable>();
    2.  
    3.  
    4. @EventHandler
    5. public void onBlazeRodClick(final PlayerInteractEvent e){
    6.  
    7. if(e.getPlayer().getItemInHand().getType() == Material.BLAZE_ROD){
    8.  
    9. if(Points.hasEnough(e.getPlayer().getName(), 100)){
    10. Points.removePoints(e.getPlayer().getName(), 100);
    11.  
    12. task.put(e.getPlayer(), new BukkitRunnable(){
    13.  
    14.  
    15. int takeaway = 1;
    16. Location loc = e.getPlayer().getLocation().add(0,30,0); //Start 30 blocks above player
    17. public void run() {
    18.  
    19.  
    20. takeaway++;
    21.  
    22. Bukkit.broadcastMessage("" + takeaway); //it's going up by one
    23.  
    24.  
    25. if(!(loc.subtract(0,takeaway,0).getBlock().getType() == Material.AIR)){
    26. loc.getWorld().strikeLightning(loc);
    27. task.remove(e.getPlayer());
    28. cancel();
    29. }
    30.  
    31. loc.subtract(0,takeaway,0).getBlock().setType(Material.GOLD_BLOCK); //I wanted to do it with Particles but I used blocks to see why it's not working
    32. }
    33.  
    34. });
    35.  
    36. task.get(e.getPlayer()).runTaskTimer(Hub.getPluginInstance(), 10, 10);
    37.  
    38. }
    39. }
    40. }


    Thanks for the help
     
  2. I'm not sure what I'm seeing in that video.

    It looks like the blocks are coming down. And then they go up again!
    It also looks like there's gravity. And it gets weaker and weaker.
    But when I read your code, there's no gravity at all. Weeeiird.

    I've watched the video a couple of times. And I'm nauseous by the spastic camera movement.

    The code looks fine to me. It should do what you explained. Although.... when you do this (line 31)
    Code:java
    1. loc.subtract(0,takeaway,0).getBlock().setType(Material.GOLD_BLOCK);
    Shouldn't you also reset the previous one to Material.AIR ??? I would expect you end up with big column of Gold blocks, without resetting the previous one to Material.AIR.
     
Thread Status:
Not open for further replies.

Share This Page