[1.11.2] setYield TNT

Discussion in 'Spigot Plugin Development' started by WAS, Apr 18, 2017.

  1. WAS

    WAS

    This doesn't seem to be working with TNT? Is this intended? Even if I setYield with getYield there is no explosion damage. I'm trying to have a multiplier on a TNTPrimed entity. In my head it all seemed easy enough

    Code (Java):
      public TNTPrimed createPrimedTNT(String type, Location location, Float multiplier, int ticks, Sound sound, float pitch, JavaPlugin plugin) {
         TNTPrimed tnt = location.getWorld().spawn(location, TNTPrimed.class);
         location.getWorld().playSound(location, sound, 1, pitch);
         tnt.setYield(tnt.getYield() * multiplier);
         tnt.setMetadata("tntType", new FixedMetadataValue(plugin, type));
         tnt.setFuseTicks(ticks);
         return tnt;
       }
    Update: Figured it out. My float was default to zero as there was a typo in the config path key. :p
     
    #1 WAS, Apr 18, 2017
    Last edited: Apr 18, 2017
  2. NathanWolf

    Supporter

    What multiplier are you trying? Maybe add some debug prints- setYield definitely works, though I've never used getYield.
     
  3. Try listening for the ExplosionPrimeEvent and do e#setYield() there. Should work.
     
    • Like Like x 1
  4. WAS

    WAS

    Just figured it out. Hard to get yield-multiplier from yeld-multipler lol, which had a default value of 0 (being no yeield as a multiplier)
     
    • Funny Funny x 1
  5. NathanWolf

    Supporter

    Should work on spawn, too. I'm doing something very similar and it works (can make very large or very small explosions)

    Code (Text):
    TNTPrimed grenade = (TNTPrimed)context.getWorld().spawnEntity(targetLoc, EntityType.PRIMED_TNT);
                if (grenade == null) {
                    return SpellResult.FAIL;
                }
                if (living != null) {
                    CompatibilityUtils.setTNTSource(grenade, living);
                }
                Vector aim = context.getDirection();
                grenade.setVelocity(aim);
                grenade.setYield(size);
                grenade.setFuseTicks(fuse);
                grenade.setIsIncendiary(useFire);
     
    • Friendly Friendly x 1
  6. I use the setYield in the event so i can change also creepers explosions range, that's why i suggested that.
     
    • Informative Informative x 1
  7. WAS

    WAS

    Thanks I figured it out. It was a typo. Oi. But I am curious. Because you use spawnEntity, does your primed TNT pass through the entity-based event listeners? Default bukkit uses spawn like I am using in my method which I wonder if that is why the TNTPrimed circumvents those events? Or are the events literally just ignoring TNTPrimed
     
  8. NathanWolf

    Supporter

    I believe it will fire an entity spawn event with a spawn reason of CUSTOM.
     
  9. I think it might throw you an error. I think spawnEntity() can be used only with LivingEntity. Not 100% sure though
     
  10. NathanWolf

    Supporter

    spawnEntity can spawn any entity type.
     
    • Agree Agree x 1