minecraft - Bukkit EntityExplode physics and regeneration of blocks -


i having issue code when tnt or creeper explodes, blocks fly everywhere when blocks have landed should regenerate dosen't. has conclusion?

here code:

      @eventhandler       void onexplode1(entityexplodeevent event) {      for(block block : event.blocklist()) {          if(block.gettype() != material.tnt) {             float x = -0.4f + (float) (math.random() * 0.9d);             float y = -1.2f + (float) (math.random() * 1.9d);             float z = -0.9f + (float) (math.random() * 1.4d);              fallingblock falling = block.getworld().spawnfallingblock(block.getlocation(), block.gettype(), block.getdata());             falling.setvelocity(new vector(x, y, z));             falling.setdropitem(true);              block.settype(material.air);          }          if(block.gettype() != material.air) {              final blockstate state = block.getstate();              int delay;              if(block.gettype().hasgravity()) {                  delay = 80;              } else {                  delay = 80 + (int)(math.random()*60);              }              // set block air no blocks drop             block.settype(material.air);              // regenerate blocks in random order             bukkit.getserver().getscheduler().schedulesyncdelayedtask(this, new runnable() {                  public void run() {                      state.update(true, false);                  }              }, delay);          }      }  } } 

i think have store entitys created , locations... here example code... doesn't have work others it's try.

package me.mcplayhd.testt;  import java.util.hashmap; import java.util.iterator;  import org.bukkit.location; import org.bukkit.material; import org.bukkit.block.block; import org.bukkit.entity.fallingblock; import org.bukkit.event.eventhandler; import org.bukkit.event.listener; import org.bukkit.event.entity.entitychangeblockevent; import org.bukkit.event.entity.entitydamageevent; import org.bukkit.event.entity.entitydeathevent; import org.bukkit.event.entity.entityexplodeevent; import org.bukkit.plugin.java.javaplugin; import org.bukkit.util.vector;  public class explodeblocks extends javaplugin implements listener {      public void onenable() {         getserver().getpluginmanager().registerevents(this, this);     }      hashmap<fallingblock, location> blocks = new hashmap<fallingblock, location>();      @suppresswarnings("deprecation")     @eventhandler     void onentityexplode(entityexplodeevent e) {         iterator<block> bi = e.blocklist().iterator();         while(bi.hasnext()) {             block b = bi.next();             if(b.gettype() != material.tnt) {                 bi.remove();                  material m = b.gettype();                 byte d = b.getdata();                  b.settype(material.air);                  float x = -0.4f + (float) (math.random() * 0.9d);                 float y = -1.2f + (float) (math.random() * 1.9d);                 float z = -0.9f + (float) (math.random() * 1.4d);                  fallingblock falling = b.getworld().spawnfallingblock(b.getlocation(), m, d);                 falling.setvelocity(new vector(x, y, z));                 falling.setdropitem(false);                  blocks.put(falling, b.getlocation());             }         }     }      @eventhandler     public void onentitydamage(entitydamageevent e) {         if(e.getentity() instanceof fallingblock) {             fallingblock fb = (fallingblock) e.getentity();             if(blocks.containskey(fb)) {                 e.setcancelled(true);             }         }     }      @suppresswarnings("deprecation")     @eventhandler     public void oneneitydeath(entitydeathevent e) {         if(e.getentity() instanceof fallingblock) {             fallingblock fb = (fallingblock) e.getentity();             if(blocks.containskey(fb)) {                 location loc = blocks.get(fb);                 loc.getblock().settype(fb.getmaterial());                 loc.getblock().setdata(fb.getblockdata());                 blocks.remove(fb);                 fb.remove();             }         }     }      @suppresswarnings("deprecation")     @eventhandler     public void onentitychangeblock(entitychangeblockevent e) {         if(e.getentity() instanceof fallingblock) {             fallingblock fb = (fallingblock) e.getentity();             if(blocks.containskey(fb)) {                 e.setcancelled(true);                 location loc = blocks.get(fb);                 loc.getblock().settype(fb.getmaterial());                 loc.getblock().setdata(fb.getblockdata());                 blocks.remove(fb);                 fb.remove();             }         }     }  } 

the problem doesn't work 100% of blocks restored. others don't know, think find cause...

sry if doesn't @ all


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -