英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论