Explosion Physics (I have the Code)

Discussion in 'Archived: Plugin Requests' started by GoldenNachos, Feb 8, 2013.

  1. Offline

    GoldenNachos

    Ok so I have the code for said plugin, I just need someone to add it into a 1.4.7 bukkit jar file.

    Code:
    package explosionphysics;
     
    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.FallingBlock;
    import org.bukkit.event.Event;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.util.Vector;
     
    /**
    *
    * @author GoldenNachos
    */
    public class ExplosionPhysics extends JavaPlugin implements Listener{
        public ArrayList<Material> disallowedBlocks = new ArrayList<Material>();
        @Override
        public void onEnable(){
            getServer().getPluginManager().registerEvents(new ExplosionPhysics(), this);
            disallowedBlocks.clear();
            disallowedBlocks.add(Material.TNT);
            disallowedBlocks.add(Material.PISTON_BASE);
            disallowedBlocks.add(Material.PISTON_EXTENSION);
            disallowedBlocks.add(Material.PISTON_MOVING_PIECE);
            disallowedBlocks.add(Material.PISTON_STICKY_BASE);
        }
     
        @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockExplode(org.bukkit.event.entity.EntityExplodeEvent e){
            if (e.isCancelled()){return;}
            if (e.blockList().isEmpty()){return;}
            e.setYield(0F);
            double x = 0;
            double y = 0;
            double z = 0;
            Location eLoc = e.getLocation();
            World w = eLoc.getWorld();
            for (int i = 0; i < e.blockList().size();i++){
                Block b = e.blockList().get(i);
                Location bLoc =b.getLocation();
                if (disallowedBlocks.contains(b.getType())){continue;}
                x = bLoc.getX() - eLoc.getX();
                y = bLoc.getY() - eLoc.getY() + .5;
                z = bLoc.getZ() - eLoc.getZ();
                FallingBlock fb = w.spawnFallingBlock(bLoc, b.getType(), (byte)b.getData());
                fb.setDropItem(false);
                fb.setVelocity(new Vector(x,y,z));
            }
           
        }
    }
    Never mind just ignore that, or if you can please change it so that the blocks shoot off in different directions please and then settle down in a normal position I would be very greatful... I got that code to work somewhat but they never actually shot off in different directions with the vectors.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    filbert66

    Nacho, what is it you are trying to do? AntiCreeper already allows for blacklists, configurable list of blocks that should be impervious to different types of explosions. And MC already applies physics to entities and dropped blocks.

    So is what is left that you want the exploded blocks to not drop where they were, but get pushed in a direction away from the explosion center?
     
  3. Offline

    Hoolean

    I got this to work a while ago but never released it :)

    Do you want me to release it with my code, with you as an author on the project :D?
     
  4. Offline

    filbert66

    I'd be happy to add it as an option to AntiCreeper.
     
  5. Offline

    Hoolean

    Attached Files:

  6. Offline

    filbert66

    FWIW, I've added a blockphysics option to AntiCreeper. It throws ItemStacks, rather than blocks. I didn't like blocks finding new homes. Haven't yet randomized it so everything is evenly distributed from explosion center.
     
    MrBluebear3 likes this.

Share This Page