Molotov Cocktail !?

Discussion in 'Plugin Development' started by Weszzz, Apr 22, 2014.

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

    Weszzz

    Hi there,
    i want to make a molotov cocktail in minecraft. It is an XP bottle and if you throw it and it hits the ground there will be fire in a radius of... lets say 2. Then after a couple of seconds i want it to remove the fire. Can someone explain me on how to make this ? I do not have any code yet
    Thanks!
     
  2. Offline

    stink123456

    You would probably be using the ProjectileHitEvent, when it hits the ground you could check for all the blocks around them and set the air ones with the lowest y coordinate on fire and save those blocks, then create a scheduled task to set those blocks back to air
     
  3. Offline

    SuppaTim

    You could throw it and check when it hits the ground (using repeating task), create fire and keep it for a while using a repeating task and also check in the repeating task which creates the fire effect if there are players within a certain region and set them on fire.
    And, poof, you've your molotov
     
  4. Offline

    Slikey

    This might have errors.. Just made it on my notepad on the laptop.. Hope it kinda works..

    Code:java
    1. public static final int RADIUS = 3;
    2. public static final int TICKS = 60;
    3.  
    4. @EventHandler
    5. public void onMolotovImpact(ExpBottleEvent event) {
    6. event.setExperience(0);
    7. Location center = event.getEntity().getLocation();
    8. final List<Block> burn = new ArrayList<Block>();
    9. int y = event.getEntity().getLocation().getBlockY();
    10. for (x = -RADIUS; x <= RADIUS; x++) {
    11. for (z = -RADIUS; z <= RADIUS; z++) {
    12. Block block = event.getEntity().getWorld().getBlockAt(x, y, z);
    13. if (block.getType() != Material.AIR)
    14. continue;
    15. block.setType(Material.FIRE);
    16. burn.add(block);
    17. }
    18. }
    19.  
    20. Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    21.  
    22. @Override
    23. public void run() {
    24. for (Block block : burn)
    25. if (block.getType() == Material.FIRE)
    26. block.setType(Material.AIR);
    27. }
    28.  
    29. }, TICKS);
    30. }


    SuppaTim stink123456 There is an ExpBottleEvent. It is fired when an ExpBottle hits the ground.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    stink123456

    is there, you can actually check with the event i gave if its an instanceof an xp bottle
     
  6. Offline

    Slikey

    stink123456 Yes of course, but you cannot control the Exp dropped with the event. ExpBottleEvent.setExperience() can. ;)
     
  7. Offline

    stink123456

    well you could probably just remove the exp bottle :)
     
  8. Offline

    Weszzz

    Slikey Hi, sorry that i am replying that late but i got this now:
    Code:java
    1. package me.Weszzz.SurviveIt;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.Location;
    8. import org.bukkit.Material;
    9. import org.bukkit.block.Block;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.entity.ExpBottleEvent;
    12.  
    13. public class Molotov {
    14.  
    15. public static final int RADIUS = 3;
    16. public static final int TICKS = 60;
    17.  
    18. @EventHandler
    19. public void onMolotovImpact(ExpBottleEvent event) {
    20. event.setExperience(0);
    21. Location center = event.getEntity().getLocation();
    22. final List<Block> burn = new ArrayList<Block>();
    23. int y = event.getEntity().getLocation().getBlockY();
    24. for (x = -RADIUS; x <= RADIUS; x++) {
    25. for (z = -RADIUS; z <= RADIUS; z++) {
    26. Block block = event.getEntity().getWorld().getBlockAt(x, y, z);
    27. if (block.getType() != Material.AIR)
    28. continue;
    29. block.setType(Material.FIRE);
    30. burn.add(block);
    31. }
    32. }
    33.  
    34. Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    35.  
    36. @Override
    37. public void run() {
    38. for (Block block : burn)
    39. if (block.getType() == Material.FIRE)
    40. block.setType(Material.AIR);
    41. }
    42.  
    43. }, TICKS);
    44. }
    45. }
    46.  

    But on line 24, 25, 26 and 34 i get errors. The errors are:
    Line 24:
    Multiple markers at this line
    - x cannot be resolved to a
    variable
    - x cannot be resolved to a
    variable
    - x cannot be resolved to a
    variable
    Line 25:
    Multiple markers at this line
    - z cannot be resolved to a
    variable
    - z cannot be resolved to a
    variable
    - z cannot be resolved to a
    variable
    Line 26:
    Multiple markers at this line
    - z cannot be resolved to a
    variable
    - x cannot be resolved to a
    variable
    Line 34:
    plugin cannot be resolved to a variable

    Could you help me with this ? Thanks!

    Slikey I already fixed the errors on line 24, 25 and 26. The only error now is on line 34.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  9. Offline

    Slikey

    Weszzz You have to pass the instance of you JavaPlugin to the scheduler
     
  10. Offline

    Weszzz

    Slikey I did that and now i got this in my Molotov class:
    Code:java
    1. package me.Weszzz.SurviveIt;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.List;
    5.  
    6.  
    7.  
    8. import org.bukkit.Bukkit;
    9. import org.bukkit.Location;
    10. import org.bukkit.Material;
    11. import org.bukkit.block.Block;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.entity.ExpBottleEvent;
    15.  
    16. public class Molotov
    17. implements Listener {
    18.  
    19. private test plugin;
    20. public Molotov(test instance)
    21. {
    22. this.plugin = instance;
    23. }
    24.  
    25. public static final int RADIUS = 3;
    26. public static final int TICKS = 60;
    27.  
    28. @EventHandler
    29. public void onMolotovImpact(ExpBottleEvent event) {
    30. event.setExperience(0);
    31. Location center = event.getEntity().getLocation();
    32. final List<Block> burn = new ArrayList<Block>();
    33. int x = event.getEntity().getLocation().getBlockX();
    34. int y = event.getEntity().getLocation().getBlockY();
    35. int z = event.getEntity().getLocation().getBlockZ();
    36. for (x = -RADIUS; x <= RADIUS; x++) {
    37. for (z = -RADIUS; z <= RADIUS; z++) {
    38. Block block = event.getEntity().getWorld().getBlockAt(x, y, z);
    39. if (block.getType() != Material.AIR)
    40. continue;
    41. block.setType(Material.FIRE);
    42. burn.add(block);
    43. }
    44. }
    45.  
    46. Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    47.  
    48. @Override
    49. public void run() {
    50. for (Block block : burn)
    51. if (block.getType() == Material.FIRE)
    52. block.setType(Material.AIR);
    53. }
    54.  
    55. }, TICKS);
    56. }
    57. }
    58.  

    In my main class i did this:
    Code:java
    1. this.getServer().getPluginManager().registerEvents(new Molotov(this), this);

    But now if i throw a Bottle 'O Enchanting and it lands nothing happens..
    Sometimes i hear the fire sound but i see no fire.
    Whats wrong ?
     
  11. Offline

    Slikey

    Weszzz you don't set the position right

    Code:java
    1. int posX = event.getEntity().getLocation().getBlockX();
    2. int posY = event.getEntity().getLocation().getBlockY();
    3. int posZ = event.getEntity().getLocation().getBlockZ();
    4. for (x = -RADIUS; x <= RADIUS; x++) {
    5. for (z = -RADIUS; z <= RADIUS; z++) {
    6. Block block = event.getEntity().getWorld().getBlockAt(posX + x, y, posZ + z);
    7. if (block.getType() != Material.AIR)
    8. continue;
    9. block.setType(Material.FIRE);
    10. burn.add(block);
    11. }
    12. }
     
  12. Offline

    Weszzz

Thread Status:
Not open for further replies.

Share This Page