0

私は1.7.10でこれを持っていましたが、エラーはありませんでした.1.8でworld.setblockを削除するまで

@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 でブロックを設定するにはどうすればよいですか。また、ブロックが邪魔になっている場合は、パックされた氷に置き換えます。また、左クリックがクリックされるたびにサウンドを再生するにはどうすればよいですか

4

1 に答える 1

2

1.8 では、setblock の代わりに BlockState を使用します。

   // 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)
{
}
于 2015-07-03T06:51:10.893 に答える