Solved Primed tnt help.

Discussion in 'Plugin Development' started by NDUGAR, May 10, 2014.

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

    NDUGAR

    I'm creating a falling block of primed tnt so what would I put the Material as?
     
  2. Offline

    mine-care

    Int there material.tnt_primed?
    Or else you should spawn it as an entity... Spawnentity
    Sorry cant provide code, I'm on phone..
     
  3. Offline

    xTigerRebornx

  4. Offline

    NDUGAR

    The reason why I wanted it to be a falling block was so my plugin would work, my basic idea is to create a random meteor event plugin so it'll randomly find a place within a radius to spawn the falling block primed tnt so that when it hits the floor it uses my other module of code which makes blocks scatter everywhere. So would this work using the entity?

    When using .spawnEntity do you need the attribute Material.<anything>?

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

    mine-care

    Probably... Can't try because I'm on phone but the best you can do is give it a try
     
  6. Offline

    NDUGAR


    So what material would it be?
     
  7. Offline

    xTigerRebornx

  8. Offline

    NDUGAR

    It's okay, I've sorted it out kinda, so I've turned it into a block of tnt, but how would I check when the fallingBlock is on the ground?

    As in I want the primed tnt to be spawned when the tnt block has hit the ground :D

    In short I'd like to check if the fallingblock has hit the ground in order to spawn a primedtnt?

    Bump?

    So, I've created almost all of my code apart from creating PrimedTNT once the FallingBlock hits the ground... :(

    Any help?

    Code:java
    1. package me.Schnel.BetterExplosions;
    2.  
    3. import java.util.Random;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    8. import org.bukkit.World;
    9. import org.bukkit.block.Block;
    10. import org.bukkit.entity.FallingBlock;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.Event;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.entity.EntityExplodeEvent;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17. import org.bukkit.scheduler.BukkitScheduler;
    18. import org.bukkit.util.Vector;
    19.  
    20. public class main extends JavaPlugin implements Listener{
    21.  
    22.  
    23. public void onEnable(){
    24. getServer().getPluginManager().registerEvents(this, this);
    25. getLogger().info("Better Explosions Enabled");
    26. getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)");
    27. }
    28.  
    29. public void onDisable(){
    30. getLogger().info("Better Explosions Disabled");
    31. getLogger().severe("Uh oh! The plugin is DEAD!!! (or broken)");
    32. }
    33.  
    34. @EventHandler
    35. public void onEntityExplode(final EntityExplodeEvent event) {
    36. for(Block b : event.blockList()){
    37. float x = (float) -2 + (float) (Math.random() * ((2- -2) +1));
    38. float y = (float) -3 + (float) (Math.random() * ((3- -3) +1));
    39. float z = (float) -2 + (float) (Math.random() * ((2- -2) +1));
    40.  
    41. @SuppressWarnings("deprecation")
    42. FallingBlock fallingBlock = b.getWorld().spawnFallingBlock(
    43. b.getLocation(), b.getType(), b.getData());
    44. fallingBlock.setDropItem(false);
    45. fallingBlock.setVelocity(new Vector(x, y, z));
    46.  
    47. b.setType(Material.AIR);
    48. }
    49.  
    50.  
    51. Random rand = new Random();
    52.  
    53. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    54. scheduler.scheduleSyncDelayedTask(this, new Runnable() {
    55. @Override
    56. public void run() {
    57. int random = new Random().nextInt(Bukkit.getOnlinePlayers().length);
    58. Player player = Bukkit.getOnlinePlayers()[random];
    59. Location location = player.getLocation();
    60. World world = player.getWorld();
    61. Location center = location;
    62. Random rand = new Random();
    63. double angle = rand.nextDouble()*360; //Generate a random angle
    64. double x = center.getX() + (rand.nextDouble()*100*Math.cos(Math.toRadians(angle)));
    65. double z = center.getZ() + (rand.nextDouble()*100*Math.sin(Math.toRadians(angle)));
    66. double y = center.getY() + 700;
    67. Location newloc = new Location(world, x, y, z);
    68. FallingBlock TNT = location.getWorld().spawnFallingBlock(newloc, Material.TNT, (byte)0);
    69. TNT.setVelocity(new Vector());
    70. if (event.getEntity() instanceof FallingBlock); {
    71.  
    72. }
    73. }
    74. }, (long) rand.nextInt(567));
    75.  
    76. }
    77. }
    78.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page