diff --git a/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java b/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java index 1449bd2..db772f9 100644 --- a/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java +++ b/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java @@ -87,6 +87,8 @@ public class VehicleBaseRenderer entityTypeIn, World worldIn, VehicleBuildInfo vehicleBuildInfo) { super(entityTypeIn, worldIn); @@ -258,20 +260,22 @@ public class VehicleBaseEntity extends Entity { @Override public void tick() { + this.baseTick(); this.LastPositionVector = CurrentPositionVector; CurrentPositionVector = getPositionVec(); - super.tick(); Controller.PollInputs(GetByteArrayValue("INPUT_DATA")); PhysicsTick(); + this.setPosition(this.getPosX(), this.getPosY(), this.getPosZ()); SubClassTickUpdateEvent(); TickUpdateEvent(); SetBooleanDataValue("ON_GROUND",getMotion().y == 0); if(this.world.isRemote()){ - SubClassServerSideTickEvent(); + SubClassClientSideTickEvent(); ClientSideTickEvent(); } else{ - SubClassClientSideTickEvent(); + SubClassServerSideTickEvent(); ServerSideTickEvent(); + } } @@ -283,11 +287,12 @@ public class VehicleBaseEntity extends Entity { SetFloatDataValue("ORIENTATION_YAW",(GetFloatDataValue("ORIENTATION_YAW") + GetFloatDataValue("ADD_ORIENTATION_YAW_NEXT_TICK"))%360); SetFloatDataValue("ADD_ORIENTATION_YAW_NEXT_TICK",0f); } - + public void AddVelocity(double x, double y, double z){ + VehicleVelocity.add(x,y,z); + } public boolean TouchingGround(){return GetBooleanDataValue("ON_GROUND");} - public void PhysicsTick(){ - Vector3d Velocity = Vector3.Positive(getMotion()); + Vector3d Velocity = Vector3.Positive(VehicleVelocity).GetDouble(); Vector3d NormalisedVelocity = Velocity.normalize(); double OverallVelocity = Velocity.x * NormalisedVelocity.x + Velocity.z * NormalisedVelocity.z; double Scalar = Math.max(Math.min(OverallVelocity/GetDoubleDataValue("ROTATE_VELOCITY"),1),0); @@ -297,32 +302,47 @@ public class VehicleBaseEntity extends Entity { SetDoubleDataValue("ANGLE_OFFSET_YAW",AngleOffsets.x); SetDoubleDataValue("ANGLE_OFFSET_PITCH",AngleOffsets.y); SetDoubleDataValue("ANGLE_OFFSET_ROLL",AngleOffsets.z); - if(GetBooleanDataValue("ADHERES_TO_GRAVITY")){ + if(GetBooleanDataValue("ADHERES_TO_GRAVITY")) { if (!this.isOnGround()) { - this.setMotion(this.getMotion().add(0, -GetDoubleDataValue("GRAVITY"), 0)); - } else{ - if(GetFloatDataValue("ORIENTATION_PITCH") % 90 != 0){ - SetFloatDataValue("ORIENTATION_PITCH", Math.round(GetFloatDataValue("ORIENTATION_PITCH")/90.0f) * 90.0f); + VehicleVelocity.add(0, -GetDoubleDataValue("GRAVITY"), 0); + } else { + if (GetFloatDataValue("ORIENTATION_PITCH") % 90 != 0) { + SetFloatDataValue("ORIENTATION_PITCH", Math.round(GetFloatDataValue("ORIENTATION_PITCH") / 90.0f) * 90.0f); } } - this.move(net.minecraft.entity.MoverType.SELF, this.getMotion()); - this.setMotion(this.getMotion().mul(0.98D, 0.98D, 0.98D)); } + Vector3d currentMotion; + //!!!!! + //REMINDER FOR NEXT TIME + //MAKE VehicleVelocity SERVER SIDED + //BIG SYNC ISSUES IN MULTIPLAYER + //!!!!! + setMotion(VehicleVelocity.GetDouble()); + this.move(net.minecraft.entity.MoverType.SELF, VehicleVelocity.GetDouble()); + VehicleVelocity = new Vector3(this.getMotion()); + VehicleVelocity.multiply(0.98); + markVelocityChanged(); RotationTick(); - if(Scalar < 1&& this.getMotion().y < 0){ + if(Scalar < 1&& VehicleVelocity.y < 0){ double CenterOfMass = GetDoubleDataValue("CENTRE_OF_MASS_Z"); float CenterOfMassFloat = (float) CenterOfMass; - float YVelocity = (float) this.getMotion().y; - if(YVelocity < 0){ - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", (float) (-CenterOfMassFloat * (Math.max(1-Scalar,0)))); - } + SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", (float) (-CenterOfMassFloat * (Math.max(1-Scalar,0)))); } } + @Override + public void move(MoverType type, Vector3d position) { + Vector3d currentMotion = this.getMotion(); + super.move(type, position); + } + public void ApplyForce(double dx, double dy, double dz){ this.setMotion(this.getMotion().add(dx,dy,dz)); } - + @Override + public boolean canBePushed() { + return false; + } public void OnPunchedEvent(){} public void ServerSideTickEvent(){} public void ClientSideTickEvent(){} @@ -414,19 +434,6 @@ public class VehicleBaseEntity extends Entity { ); SeatPosition.transform(TransformationMatrix); - - /*Quaternion TotalRotation = new Quaternion(0.0F, 0.0F, 0.0F, 1.0F); - TotalRotation.multiply(Vector3f.YP.rotation(yawRad)); - - Vector3f LocalPitchAxis = new Vector3f((float)Math.cos(yawRad), 0.0F, (float)Math.sin(yawRad)); - TotalRotation.multiply(LocalPitchAxis.rotation(pitchRad)); - - Vector3f LocalRollAxis = new Vector3f((float)-Math.sin(yawRad),0.0F,(float)Math.cos(yawRad)); - LocalRollAxis.transform(Vector3f.XP.rotation(pitchRad)); - TotalRotation.multiply(LocalRollAxis.rotation(rollRad)); - - Vector3f localOffsetFloat = new Vector3(RelativeSeatOffset).GetFloat(); - localOffsetFloat.transform(TotalRotation);*/ passenger.setPosition( this.getPosX() + SeatPosition.getX() - OriginPosition.x, this.getPosY() + SeatPosition.getY() + passenger.getMountedYOffset() - OriginPosition.y, diff --git a/src/main/java/net/halbear/hvf/Util/Math/ExtendedVectors/Vector3.java b/src/main/java/net/halbear/hvf/Util/Math/ExtendedVectors/Vector3.java index d4cf659..aa9bdc9 100644 --- a/src/main/java/net/halbear/hvf/Util/Math/ExtendedVectors/Vector3.java +++ b/src/main/java/net/halbear/hvf/Util/Math/ExtendedVectors/Vector3.java @@ -28,6 +28,46 @@ public class Vector3 { public float GetYF(){return (float)y;} public float GetZF(){return (float)z;} + public static boolean inRange(Vector3d Lowest, Vector3d Highest, Vector3d Comparer){ + boolean InLowestRange = (Lowest.x <= Comparer.x) && (Lowest.y <= Comparer.y) && (Lowest.z <= Comparer.z); + boolean InHighestRange = (Highest.x >= Comparer.x) && (Highest.y >= Comparer.y) && (Highest.z >= Comparer.z); + return InLowestRange && InHighestRange; + } + + public void add(double vectorInx,double vectorIny,double vectorInz){ + this.x += vectorInx; + this.y += vectorIny; + this.z += vectorInz; + } + public void add(Vector3 vectorIn){ + this.x += vectorIn.x; + this.y += vectorIn.y; + this.z += vectorIn.z; + } + public void sub(Vector3 vectorIn){ + this.x -= vectorIn.x; + this.y -= vectorIn.y; + this.z -= vectorIn.z; + } + public void multiply(double value){ + this.x *= value; + this.y *= value; + this.z *= value; + } + public void multiply(Vector3 vectorIn){ + this.x *= vectorIn.x; + this.y *= vectorIn.y; + this.z *= vectorIn.z; + } + public void divide(Vector3 vectorIn){ + this.x /= vectorIn.x; + this.y /= vectorIn.y; + this.z /= vectorIn.z; + } + + public static Vector3d Negative(Vector3d in){ + return new Vector3d(in.x > 0 ? -in.x : in.x,in.y > 0 ? -in.y : in.y,in.z > 0 ? -in.z : in.z); + } public static Vector3i Positive(Vector3i in){ return new Vector3i(in.getX() < 0 ? -in.getX(): in.getX(),in.getY() < 0 ? -in.getY() : in.getY(),in.getZ() < 0 ? -in.getZ() : in.getZ()); } diff --git a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleController.java b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleController.java index edda321..dc4354e 100644 --- a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleController.java +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleController.java @@ -43,16 +43,31 @@ public class VehicleController { public VehicleController AddInputFunction(String Input, float ChangeAmount, Vector3d TerminalVelocity, InputCategory functionType){ switch(functionType){ case MoveForward: - AddInputFunction(Input,()-> Parent.setMotion(Vector3.Clamp(-TerminalVelocity.x,-TerminalVelocity.y,-TerminalVelocity.z,TerminalVelocity.x,TerminalVelocity.y,TerminalVelocity.z,Parent.getMotion().add(-ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()))))); + AddInputFunction(Input,()->{ if(Vector3.inRange(Vector3.Negative(TerminalVelocity),TerminalVelocity, Parent.getMotion())){ + Parent.AddVelocity(-ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw())); + } + }); break; case MoveBackward: - AddInputFunction(Input,()-> Parent.setMotion(Vector3.Clamp(-TerminalVelocity.x,-TerminalVelocity.y,-TerminalVelocity.z,TerminalVelocity.x,TerminalVelocity.y,TerminalVelocity.z,Parent.getMotion().add(ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * -(float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()))))); + AddInputFunction(Input,()-> { + if (Vector3.inRange(Vector3.Negative(TerminalVelocity), TerminalVelocity, Parent.getMotion())) { + Parent.AddVelocity(ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * -(float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw())); + } + }); break; case StrafeLeft: - AddInputFunction(Input,()-> Parent.setMotion(Vector3.Clamp(-TerminalVelocity.x,-TerminalVelocity.y,-TerminalVelocity.z,TerminalVelocity.x,TerminalVelocity.y,TerminalVelocity.z,Parent.getMotion().add(ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * -(float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()))))); + AddInputFunction(Input,()-> { + if (Vector3.inRange(Vector3.Negative(TerminalVelocity), TerminalVelocity, Parent.getMotion())) { + Parent.AddVelocity(ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * -(float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw())); + } + }); break; case StrafeRight: - AddInputFunction(Input,()-> Parent.setMotion(Vector3.Clamp(-TerminalVelocity.x,-TerminalVelocity.y,-TerminalVelocity.z,TerminalVelocity.x,TerminalVelocity.y,TerminalVelocity.z,Parent.getMotion().add(-ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()))))); + AddInputFunction(Input,()-> { + if (Vector3.inRange(Vector3.Negative(TerminalVelocity), TerminalVelocity, Parent.getMotion())) { + Parent.AddVelocity(-ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw())); + } + }); break; } return this;