2015-07-02 39 views
0

我在1.7.10过这种去除world.setblock,没有任何错误,直到他们1.8取出world.setblock的Minecraft 1.8

@Override 
public ItemStack onItemRightClick(ItemStack itemStack, World world, 
            EntityPlayer entityPlayer) { 
    if(entityPlayer.capabilities.isCreativeMode||entityPlayer.inventory.consumeInventoryItem(Items.sugar)) 
    { 
     //play sound stuff com.example.examplemod.SoundHandler.onEntityPlay("fizz", Event.player.worldObj, Event.player, 1, 1); 
     if (!world.isClient) 
     { 
      Vec3 look = entityPlayer.getLookVec(); 
      world.setBlock((int) (entityPlayer.posX + look.xCoord * 5), 
        (int) (entityPlayer.posY + look.yCoord * 5), 
        (int) (entityPlayer.posZ + look.zCoord * 5), 
        Block.getBlockById(79)); 

     } 
    } 
    return itemStack; 
} 

现在,我怎么在1.8的方向设置的块玩家正在面对,如果一个街区正在用冰块取代它。每次点击左键点击时我该如何播放声音

回答

2

在1.8中,您使用BlockState而不是setblock。

// Get the reference to the block we want to place 
    Block blk = Blocks.furnace; 
    // Make a position. 
    BlockPos pos0 = new BlockPos(pos.getX()+1, (pos.getY()+1) , pos.getZ()); 
    // Get the default state(basically metadata 0) 
    IBlockState state0=blk.getDefaultState(); 
    // set the block 
    world.setBlockState(pos0, state0); 

我建议你做一些阅读块状态。

您应该为您的声音播放收听PlayerInteractEvent。有几种播放声音的方式,所以你只需要谷歌你想使用的方法。

@SubscribeEvent 
public void playerdidsomething(PlayerInteractEvent event) 
{ 
}