Regenerating explosions with all data

Discussion in 'Plugin Development' started by bartboy8, Jul 25, 2014.

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

    bartboy8

    Hey, I've been searching the bukkit forums for hours, and trying to experiment with different things.. I can't seem to figure out how to restore an explosion back to its prior form. I want to slowly fill in the area with the blocks again, I have that part working.. But since BlockState doesn't seem to store inventory data and such, I can't seem to figure out a way. I tried setting the blocks to air for the clients via packets.. then updating them after a few ticks.. But that causes the player to not be able to enter the block spaces that were set to air (with the packet). Any, and all help would be greatly appreciated. Thanks in advance :)

    Edit: I'd like to be able to do have the area regenerate to its prior form completely. (Like flowers inside of flower pots, text on signs, etc.)
     
  2. Offline

    fireblast709

    Can you show the code you tried here, because the blockstate should in fact hold the full inventory data
     
  3. Offline

    bartboy8


    Code:
    @SuppressWarnings("deprecation")
        @EventHandler
        public void onExplode(EntityExplodeEvent event)
        {
            event.setYield(0.0F);
            final LinkedList<BlockState> data_map = new LinkedList<BlockState>();
            List<Block> list = new ArrayList<Block>(event.blockList());
            while(!list.isEmpty())
            {
                Block b = getBestBlock(list);
                b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType().getId() | (b.getData() << 0x10));
                BlockData bd = new BlockData(b.getType(), b.getData());
                data_map.add(b.getState());
                list.remove(b);
                b.getDrops().clear();
            }
            new BukkitRunnable()
            {
                public void run()
                {
                    regenBlocks(data_map);
                }
            }.runTaskLater(MinigameManager.getInstance(), (new Random().nextInt(6)+5)*20);
        }
       
        public void regenBlocks(final LinkedList<BlockState> blocks)
        {
            new BukkitRunnable()
            {
                Iterator<BlockState> clone = blocks.iterator();
                int wait = 0;
                @SuppressWarnings("deprecation")
                public void run()
                {
                    if(wait > 0)
                    {
                        wait -= 1;
                        return;
                    }
                    if(!clone.hasNext())
                    {
                        this.cancel();
                        return;
                    }
                   
                    BlockState bs = clone.next();
                    bs.getWorld().playEffect(bs.getLocation(), Effect.STEP_SOUND, bs.getType().getId() | (bs.getData().getData() << 0x10));
                    bs.update(true);
                    wait = 1;
                }
            }.runTaskTimer(MinigameManager.getInstance(), 1L, 1L);
        }
       
        public Block getBestBlock(List<Block> blocks)
        {
            Block b = null;
            Collections.shuffle(blocks);
            for(Block block : blocks)
            {
                if(b == null)
                    b = block;
                if(block.getY() < b.getY())
                    b = block;
            }
            return b;
        }
     
  4. Offline

    fireblast709

    bartboy8 debug the BlockStates (especially container contents)
     
  5. Offline

    bartboy8

    I have.. I'm sure this is a bug with bukkit. I've seen posts about this multiple times but I just wanted to verify I'm not doing something wrong. There's definitely another solution.. I just would prefer for it to not be as difficult as I think it will be...
     
Thread Status:
Not open for further replies.

Share This Page