use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinEntityRenderer method orientCamera.
@Inject(method = "orientCamera", at = @At("HEAD"), cancellable = true)
private void orientCamera(float partialTicks, CallbackInfo ci) {
EntityShipMountData mountData = ValkyrienUtils.getMountedShipAndPos(mc.getRenderViewEntity());
if (mountData.getMountedShip() == null) {
// Do nothing. We don't want to mess with camera code unless we have to.
return;
} else {
// Take over the camera orientation entirely. Don't let anything else touch it.
ci.cancel();
}
Entity entity = this.mc.getRenderViewEntity();
Vector3d eyeVector = new Vector3d(0, entity.getEyeHeight(), 0);
if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
eyeVector.y += .7D;
}
double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks;
double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks;
double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks;
// Probably overkill, but this should 100% fix the crash in issue #78
if (mountData.isMounted() && mountData.getMountedShip().getShipRenderer().offsetPos != null) {
final ShipTransform renderTransform = mountData.getMountedShip().getShipTransformationManager().getRenderTransform();
renderTransform.transformDirection(eyeVector, TransformType.SUBSPACE_TO_GLOBAL);
Vector3d playerPosition = JOML.convert(mountData.getMountPos());
renderTransform.transformPosition(playerPosition, TransformType.SUBSPACE_TO_GLOBAL);
d0 = playerPosition.x;
d1 = playerPosition.y;
d2 = playerPosition.z;
}
d0 += eyeVector.x;
d1 += eyeVector.y;
d2 += eyeVector.z;
if (entity instanceof EntityLivingBase && ((EntityLivingBase) entity).isPlayerSleeping()) {
if (!this.mc.gameSettings.debugCamEnable) {
// VS code starts here
if (mountData.isMounted()) {
Vector3d playerPosInLocal = JOML.convert(mountData.getMountPos());
playerPosInLocal.sub(.5D, .6875, .5);
playerPosInLocal.round();
BlockPos bedPos = new BlockPos(playerPosInLocal.x, playerPosInLocal.y, playerPosInLocal.z);
IBlockState state = this.mc.world.getBlockState(bedPos);
Block block = state.getBlock();
float angleYaw = 0;
if (block != null && block.isBed(state, entity.world, bedPos, entity)) {
angleYaw = block.getBedDirection(state, entity.world, bedPos).getHorizontalIndex() * 90;
angleYaw += 180;
}
entity.rotationYaw = entity.prevRotationYaw = angleYaw;
entity.rotationPitch = entity.prevRotationPitch = 0;
} else {
BlockPos blockpos = new BlockPos(entity);
IBlockState iblockstate = this.mc.world.getBlockState(blockpos);
net.minecraftforge.client.ForgeHooksClient.orientBedCamera(this.mc.world, blockpos, iblockstate, entity);
GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
}
}
} else if (this.mc.gameSettings.thirdPersonView > 0) {
double d3 = this.thirdPersonDistancePrev + (4.0F - this.thirdPersonDistancePrev) * partialTicks;
IShipPilot shipPilot = (IShipPilot) Minecraft.getMinecraft().player;
if (shipPilot.isPilotingShip()) {
// TODO: Make this number scale with the Ship
d3 = 15D;
}
if (this.mc.gameSettings.debugCamEnable) {
GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
} else {
float f1 = entity.rotationYaw;
float f2 = entity.rotationPitch;
if (this.mc.gameSettings.thirdPersonView == 2) {
f2 += 180.0F;
}
double d4 = -MathHelper.sin(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * d3;
double d5 = MathHelper.cos(f1 * 0.017453292F) * MathHelper.cos(f2 * 0.017453292F) * d3;
double d6 = (-MathHelper.sin(f2 * 0.017453292F)) * d3;
for (int i = 0; i < 8; ++i) {
float f3 = (i & 1) * 2 - 1;
float f4 = (i >> 1 & 1) * 2 - 1;
float f5 = (i >> 2 & 1) * 2 - 1;
f3 = f3 * 0.1F;
f4 = f4 * 0.1F;
f5 = f5 * 0.1F;
IShipPilot pilot = (IShipPilot) Minecraft.getMinecraft().player;
((IWorldVS) this.mc.world).excludeShipFromRayTracer(((IShipPilot) this.mc.player).getPilotedShip());
// RayTraceResult raytraceresult = EntityMoveInjectionMethods.rayTraceBlocksIgnoreShip(Minecraft.getMinecraft().world, new Vec3d(d0 + f3, d1 + f4, d2 + f5), new Vec3d(d0 - d4 + f3 + f5, d1 - d6 + f4, d2 - d5 + f5), false, false, false, pilot.getPilotedShip());
RayTraceResult raytraceresult = mc.world.rayTraceBlocks(new Vec3d(d0 + (double) f3, d1 + (double) f4, d2 + (double) f5), new Vec3d(d0 - d4 + (double) f3 + (double) f5, d1 - d6 + (double) f4, d2 - d5 + (double) f5));
((IWorldVS) this.mc.world).unexcludeShipFromRayTracer(((IShipPilot) this.mc.player).getPilotedShip());
if (raytraceresult != null) {
double d7 = raytraceresult.hitVec.distanceTo(new Vec3d(d0, d1, d2));
if (d7 < d3) {
d3 = d7;
}
}
}
if (this.mc.gameSettings.thirdPersonView == 2) {
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
}
GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(0.0F, 0.0F, (float) (-d3));
GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
}
} else {
GlStateManager.translate(0.0F, 0.0F, 0.05F);
}
if (!this.mc.gameSettings.debugCamEnable) {
float yaw = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F;
float pitch = entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks;
float roll = 0.0F;
if (entity instanceof EntityAnimal) {
EntityAnimal entityanimal = (EntityAnimal) entity;
yaw = entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F;
}
IBlockState state = ActiveRenderInfo.getBlockStateAtEntityViewpoint(this.mc.world, entity, partialTicks);
net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup event = new net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup(EntityRenderer.class.cast(this), entity, state, partialTicks, yaw, pitch, roll);
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event);
GlStateManager.rotate(event.getRoll(), 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(event.getPitch(), 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(event.getYaw(), 0.0F, 1.0F, 0.0F);
}
if (mountData.isMounted() && mountData.getMountedShip().getShipRenderer().offsetPos != null) {
final ShipTransform renderTransform = mountData.getMountedShip().getShipTransformationManager().getRenderTransform();
Quaterniond orientationQuat = renderTransform.rotationQuaternion(TransformType.SUBSPACE_TO_GLOBAL);
Vector3dc radians = orientationQuat.getEulerAnglesXYZ(new Vector3d());
float moddedPitch = (float) Math.toDegrees(radians.x());
float moddedYaw = (float) Math.toDegrees(radians.y());
float moddedRoll = (float) Math.toDegrees(radians.z());
GlStateManager.rotate(-moddedRoll, 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(-moddedYaw, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(-moddedPitch, 1.0F, 0.0F, 0.0F);
}
GlStateManager.translate(-eyeVector.x, -eyeVector.y, -eyeVector.z);
d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks + eyeVector.x;
d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks + eyeVector.y;
d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks + eyeVector.z;
this.cloudFog = this.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method rayTraceBlocksInShip.
@Override
public RayTraceResult rayTraceBlocksInShip(Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock, PhysicsObject toUse) {
this.shouldInterceptRayTrace = false;
final ShipTransform shipTransform = toUse.getShipTransformationManager().getRenderTransform();
final Vec3d traceStart = shipTransform.transform(vec31, TransformType.GLOBAL_TO_SUBSPACE);
final Vec3d traceEnd = shipTransform.transform(vec32, TransformType.GLOBAL_TO_SUBSPACE);
final RayTraceResult resultInShip = World.class.cast(this).rayTraceBlocks(traceStart, traceEnd, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
if (resultInShip != null && resultInShip.hitVec != null && resultInShip.typeOfHit == Type.BLOCK) {
// The hitVec must ALWAYS be in global coordinates.
resultInShip.hitVec = shipTransform.transform(resultInShip.hitVec, TransformType.SUBSPACE_TO_GLOBAL);
this.shouldInterceptRayTrace = true;
return resultInShip;
}
this.shouldInterceptRayTrace = true;
return null;
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method rayTraceBlocksIgnoreShip.
@Override
public RayTraceResult rayTraceBlocksIgnoreShip(Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock, PhysicsObject toIgnore) {
this.shouldInterceptRayTrace = false;
RayTraceResult vanillaTrace = World.class.cast(this).rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
IPhysObjectWorld physObjectWorld = ((IHasShipManager) (this)).getManager();
if (physObjectWorld == null) {
return vanillaTrace;
}
Vec3d playerReachVector = vec32.subtract(vec31);
AxisAlignedBB playerRangeBB = new AxisAlignedBB(vec31.x, vec31.y, vec31.z, vec32.x, vec32.y, vec32.z);
List<PhysicsObject> nearbyShips = physObjectWorld.getPhysObjectsInAABB(playerRangeBB);
// Get rid of the Ship that we're not supposed to be RayTracing for
nearbyShips.remove(toIgnore);
double reachDistance = playerReachVector.length();
double worldResultDistFromPlayer = 420000000D;
if (vanillaTrace != null && vanillaTrace.hitVec != null) {
worldResultDistFromPlayer = vanillaTrace.hitVec.distanceTo(vec31);
}
for (PhysicsObject wrapper : nearbyShips) {
Vec3d playerEyesPos = vec31;
playerReachVector = vec32.subtract(vec31);
ShipTransform shipTransform = wrapper.getShipTransformationManager().getRenderTransform();
playerEyesPos = shipTransform.transform(playerEyesPos, TransformType.GLOBAL_TO_SUBSPACE);
playerReachVector = shipTransform.rotate(playerReachVector, TransformType.GLOBAL_TO_SUBSPACE);
Vec3d playerEyesReachAdded = playerEyesPos.add(playerReachVector.x * reachDistance, playerReachVector.y * reachDistance, playerReachVector.z * reachDistance);
RayTraceResult resultInShip = World.class.cast(this).rayTraceBlocks(playerEyesPos, playerEyesReachAdded, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
if (resultInShip != null && resultInShip.hitVec != null && resultInShip.typeOfHit == Type.BLOCK) {
double shipResultDistFromPlayer = resultInShip.hitVec.distanceTo(playerEyesPos);
if (shipResultDistFromPlayer < worldResultDistFromPlayer) {
worldResultDistFromPlayer = shipResultDistFromPlayer;
// The hitVec must ALWAYS be in global coordinates.
resultInShip.hitVec = shipTransform.transform(resultInShip.hitVec, TransformType.SUBSPACE_TO_GLOBAL);
vanillaTrace = resultInShip;
}
}
}
this.shouldInterceptRayTrace = true;
return vanillaTrace;
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinWorld method postCheckBlockCollision.
/**
* This mixin fixes players getting kicked for flying when they're standing on the ground.
*/
@Inject(method = "checkBlockCollision", at = @At("HEAD"), cancellable = true)
public void postCheckBlockCollision(final AxisAlignedBB axisAlignedBB, final CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
// If there wasn't a collision in the world, then check if there is a collision in ships
final List<PhysicsObject> physObjectsInAABB = getManager().getPhysObjectsInAABB(axisAlignedBB);
for (final PhysicsObject physicsObject : physObjectsInAABB) {
final ShipTransform shipTransform = physicsObject.getShipTransform();
final AxisAlignedBB aabbInShipSpace = new Polygon(axisAlignedBB, shipTransform.getGlobalToSubspace()).getEnclosedAABB();
final boolean collisionInShip = this.checkBlockCollision(aabbInShipSpace);
if (collisionInShip) {
callbackInfoReturnable.setReturnValue(true);
return;
}
}
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MixinNetHandlerPlayServer method preProcessPlayer.
/**
* This mixin fixes "Player Moved Wrongly" errors.
*
* @param packetPlayer The packet the player sent us
* @param info We can use this to cancel the invocation
*/
@Inject(method = "processPlayer", at = @At("HEAD"))
private void preProcessPlayer(final CPacketPlayer packetPlayer, final CallbackInfo info) {
// Don't run any of this code on the network thread!
if (this.player.getServerWorld().isCallingFromMinecraftThread()) {
// This fixes players dying of fall damage when changing dimensions
if (this.player.isInvulnerableDimensionChange()) {
return;
}
final PlayerMovementData addedPlayerMovementData = IHasPlayerMovementData.class.cast(packetPlayer).getPlayerMovementData();
final World world = player.world;
final UUID lastTouchedShipId = addedPlayerMovementData.getLastTouchedShipId();
final int ticksSinceTouchedLastShip = addedPlayerMovementData.getTicksSinceTouchedLastShip();
if (ticksSinceTouchedLastShip > 40) {
// If the player hasn't touched the ship in over 40 ticks, then ignore its coordinates relative to that ship.
final IDraggable playerAsDraggable = IDraggable.class.cast(this.player);
playerAsDraggable.setEntityShipMovementData(playerAsDraggable.getEntityShipMovementData().withLastTouchedShip(null).withAddedLinearVelocity(new Vector3d()).withAddedYawVelocity(0).withTicksPartOfGround(addedPlayerMovementData.getTicksPartOfGround()).withTicksSinceTouchedShip(ticksSinceTouchedLastShip));
return;
}
final int ticksPartOfGround = addedPlayerMovementData.getTicksPartOfGround();
final Vector3d playerPosInShip = new Vector3d(addedPlayerMovementData.getPlayerPosInShip());
final Vector3d playerLookInShip = new Vector3d(addedPlayerMovementData.getPlayerLookInShip());
ShipData lastTouchedShip = null;
if (lastTouchedShipId != null) {
final QueryableShipData queryableShipData = QueryableShipData.get(world);
final Optional<ShipData> shipDataOptional = queryableShipData.getShip(lastTouchedShipId);
if (shipDataOptional.isPresent()) {
lastTouchedShip = shipDataOptional.get();
final PhysicsObject shipObject = ValkyrienUtils.getServerShipManager(world).getPhysObjectFromUUID(lastTouchedShip.getUuid());
if (shipObject != null) {
if (shipObject.getTicksSinceShipTeleport() > PhysicsObject.TICKS_SINCE_TELEPORT_TO_START_DRAGGING) {
final ShipTransform shipTransform = lastTouchedShip.getShipTransform();
shipTransform.transformPosition(playerPosInShip, TransformType.SUBSPACE_TO_GLOBAL);
shipTransform.transformDirection(playerLookInShip, TransformType.SUBSPACE_TO_GLOBAL);
} else {
// Don't move the player relative to the ship until the TicksSinceShipTeleport timer expires.
playerPosInShip.set(player.posX, player.posY, player.posZ);
}
}
} else {
// info.cancel();
return;
}
}
// Get the player pitch/yaw from the look vector
final Tuple<Double, Double> pitchYawTuple = VSMath.getPitchYawFromVector(playerLookInShip);
final double playerPitchInGlobal = pitchYawTuple.getFirst();
final double playerYawInGlobal = pitchYawTuple.getSecond();
// Idk if this is needed, but I'm too bothered to change it
packetPlayer.moving = true;
// Then update the packet values to match the ones above.
packetPlayer.x = playerPosInShip.x();
packetPlayer.y = playerPosInShip.y();
packetPlayer.z = playerPosInShip.z();
packetPlayer.yaw = (float) playerYawInGlobal;
packetPlayer.pitch = (float) playerPitchInGlobal;
// Set the player motion values to tell the NetHandlerPlayServer that the player is allowed to move this fast.
this.player.motionX = packetPlayer.x - this.firstGoodX;
this.player.motionY = packetPlayer.y - this.firstGoodY;
this.player.motionZ = packetPlayer.z - this.firstGoodZ;
// Update the player draggable
final IDraggable playerAsDraggable = IDraggable.class.cast(this.player);
playerAsDraggable.setEntityShipMovementData(playerAsDraggable.getEntityShipMovementData().withLastTouchedShip(lastTouchedShip).withAddedLinearVelocity(new Vector3d()).withAddedYawVelocity(0).withTicksPartOfGround(ticksPartOfGround).withTicksSinceTouchedShip(ticksSinceTouchedLastShip));
}
}
Aggregations