这种能力在这里非常有效,除了受害者只要站在立石板上或其他任何形式时,他们都会被石板代替。这仅在平板上发生,例如砂岩楼梯将被该能力替换为砂岩楼梯。
@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分配子类型?
最佳答案
您还需要保存并设置块数据。 Block类包含方法getData()和setData(),这些方法包含指定要使用的确切块类型的字节。如果要查看Minecraft区块的ID list,您会看到一些项目的ID,其后跟一个冒号和另一个数字:
1:1
1:2
代表两种不同类型的块。因此,当您从块中获取材料时,您还需要获取字节数据:
byte data = block.getData();
然后,当您将另一个块设置为这种类型时,需要设置其数据:
block2.setData(data);
关于java - 我如何停止用石板代替特殊板的能力?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31546169/