use of org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ValkyrienUtils method getMountedShipAndPos.
public EntityShipMountData getMountedShipAndPos(Entity entity) {
Entity ridingEntity = entity.ridingEntity;
if (ridingEntity instanceof EntityMountable) {
EntityMountable mountable = (EntityMountable) ridingEntity;
Optional<PhysicsObject> mountedShip = mountable.getMountedShip();
if (mountedShip.isPresent()) {
return new EntityShipMountData(mountedShip.get(), mountable.getMountPos());
}
}
return new EntityShipMountData();
}
use of org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntity method getLook.
/**
* This is easier to have as an overwrite because there's less laggy hackery to be done then :P
*
* @author DaPorkchop_
*/
@Overwrite
public Vec3d getLook(float partialTicks) {
// BEGIN VANILLA CODE
Vec3d original;
if (partialTicks == 1.0F) {
original = this.getVectorForRotation(this.rotationPitch, this.rotationYaw);
} else {
float f = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * partialTicks;
float f1 = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * partialTicks;
original = this.getVectorForRotation(f, f1);
}
// END VANILLA CODE
EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(Entity.class.cast(this));
if (mountData.isMounted()) {
return mountData.getMountedShip().getShipTransformationManager().getRenderTransform().rotate(original, TransformType.SUBSPACE_TO_GLOBAL);
} else {
return original;
}
}
use of org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntity method getPositionEyesInject.
@Inject(method = "getPositionEyes(F)Lnet/minecraft/util/math/Vec3d;", at = @At("HEAD"), cancellable = true)
private void getPositionEyesInject(float partialTicks, CallbackInfoReturnable<Vec3d> callbackInfo) {
EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(Entity.class.cast(this));
if (mountData.isMounted()) {
Vector3d playerPosition = JOML.convert(mountData.getMountPos());
mountData.getMountedShip().getShipTransformationManager().getRenderTransform().transformPosition(playerPosition, TransformType.SUBSPACE_TO_GLOBAL);
Vector3d playerEyes = new Vector3d(0, this.getEyeHeight(), 0);
// Remove the original position added for the player's eyes
// RotationMatrices.doRotationOnly(wrapper.wrapping.coordTransform.lToWTransform,
// playerEyes);
mountData.getMountedShip().getShipTransformationManager().getCurrentTickTransform().transformDirection(playerEyes, TransformType.SUBSPACE_TO_GLOBAL);
// Add the new rotate player eyes to the position
playerPosition.add(playerEyes);
callbackInfo.setReturnValue(JOML.toMinecraft(playerPosition));
// return the value, as opposed to the default one
callbackInfo.cancel();
}
}
use of org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinRenderManager method preDoRenderEntity.
@Inject(method = "renderEntity", at = @At("HEAD"), cancellable = true)
public void preDoRenderEntity(Entity entityIn, double x, double y, double z, float yaw, float partialTicks, boolean p_188391_10_, CallbackInfo callbackInfo) {
if (!hasChanged) {
EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(entityIn);
if (mountData.isMounted()) {
double oldPosX = entityIn.posX;
double oldPosY = entityIn.posY;
double oldPosZ = entityIn.posZ;
double oldLastPosX = entityIn.lastTickPosX;
double oldLastPosY = entityIn.lastTickPosY;
double oldLastPosZ = entityIn.lastTickPosZ;
Vec3d mountPos = mountData.getMountPos();
mountData.getMountedShip().getShipRenderer().applyRenderTransform(partialTicks);
if (mountPos != null) {
Vector3d localPosition = JOML.convert(mountPos);
localPosition.x -= mountData.getMountedShip().getShipRenderer().offsetPos.getX();
localPosition.y -= mountData.getMountedShip().getShipRenderer().offsetPos.getY();
localPosition.z -= mountData.getMountedShip().getShipRenderer().offsetPos.getZ();
x = entityIn.posX = entityIn.lastTickPosX = localPosition.x;
y = entityIn.posY = entityIn.lastTickPosY = localPosition.y;
z = entityIn.posZ = entityIn.lastTickPosZ = localPosition.z;
}
hasChanged = true;
this.renderEntity(entityIn, x, y, z, yaw, partialTicks, p_188391_10_);
hasChanged = false;
if (mountPos != null) {
mountData.getMountedShip().getShipRenderer().applyInverseTransform(partialTicks);
}
entityIn.posX = oldPosX;
entityIn.posY = oldPosY;
entityIn.posZ = oldPosZ;
entityIn.lastTickPosX = oldLastPosX;
entityIn.lastTickPosY = oldLastPosY;
entityIn.lastTickPosZ = oldLastPosZ;
callbackInfo.cancel();
}
}
}
use of org.valkyrienskies.mod.common.ships.entity_interaction.EntityShipMountData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntityPlayerSP method getLook.
/**
* @author Tri0de
* @reason Fixes player ray tracing when they're on a ship thats rotating.
*/
@Overwrite
public Vec3d getLook(final float partialTicks) {
final Vec3d playerLook;
if (partialTicks == 1.0F) {
playerLook = getVectorForRotationInMc_1_12(player.rotationPitch, player.rotationYawHead);
} else {
final float playerPitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * partialTicks;
final float playerYaw = player.prevRotationYawHead + (player.rotationYawHead - player.prevRotationYawHead) * partialTicks;
playerLook = this.getVectorForRotationInMc_1_12(playerPitch, playerYaw);
}
// If the player is mounted to a ship then we must rotate the player look vector.
final EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(player);
if (mountData.isMounted()) {
return mountData.getMountedShip().getShipTransformationManager().getRenderTransform().rotate(playerLook, TransformType.SUBSPACE_TO_GLOBAL);
} else {
return playerLook;
}
}
Aggregations