尝试在 minecraft 中制作一把匕首(使用 eclipse),右键单击时让你传送
Trying to make A dagger in minecraft (with eclipse) that makes you teleport when right clicking
我一直在通过 Eclipse 为 Minecraft 1.12.2 制作 mod。我添加了一把匕首,当右键单击时应该将你传送到更远的五个街区。我能想到的唯一方法是在项目 class 中使用 onItemRightClick 方法,并尝试使用 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
}`
有没有人有什么想法?
我通过在线查找脚本的不同组件找到了答案,这就是我最终得到的:
@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
}
}
不太确定您是否还需要它,但我是这样做的。
if (worldIn.getBlockState(pos).allowsMovement(worldIn, pos, PathType.LAND)) {
playerIn.getCooldownTracker().setCooldown(stack.getItem(), 30);
playerIn.setPosition(playerIn.getPosX() + x * dist, playerIn.getPosY() + y * dist + 1, playerIn.getPosZ() + z * dist);
}
有点像你想要的一样!我将你传送到你正在看的方向。您可能想为您的项目设置最大射程!
我一直在通过 Eclipse 为 Minecraft 1.12.2 制作 mod。我添加了一把匕首,当右键单击时应该将你传送到更远的五个街区。我能想到的唯一方法是在项目 class 中使用 onItemRightClick 方法,并尝试使用 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
}`
有没有人有什么想法?
我通过在线查找脚本的不同组件找到了答案,这就是我最终得到的:
@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
}
}
不太确定您是否还需要它,但我是这样做的。
if (worldIn.getBlockState(pos).allowsMovement(worldIn, pos, PathType.LAND)) {
playerIn.getCooldownTracker().setCooldown(stack.getItem(), 30);
playerIn.setPosition(playerIn.getPosX() + x * dist, playerIn.getPosY() + y * dist + 1, playerIn.getPosZ() + z * dist);
}
有点像你想要的一样!我将你传送到你正在看的方向。您可能想为您的项目设置最大射程!