试图在Minecraft中制作匕首(带有月食),使您在右键单击时可以传送

问题描述 投票:1回答:1

我已经通过eclipse为Minecraft 1.12.2制作了mod。我添加了一个匕首,当右键单击时,应该将其进一步传送五个格。我唯一想到的方法是使用onItemRightClick方法在item类中,并尝试使用playerIn.moveForward,但我不知道如何使用它,并尝试使用moveRelative,但我不知道如何要么使用它。这是当前代码:

 `public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityLivingBase playerIn, EnumHand 
 handIn)
 {
    Vec3d forward = playerIn.getForward();
    Object move = playerIn.moveRelative(0.0F, 0.0F, 3.0F, 0.0F);
    return //I don't know what to add here yet
 }`

有人有什么想法吗?

java eclipse minecraft minecraft-forge
1个回答
0
投票

我通过在线查找脚本的不同组件找到了答案,这就是我最终得到的结果:

@Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) 
    {
        player.getCooldownTracker().setCooldown(this, 20); //Sets a cooldown of one second
        {
            Vec3d look = player.getLookVec(); //Lets you check the coordinates the player is facing
            player.setVelocity(look.x, look.y, look.z); //setting the player's velocity towards the direction they are looking at
            return super.onItemRightClick(worldIn, player, handIn); //A return method, since this method isn't a void
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.