How do I detonate a TNT?

Discussion in 'Plugin Development' started by Etsijä, Apr 28, 2013.

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

    Etsijä

    Simple question: I have a plugin under development, which lets users throw TNT as grenades, and the TNT explodes on impact. This kind of works, but how I'm doing it atm is that when the TNT hits something, I delete the entity and create an explosion at the coordinates instead with world.createExplosion().

    The reason I'm doing it this way is I cannot seem to make the original TNT explode when I want to. I have tried to set its fuseTicks to zero, but the method throws tens of Java errors in my code.

    What I'm asking is this: is the setFuseTicks(0) the proper way to detonate a TNT? Because if it is, then I just have to fix my code...
     
  2. Offline

    chasechocolate

    Try using .setFuseTicks(1).
     
  3. Offline

    Etsijä

    Nope, still does it. The second I try to set up the fuseTicks of my entity (casted to TNTPrimed), it spams out the "ticking entity" error and the whole server crashes (becomes unresponsive to the players, altough I can still commad it via console).

    Here's the relevant code. The commented-out lines do work, the one which sets the fuseTicks doesn't.
    Code:
    CommonEntity<Entity> tntEntity = CommonEntity.get(entity);
    tntEntity.setController(new EntityController<CommonEntity<TNTPrimed>>() {
      public void onTick() {
        super.onTick();
          double squaredDistance = handLocation.distanceSquared(entity.getLocation());
          if (entity.isMovementImpaired() || !entity.isMoving() || entity.isOnGround()) {
            if (squaredDistance > squaredSafetyDistance) {
              //entity.remove();
              //world.createExplosion(entity.getLocation(), ImpactTNT.expRadius);
              ((TNTPrimed) entity).setFuseTicks(1);
              return;
            } else {
              player.sendMessage(ChatColor.GREEN + "ImpactTNT: safety fuse applied, immediate detonation cancelled");
              return;
            }
          }
        }
      });
    The code uses a controller from BKCommonLib. Like I say, it works like a charm when those two commented lines are used, but the setFuseTicks() one crashes the whole server. Here's the error report:
    http://pastebin.com/PrBararS

    Yeah, seems like these were a problem in some Bukkit servers some while ago, but Bukkit fixed it. I suspect something's wrong in BKCommonLib. Having anything TNTPrimed related (even a simple creator) at all inside doTick() crashes the server.

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

Share This Page