0

I had this in 1.7.10, with no errors Until in 1.8 they removed the 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;
}

Now, how do i set a block in 1.8 in the direction the player is facing and if a block is in the way replace it with packed ice. Also how do i play a sound each time the left click is clicked

4

1 回答 1

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