Tnt entity speed

Discussion in 'Plugin Requests' started by Pvprod, Oct 21, 2020.

  1. Minecraft version: 1.12.x
    Suggested name: Tnt entity speed

    What I want: A plugin that would increase the velocity of tnt flying upon it being exploded by other tnt. This is so that tnt cannons can shoot tnt at a faster speed, therefor at a further range. If it would be some how configurable.. say 1.3x the normal speed for instance would be adjustable.

    Thanks! I'm hoping this wouldn't cause any other entites to bug out/or be effected. Hoping its doable. Someone i asked mention maybe 'you could use getVelocity to get its velocity, modify the speed and then set the velocity back'. Hope that helps.
     
    Last edited: Oct 21, 2020
  2. bump - if this is not possible do let me know. thanks!
     
  3. I do believe it is possible, it might just be a little tricky.

    Unfortunately, that is the easy part. The part that might be hard is getting all the TNT that is supposed to be launched after the first TNT explodes, and emulate the normal velocity effect.

    I am thinking this might be achieved by listening to the ExplosionPrimeEvent, getting the explosion radius, checking if any PrimedTNT entity is inside that radius, get those TNT, set their velocity to move away from the TNT that exploded, and then multiply the velocity by the speed in the config.

    It might not give the same result as it normally would, and it might not even work, but i think it is at least worth a try.
     
  4. Offline

    JavaNoob

    Are Primed TNT blocks not considered blocks anymore?
     
  5. They have always been entities. They are blocks until they are primed.
     
  6. Offline

    JavaNoob

    So would it work if when you prime the original tnt, you get a radius of blocks around it? Because for tnt cannons to work, the tnt that you are launching would need to be lit a bit after the original one. Then you could register a block around it is a TNT block, then on the explosion event, get those blocks, and launch it away based upon the face direction? I don't know much, but I am trying to figure things out because I think this is the best way to learn.
    I don't know if this would work, but something like this maybe?

    Code:
    @Override
    
        public void onEnable(){
    
           
    
            Bukkit.getPluginManager().registerEvents(this, this);
    
           
    
        }
    
       
    
        public static Set<Block> sphereAround(Location location, int radius){
    
            Set<Block> sphere = new HashSet<Block>();
    
            Block center = location.getBlock();
    
            for(int x = -radius; x <= radius; x++) {
    
                for(int y = -radius; y <= radius; y++) {
    
                    for(int z = -radius; z <= radius; z++) {
    
                        Block b = center.getRelative(x, y, z);
    
                        if(center.getLocation().distance(b.getLocation()) <= radius) {
    
                            sphere.add(b);
    
                        }
    
                    }
    
                }         
    
            }
    
            return sphere;
    
        }
    
    
    
        ArrayList<Block> tntBlock = newArrayList<Block>();
    
        Entity tntPrimed = null;
    
        @EventHandler
    
        public void onPrime(ExplosionPrimeEvent event){
    
            Entity ent = (Entity) event.getEntity();
    
            if (event.getEntityType().equals(EntityType.PRIMED_TNT)){
    
                Location loc = (Location) ent.getLocation();
    
                tntPrimed = ent;
    
                for (Block bl : sphereAround(loc, (int) event.getRadius())){
    
                    if(bl.getType().equals(Material.TNT)){
    
                        tntBlock.add(bl);
    
                    }
    
                }
    
            }
    
        }
    
       
    
        @EventHandler
    
        public void onExplosion(EntityExplodeEvent event){
    
            if(event.getEntity().equals(tntPrimed)){
    
                for(Block bl : tntBlock){
    
                   
    
                }
    
            }
    
        }
    
    And then like get the relative location from each previous tnt block to the original primed tnt and set the velocity away from it or something. I'm not that good of a coder yet.
     
    Last edited: Oct 29, 2020
    Pvprod likes this.
  7. Offline

    w0lves

    Which type of cannons are u doing?

    Because if u are talking about faction cannons.. a plugin like that will mess up all cannons timings and it will be useless.
     
    Pvprod and bitfreeze.dev like this.
  8. Offline

    bitfreeze.dev

    Pvprod, check this out:

    https://www.spigotmc.org/resources/cannonboost.85323/

    Please let me know if that works for you.
     
  9. Tell you what i think your right on that. Never mind! I think il play see if i can further improve the tnt cannons i have setup for players.
     
  10. You want to get the blocks around it when it explodes, not when it is primed.

    1. I would use World#getEntitiesByClass(Class<T extends Entity>) to get all primed tnt in the world.
    2. You are getting the TNT block, not the PrimedTNT entity. TNT cannons work by pushing the PrimedTNT entity, not the TNT block.
    3. I would use Location#distanceSquared(Location) instead of Location#distance(Location), it has better performance.
    4. I do not think you need any collections or fields for this plugin, at least not this part of it.

    I do not play factions, so i am not sure about what kind of cannons you are talking about. Could you either elaborate, or link to a source i could look at?
     
  11. Offline

    w0lves

    @KarimAKL something like that

    Show Spoiler


    This cannons use tnt mechanics of minecraft 1.7 i think, so at least he doesn't have a specific jar for cannons they won't work on later versions... however, if he's trying to replicate something like that, this cannons have specific gameticks for every booster, etc. So increasing the tnt velocity will just mess up them.

    Idk if it's possible on 1.12, but on factions servers u can do easily a cannon that reach 6000 blocks away, or cannons that shoot every 0.5 seconds
     
  12. Offline

    JavaNoob

    Interesting. This shows how bad I am at thinking I guess.

    Do you no longer want this? Or do you want me to continue working on trying to make something work?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  13. Offline

    bitfreeze.dev

    Perhaps my post has passed unnoticed, due to the moderation delay. I've already developed the plugin, in two versions. One is compatible with 1.12.x, the other is for 1.13 and above.
     
    Pvprod likes this.
  14. Apoligies! I someone missed it with all the messages! Thanks a lot! I will give it a test
     
  15. Thought i replied a while ago. Must have been an issue with my phone. Ok so the only issue is that it changes how tnt cannons function as the tnt seems to move quicker when sliding down water for instance. Is there a way of increasing the speed of which ignited tnt moves upon being exploded? So im guessing increasing the intensity of which blocks are thrown upon being exploded.
     
  16. Offline

    bitfreeze.dev

    Mmm that is unlikely to happen, since that is exactly what it does: listen to the event when the TNT explodes, speeding up certain entities that get caught by the blast.
    Until the very explosions happen, my plugin does nothing but to wait.
     

Share This Page