Topic category: Advanced modding
I have made a rideable entity, but need to be able to turn ONLY the player's head with the mouse (like vanilla boats, which use "A" and "D" to turn the boat, but allow the player head to turn freely, while the body changes direction with the boat).
I can make the entity not rotate with the player's direction by changing this bit (the only part related to rotation) of the entity's auto-generated code by MCreator (the bold is what I changed):
@Override
public void travel(Vec3d dir) {
Entity entity = this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
if (this.isBeingRidden()) {
this.rotationYaw = entity.rotationYaw;
this.prevRotationYaw = this.rotationYaw;
this.rotationPitch = entity.rotationPitch * 0.5F;
this.setRotation(this.rotationYaw, this.rotationPitch);
this.jumpMovementFactor = this.getAIMoveSpeed() * 0.15F;
this.renderYawOffset = entity.rotationYaw;
this.rotationYawHead = entity.rotationYaw;
this.stepHeight = 1.0F;
to:
@Override
public void travel(Vec3d dir) {
Entity entity = this.getPassengers().isEmpty() ? null : (Entity) this.getPassengers().get(0);
if (this.isBeingRidden()) {
this.rotationYaw = this.rotationYaw;
this.prevRotationYaw = this.rotationYaw;
this.rotationPitch = this.rotationPitch * 0.5F;
this.setRotation(this.rotationYaw, this.rotationPitch);
this.jumpMovementFactor = this.getAIMoveSpeed() * 0.15F;
this.renderYawOffset = this.rotationYaw;
this.rotationYawHead = this.rotationYaw;
this.stepHeight = 1.0F;
Which simply stops syncing the entity direction to the player direction. The problem, is that the player can rotate their entire body 360 degrees with the mouse, not just their head. This odd spinning ability can be prevented by setting the new:
this.rotationYaw = this.rotationYaw;
to:
entity.rotationYaw = this.rotationYaw;
Reversing the intent of the original code by syncing the player direction to the entity direction. The problem now, is that this applies to the body AND head, not just the body (though I can still look up and down, as the pitch is unaffected).
Does anyone know how to set only the player's body to the entity's rotation, without locking the head in place?
P.S. Only the "Rideable" and "forward movement control" checkboxes are enabled.
There is a strafe control option in mcreators is entity rideable area. This is what you are looking for.
Good suggestion, that does help the head to turn independent of the body, however once the player turns far enough the body begins turning with the head (just like when standing still normally). This also allows strafing, which will not work in this instance.
I discovered that only an entity's body can be controlled with the "renderYawOffset" variable according to this website (http://greyminecraftcoder.blogspot.com/2015/07/entity-rotations-and-animation.html), however I can't reverse the code and say:
entity.renderYawOffset = this.rotationYaw;
It doesn't recognize the "renderYawOffset" if it is prefixed by "entity". I'm guessing that the player's "renderYawOffset" is not able to be modified from another entity, however I don't know how to combat this if it is the problem.
Did you try looking at the boat class?
I haven't figured out how. Do you know where I'd find it?
There is a button left of the workspace tab. It is a pointed arrow. Click it and the source code will be revealed. Go to the external libraries and go to forge -> net -> minecraft.
where is that>>
Live does not return when clicking A, D
I'm not into java, but the solution could be maybe setting the players rotation to the rided entity rotation + some value once the player rotates too much. The events should then go like this:
If player body is about to start turning to the right:
Set player rotation to entity rotation + maximum right rotation angle allowed (not to turn the body) - safety margin.
Else if player body is about to start turning to the left:
Set player rotation to entity rotation + maximum left rotation angle allowed (not to turn the body) - safety margin
Else:
Don't change the player's rotation.