旋转 Minecraft 玩家 180 度,在 1.12.2 版本的 Forge 中。

huangapple go评论90阅读模式
英文:

Rotating a Minecraft player 180 degrees in 1.12.2 forge

问题

player.getCooldownTracker().setCooldown(this, 23);
{
    Vec3d look = player.getLookVec();
    BlockPos pos = player.getPosition();
    float rot = (float)(2 * (look.x));
    double goToX = pos.getX() + look.x * 0;
    double goToY = pos.getY() + look.y * 0;
    double goToZ = pos.getZ() + look.z * 0;
    if(player.isAirBorne || player.onGround)
    {
        System.out.println(rot);
        player.setPositionAndRotation(goToX, goToY, goToZ, rot, rot);
        System.out.println(rot);
    }
    return super.onItemRightClick(worldIn, player, handIn);
}
英文:

So I was making a dagger for my Minecraft 1.12.2 mod. This dagger is supposed to teleport you 3 block towards where you're facing and turn you around, basically so you can teleport behind an enemy and attack them. I previously settled with just setting the player's velocity toward where they're looking to a certain amount, but now I'm trying to make the original design work. The thing is, I can't figure out how to rotate the player. Right now when instead of turning you around it always rotates you to Positive Z, which I'm assuming is the default player rotation. Anybody know a fix? This is my current code for the dagger:

		{
			Vec3d look = player.getLookVec();
			BlockPos pos = player.getPosition();
			float rot = (float)(2 * (look.x));
			double goToX = pos.getX() + look.x * 0;
			double goToY = pos.getY() + look.y * 0;
			double goToZ = pos.getZ() + look.z * 0;
			if(player.isAirBorne || player.onGround)
			{
				System.out.println(rot);
				player.setPositionAndRotation(goToX, goToY, goToZ, rot, rot);
				System.out.println(rot);
			}
			return super.onItemRightClick(worldIn, player, handIn);

Thanks in advance!

答案1

得分: 1

player.setPositionAndRotation(goToX, goToY, goToZ, player.getPitchYaw().y + 180F, player.getPitchYaw().x);
英文:

You just need to add 180 to their yaw:

player.setPositionAndRotation(goToX, goToY, goToZ, player.getPitchYaw().y + 180F, player.getPitchYaw().x);

huangapple
  • 本文由 发表于 2020年9月24日 21:11:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/64047218.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定