2015-07-21 14 views
0

這種能力在這裏完美運作,除非受害者站立在石板或任何其他類型的地方,否則它們會被石板取代。這隻發生在平板上,例如砂岩樓梯將被砂岩樓梯取代後才能使用。我該如何阻止這種用石板取代特殊板的能力?

@EventHandler 
public void onPlayerInteractBlockEarthSpike(PlayerInteractEvent event) { 
    final Player player = event.getPlayer(); 
    int selected = player.getInventory().getHeldItemSlot(); 
    if (selected == 5){ 
     if (player.getFoodLevel() > 9){ 
      Block target = (Block) player.getTargetBlock((Set<Material>) null, 15).getLocation().getBlock(); 
      List<Entity> victims = (List<Entity>) target.getWorld().getNearbyEntities(target.getLocation(), 2, 2, 2); 
      player.getWorld().playEffect(target.getLocation().clone().add(0,1,0), Effect.SMOKE, 10); 
      for (Entity victim : victims){ 
       if (victim instanceof LivingEntity){ 
        victim.setVelocity(new Vector(0,1,0)); 
        ((LivingEntity) victim).damage(2,player); 
        victim.setVelocity(new Vector(0,1,0)); 
        final Block block1 = victim.getLocation().getBlock(); 
        final Block block2 = victim.getLocation().clone().add(0,1,0).getBlock(); 
        final Material type1 = block1.getType(); 
        final Material type2 = block2.getType(); 
       Bukkit.getScheduler().runTaskLater(MagictgCraft.that, new Runnable(){ 
        @Override 
        public void run(){ 
         block1.setType(Material.STONE); 
         player.getWorld().playSound(player.getLocation(), Sound.EXPLODE, 10, 5); 
         int count = 0; 
         while (count < 20){ 
          player.getWorld().playEffect(block1.getLocation().clone().add(0.5,0.5,0.5), Effect.LAVA_POP, 10); 
          count = count + 1; 
         } 
        } 
       },3); 
       Bukkit.getScheduler().runTaskLater(MagictgCraft.that, new Runnable(){ 
        @Override 
        public void run() { 
         block2.setType(Material.STONE); 
         player.getWorld().playSound(player.getLocation(), Sound.EXPLODE, 10, 5); 
         int count = 0; 
         while (count < 10){ 
          count = count + 1; 
          player.getWorld().playEffect(block1.getLocation().clone().add(0.5,0.5,0.5), Effect.LAVA_POP, 10); 
         } 
        } 
       },5); 
       Bukkit.getScheduler().runTaskLater(MagictgCraft.that, new Runnable(){ 
        @Override 
        public void run(){ 
         block2.setType(type2); 
        } 
       },8); 
       Bukkit.getScheduler().runTaskLater(MagictgCraft.that, new Runnable(){ 
        @Override 
        public void run(){ 
         block1.setType(type1); 
        } 
       },10); 
      } 
     } 
    } 
} 

我認爲它是因爲1型& 2沒有得到分配給他們的亞型(這是奇怪的,因爲正如我所說的,樓梯不受此影響) 如何使它分配的亞型類型1 & 2?

回答

1

您還需要保存並設置塊數據。 Block類包含方法getData()和setData(),它們包含一個指定要使用的塊的確切類型的字節。如果你看一下我的世界塊的ID list你會看到一些項目都遵循一個冒號和另一個號碼,他們的ID:

1:1 
1:2 

代表兩種不同類型的塊。所以,當你從塊得到的材料,你也想獲得字節數據:

byte data = block.getData(); 

然後當你在另一個塊設置爲這種類型的你需要設置它的數據:

block2.setData(data); 
相關問題