这种能力在这里完美无缺,只要受害者站在石板或任何其他类型的石板上,就会被石板取代。这只发生在平板上,例如砂岩阶梯将被砂岩阶梯取代。
@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型和1型2没有分配给他们的子类型(这是奇怪的,因为正如我所说,楼梯不受此影响) 如何让它为类型1和类型分配子类型? 2?
答案 0 :(得分:1)
您还需要保存和设置块数据。 Block类包含getData()和setData()方法,它们包含一个指定要使用的块的确切类型的字节。如果你要查看一个ID list的我的世界地块,你会看到一些项目的ID,后面跟一个冒号和另一个数字:
1:1
1:2
代表两种不同类型的块。因此,当您从块中获取材料时,您还需要获取字节数据:
byte data = block.getData();
然后当您将另一个区块设置为此类型时,您需要设置其数据:
block2.setData(data);