From 73f958423c2b062e3f119c0eaba06db2cf140581 Mon Sep 17 00:00:00 2001 From: Halbear Date: Mon, 1 Jun 2026 23:57:22 +0100 Subject: [PATCH] Seat positions and more physics work --- .../Renderer/VehicleAnimationManager.java | 11 +- .../Entity/Renderer/VehicleBaseRenderer.java | 9 +- .../halbear/hvf/Entity/VehicleBaseEntity.java | 156 +++++++++++++----- .../EventHandlers/ModEventHandler.java | 1 - .../hvf/Registry/Input/InputManager.java | 7 + .../hvf/Registry/Input/ModKeybinds.java | 24 +-- .../UsageExamples/Aeroplane/Aeroplane.java | 20 ++- .../Aeroplane/Renderer/AeroplaneRenderer.java | 13 +- .../hvf/UsageExamples/Airboat/Airboat.java | 6 +- .../Util/Client/VehicleCameraSettings.java | 2 +- .../hvf/Util/Math/CommonFunctions.java | 37 +++++ .../Util/Math/ExtendedVectors/Vector3.java | 150 +++++++++++++++++ .../halbear/hvf/Util/Mixin/CameraMixin.java | 9 +- .../Util/VehicleData/VehicleBuildInfo.java | 49 +++++- .../Util/VehicleData/VehicleController.java | 58 ++++++- 15 files changed, 463 insertions(+), 89 deletions(-) create mode 100644 src/main/java/net/halbear/hvf/Util/Math/CommonFunctions.java create mode 100644 src/main/java/net/halbear/hvf/Util/Math/ExtendedVectors/Vector3.java diff --git a/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleAnimationManager.java b/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleAnimationManager.java index 13be106..be2f1ed 100644 --- a/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleAnimationManager.java +++ b/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleAnimationManager.java @@ -2,6 +2,7 @@ package net.halbear.hvf.Entity.Renderer; import net.halbear.hvf.Entity.*; import net.halbear.hvf.Halsvehicleframework; +import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3f; import net.minecraft.client.renderer.model.ModelRenderer; @@ -30,18 +31,20 @@ public class VehicleAnimationManager { } public ModelRenderer WheelAnimationAccurate(ModelRenderer BoneIn, T entity, double WheelDiameterInMetres, AnimationAxis axis, boolean invertAnimation){ + Vector3d Normalised = entity.getMotion().normalize(); + float Modifier = (float) ((Normalised.x * Math.sin(entity.GetVehicleYaw())) +(Math.cos(entity.GetVehicleYaw()) * Normalised.z)); float PartialTick = VehicleBaseRenderer.PartialTick; - double RotationDeg = ((360 * entity.GetPositionDifference())/ (WheelDiameterInMetres * Math.PI))%360; + double RotationDeg = ((360 * Modifier * entity.GetPositionDifference()/100)/ (WheelDiameterInMetres * Math.PI))%360; float RotationRad = (float)(RotationDeg * DegToRad); switch(axis){ case X_AXIS: - BoneIn.rotateAngleX = BoneIn.rotateAngleX + (RotationRad*PartialTick); + BoneIn.rotateAngleX += (RotationRad*PartialTick); break; case Y_AXIS: - BoneIn.rotateAngleY = BoneIn.rotateAngleY + (RotationRad*PartialTick); + BoneIn.rotateAngleY += (RotationRad*PartialTick); break; case Z_AXIS: - BoneIn.rotateAngleZ = BoneIn.rotateAngleZ + (RotationRad*PartialTick); + BoneIn.rotateAngleZ += (RotationRad*PartialTick); break; } return BoneIn; 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 36f6379..1449bd2 100644 --- a/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java +++ b/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.IVertexBuilder; import net.halbear.hvf.Entity.VehicleBaseEntity; import net.halbear.hvf.Halsvehicleframework; +import net.halbear.hvf.Util.Math.ExtendedVectors.Vector3; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.entity.EntityRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; @@ -22,8 +23,8 @@ import java.util.Map; public class VehicleBaseRenderer> extends EntityRenderer { private Vector3f LastRotations = new Vector3f(0,0,0); - private PivotOrigin OriginType = PivotOrigin.RelativeToEntityCenter; - private Vector3d OriginOffset = new Vector3d(0,0,0); + public PivotOrigin OriginType = PivotOrigin.RelativeToEntityCenter; + public Vector3d OriginOffset = new Vector3d(0,0,0); public static float PartialTick = 0.0f; private final Map STATE_BASED_MODELS = new HashMap<>(); @@ -80,11 +81,13 @@ public class VehicleBaseRenderer VEHICLE_SYNCHED_PARAMETERS = EntityDataManager.createKey(VehicleBaseEntity.class, DataSerializers.COMPOUND_NBT); @@ -40,20 +45,11 @@ public class VehicleBaseEntity extends Entity { private Vector3d LastPositionVector = new Vector3d(0,0,0); private Vector3d CurrentPositionVector = new Vector3d(0,0,0); private final VehicleController Controller; - - public void SetPartialTick(float PartialTick){this.PartialTick = PartialTick;} - public float GetPartialTick(){return PartialTick;} - - public VehicleAnimationManager GetAnimationManager(){return ANIMATION_MANAGER;} - - public Vector3d GetPilotSeat(){return VehicleSeatOffsets.length > 0 ? VehicleSeatOffsets[0] : new Vector3d(0,0,0);} - - public VehicleController GetVehicleController(){ - return Controller; - } + public VehicleBuildInfo vehicleBuildInfo; public VehicleBaseEntity(EntityType entityTypeIn, World worldIn, VehicleBuildInfo vehicleBuildInfo) { super(entityTypeIn, worldIn); + this.vehicleBuildInfo = vehicleBuildInfo; Controller = new VehicleController(this); this.setNoGravity(vehicleBuildInfo.GetAdheresToGravity()); List VehicleSeats = new ArrayList(); @@ -65,9 +61,20 @@ public class VehicleBaseEntity extends Entity { float PropRotation = (float)(360 * Math.random()); BASE_DOUBLE_PARAMETERS.put("GRAVITY",!vehicleBuildInfo.GetAdheresToGravity() ? 0 : vehicleBuildInfo.GetGravityStrength()/200.0); BASE_BOOL_PARAMETERS.put("ADHERES_TO_GRAVITY",vehicleBuildInfo.GetAdheresToGravity()); + BASE_BOOL_PARAMETERS.put("ON_GROUND",true); BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_X",vehicleBuildInfo.GetCentreOfMass().x); BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_Y",vehicleBuildInfo.GetCentreOfMass().y); BASE_DOUBLE_PARAMETERS.put("CENTRE_OF_MASS_Z",vehicleBuildInfo.GetCentreOfMass().z); + BASE_DOUBLE_PARAMETERS.put("AT_REST_ANGLE_OFFSET_YAW",vehicleBuildInfo.GetAtRestAngleOffsets().x); + BASE_DOUBLE_PARAMETERS.put("AT_REST_ANGLE_OFFSET_PITCH",vehicleBuildInfo.GetAtRestAngleOffsets().y); + BASE_DOUBLE_PARAMETERS.put("AT_REST_ANGLE_OFFSET_ROLL",vehicleBuildInfo.GetAtRestAngleOffsets().z); + BASE_DOUBLE_PARAMETERS.put("ANGLE_OFFSET_YAW",0d); + BASE_DOUBLE_PARAMETERS.put("ANGLE_OFFSET_PITCH",0d); + BASE_DOUBLE_PARAMETERS.put("ANGLE_OFFSET_ROLL",0d); + BASE_DOUBLE_PARAMETERS.put("AT_ROTATE_SPEED_ANGLE_OFFSET_YAW",vehicleBuildInfo.GetRotateAngleOffsets().x); + BASE_DOUBLE_PARAMETERS.put("AT_ROTATE_SPEED_ANGLE_OFFSET_PITCH",vehicleBuildInfo.GetRotateAngleOffsets().y); + BASE_DOUBLE_PARAMETERS.put("AT_ROTATE_SPEED_ANGLE_OFFSET_ROLL",vehicleBuildInfo.GetRotateAngleOffsets().z); + BASE_DOUBLE_PARAMETERS.put("ROTATE_VELOCITY",vehicleBuildInfo.GetRotateVelocity()); BASE_FLOAT_PARAMETERS.put("ORIENTATION_YAW",0f); BASE_FLOAT_PARAMETERS.put("ADD_ORIENTATION_YAW_NEXT_TICK",0f); BASE_FLOAT_PARAMETERS.put("ORIENTATION_PITCH",0f); @@ -113,7 +120,7 @@ public class VehicleBaseEntity extends Entity { case Ship: break; } - + this.stepHeight = vehicleBuildInfo.GetStepHeight(); CompoundNBT SyncedData = this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS).copy(); BASE_FLOAT_PARAMETERS.forEach(SyncedData::putFloat); BASE_DOUBLE_PARAMETERS.forEach(SyncedData::putDouble); @@ -126,6 +133,19 @@ public class VehicleBaseEntity extends Entity { this.CurrentPositionVector = this.getPositionVec(); } + public VehicleBuildInfo getBuildInfo(){return vehicleBuildInfo;} + + public void SetPartialTick(float PartialTick){this.PartialTick = PartialTick;} + public float GetPartialTick(){return PartialTick;} + + public VehicleAnimationManager GetAnimationManager(){return ANIMATION_MANAGER;} + + public Vector3d GetPilotSeat(){return VehicleSeatOffsets.length > 0 ? VehicleSeatOffsets[0] : new Vector3d(0,0,0);} + + public VehicleController GetVehicleController(){ + return Controller; + } + public Vector3d GetLastEntityPosition(){ return this.LastPositionVector; } @@ -194,7 +214,7 @@ public class VehicleBaseEntity extends Entity { public void SetVehicleYaw(float value){SetFloatDataValue("ORIENTATION_YAW", value);} public void SetVehiclePitch(float value){SetFloatDataValue("ORIENTATION_PITCH", value); } public float GetVehicleRoll(){return GetFloatDataValue("ORIENTATION_ROLL"); } - public float GetVehicleYaw(){ return GetFloatDataValue("ORIENTATION_YAW"); } + public float GetVehicleYaw(){ return 180F - GetFloatDataValue("ORIENTATION_YAW"); } public float GetVehiclePitch(){return GetFloatDataValue("ORIENTATION_PITCH"); } public float[] GetVehicleRotations(){ return new float[]{GetVehicleYaw(),GetVehiclePitch(),GetVehicleRoll()}; @@ -245,6 +265,7 @@ public class VehicleBaseEntity extends Entity { PhysicsTick(); SubClassTickUpdateEvent(); TickUpdateEvent(); + SetBooleanDataValue("ON_GROUND",getMotion().y == 0); if(this.world.isRemote()){ SubClassServerSideTickEvent(); ClientSideTickEvent(); @@ -263,7 +284,19 @@ public class VehicleBaseEntity extends Entity { SetFloatDataValue("ADD_ORIENTATION_YAW_NEXT_TICK",0f); } + public boolean TouchingGround(){return GetBooleanDataValue("ON_GROUND");} + public void PhysicsTick(){ + Vector3d Velocity = Vector3.Positive(getMotion()); + 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); + Vector3d AtRest = new Vector3d(GetDoubleDataValue("AT_REST_ANGLE_OFFSET_YAW"),GetDoubleDataValue("AT_REST_ANGLE_OFFSET_PITCH"),GetDoubleDataValue("AT_REST_ANGLE_OFFSET_ROLL")); + Vector3d AtRotate = new Vector3d(GetDoubleDataValue("AT_ROTATE_SPEED_ANGLE_OFFSET_YAW"),GetDoubleDataValue("AT_ROTATE_SPEED_ANGLE_OFFSET_PITCH"),GetDoubleDataValue("AT_ROTATE_SPEED_ANGLE_OFFSET_ROLL")); + Vector3d AngleOffsets = Vector3.Lerp(AtRest,AtRotate,Scalar); + SetDoubleDataValue("ANGLE_OFFSET_YAW",AngleOffsets.x); + SetDoubleDataValue("ANGLE_OFFSET_PITCH",AngleOffsets.y); + SetDoubleDataValue("ANGLE_OFFSET_ROLL",AngleOffsets.z); if(GetBooleanDataValue("ADHERES_TO_GRAVITY")){ if (!this.isOnGround()) { this.setMotion(this.getMotion().add(0, -GetDoubleDataValue("GRAVITY"), 0)); @@ -276,29 +309,12 @@ public class VehicleBaseEntity extends Entity { this.setMotion(this.getMotion().mul(0.98D, 0.98D, 0.98D)); } RotationTick(); - if(this.getMotion().z == 0 && this.getMotion().x == 0 && this.getMotion().y != 0){ + if(Scalar < 1&& this.getMotion().y < 0){ double CenterOfMass = GetDoubleDataValue("CENTRE_OF_MASS_Z"); float CenterOfMassFloat = (float) CenterOfMass; - if(this.getMotion().y < 0){ - if(GetFloatDataValue("ORIENTATION_PITCH") <= 0 && GetFloatDataValue("ORIENTATION_PITCH") > -90){ - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", -CenterOfMassFloat); - } else if ( GetFloatDataValue("ORIENTATION_PITCH") <= 360 && GetFloatDataValue("ORIENTATION_PITCH") > 270){ - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", CenterOfMassFloat); - } else if (GetFloatDataValue("ORIENTATION_PITCH") <= -90 && GetFloatDataValue("ORIENTATION_PITCH") > -180 ){ - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", - CenterOfMassFloat); - } else if(GetFloatDataValue("ORIENTATION_PITCH") <= 270 && GetFloatDataValue("ORIENTATION_PITCH") > 180){ - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", CenterOfMassFloat); - } - } else{ - if(GetFloatDataValue("ORIENTATION_PITCH") <= 0 && GetFloatDataValue("ORIENTATION_PITCH") > -90){ - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", CenterOfMassFloat); - } else if ( GetFloatDataValue("ORIENTATION_PITCH") <= 360 && GetFloatDataValue("ORIENTATION_PITCH") > 270){ - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", -CenterOfMassFloat); - } else if (GetFloatDataValue("ORIENTATION_PITCH") <= -90 && GetFloatDataValue("ORIENTATION_PITCH") > -180 ){ - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", CenterOfMassFloat); - } else if(GetFloatDataValue("ORIENTATION_PITCH") <= 270 && GetFloatDataValue("ORIENTATION_PITCH") > 180) { - SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", -CenterOfMassFloat); - } + float YVelocity = (float) this.getMotion().y; + if(YVelocity < 0){ + SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", (float) (-CenterOfMassFloat * (Math.max(1-Scalar,0)))); } } } @@ -348,11 +364,73 @@ public class VehicleBaseEntity extends Entity { int seatIndex = this.getPassengers().indexOf(passenger); if (seatIndex >= 0 && seatIndex < VehicleSeatOffsets.length) { Vector3d localOffset = VehicleSeatOffsets[seatIndex]; - Vector3d rotatedOffset = localOffset.rotateYaw((float) Math.toRadians(-this.rotationYaw)); + PivotOrigin OriginType = vehicleBuildInfo.GetOriginType(); + Vector3d OriginPosition = vehicleBuildInfo.GetOriginOffset(); + switch(OriginType) { + case PilotSeat: + OriginPosition = OriginPosition.add(GetPilotSeat().x,GetPilotSeat().y,GetPilotSeat().z); + break; + case EntityPosition: + break; + case RelativeToEntityCenter: + OriginPosition = OriginPosition.add(new Vector3d(0, getHeight()/2, 0)); + break; + } + float yawRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_YAW")); + float pitchRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_PITCH")); + float rollRad = (float) Math.toRadians(GetFloatDataValue("ORIENTATION_ROLL")); + + float CosYaw = (float)Math.cos(yawRad); + float SinYaw = (float)Math.sin(yawRad); + float CosPitch = (float)Math.cos(pitchRad); + float SinPitch = (float)Math.sin(pitchRad); + float CosRoll = (float)Math.cos(rollRad); + float SinRoll = (float)Math.sin(rollRad); + + float m00 = CosYaw * CosRoll + SinYaw * SinPitch * SinRoll; + float m01 = -CosYaw * SinRoll + SinYaw * SinPitch * CosRoll; + float m02 = SinYaw * CosPitch; + + float m10 = SinRoll * CosPitch; + float m11 = CosRoll * CosPitch; + float m12 = -SinPitch; + + float m20 = -SinYaw * CosRoll + CosYaw * SinPitch * SinRoll; + float m21 = SinYaw * SinRoll + CosYaw * SinPitch * CosRoll; + float m22 = CosYaw * CosPitch; + + Matrix4f TransformationMatrix = new Matrix4f(new float[]{ + m00,m01,m02,0f, + m10,m11,m12,0f, + m20,m21,m22,0f, + 0f,0f,0f,1f + }); + + Vector4f SeatPosition = new Vector4f( + (float) (localOffset.x + OriginPosition.x), + (float) (localOffset.y + OriginPosition.y), + (float) (localOffset.z + OriginPosition.z), + 1.0f + ); + + 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() + rotatedOffset.x, - this.getPosY() + rotatedOffset.y + passenger.getMountedYOffset(), - this.getPosZ() + rotatedOffset.z + this.getPosX() + SeatPosition.getX() - OriginPosition.x, + this.getPosY() + SeatPosition.getY() + passenger.getMountedYOffset() - OriginPosition.y, + this.getPosZ() + SeatPosition.getZ() - OriginPosition.z ); } else { super.updatePassenger(passenger); diff --git a/src/main/java/net/halbear/hvf/Registry/EventHandlers/ModEventHandler.java b/src/main/java/net/halbear/hvf/Registry/EventHandlers/ModEventHandler.java index 589081f..d386d5f 100644 --- a/src/main/java/net/halbear/hvf/Registry/EventHandlers/ModEventHandler.java +++ b/src/main/java/net/halbear/hvf/Registry/EventHandlers/ModEventHandler.java @@ -28,7 +28,6 @@ public class ModEventHandler { for(int i = 0; i < InputManager.ActiveKeys.size(); i++){ bytesFromBytes[i] = InputManager.ActiveKeys.get(i); } - System.out.println(vehicle.GetStringDataValue("PILOT_UUID") + "\n" + player.getUniqueID()); if(Objects.equals(vehicle.GetStringDataValue("PILOT_UUID"), player.getUniqueID().toString()) && !Arrays.equals(bytesFromBytes, vehicle.GetByteArrayValue("INPUT_DATA"))) { InputArrayNetworking.INSTANCE.sendToServer(new InputArrayPacket(bytesFromBytes)); } diff --git a/src/main/java/net/halbear/hvf/Registry/Input/InputManager.java b/src/main/java/net/halbear/hvf/Registry/Input/InputManager.java index bdda0e0..6934f50 100644 --- a/src/main/java/net/halbear/hvf/Registry/Input/InputManager.java +++ b/src/main/java/net/halbear/hvf/Registry/Input/InputManager.java @@ -29,6 +29,13 @@ public class InputManager { public static void AddBinding(KeyBinding keyBinding, String BindingName){ KEY_BINDING_MAP.put(keyBinding,BindingName); + ReCalculateByteArrays(); + } + public static void AddBindings(KeyBinding[] keyBinding, String[] BindingName){ + for(int i = 0; i < (Math.min(keyBinding.length, BindingName.length)); i++) { + KEY_BINDING_MAP.put(keyBinding[i], BindingName[i]); + } + ReCalculateByteArrays(); } public static void ReCalculateByteArrays(){ diff --git a/src/main/java/net/halbear/hvf/Registry/Input/ModKeybinds.java b/src/main/java/net/halbear/hvf/Registry/Input/ModKeybinds.java index 04be946..eb18fb0 100644 --- a/src/main/java/net/halbear/hvf/Registry/Input/ModKeybinds.java +++ b/src/main/java/net/halbear/hvf/Registry/Input/ModKeybinds.java @@ -41,6 +41,18 @@ public class ModKeybinds { GLFW.GLFW_KEY_D, "key.categories.general_vehicle_controls" ); + public static KeyBinding TURN_LEFT_KEY = new KeyBinding( + "key.hals_vehicle_framework.turn_left", + InputMappings.Type.KEYSYM, + GLFW.GLFW_KEY_A, + "key.categories.general_vehicle_controls" + ); + public static KeyBinding TURN_RIGHT_KEY = new KeyBinding( + "key.hals_vehicle_framework.turn_right", + InputMappings.Type.KEYSYM, + GLFW.GLFW_KEY_D, + "key.categories.general_vehicle_controls" + ); //Wheeled Land Vehicles (Cars) public static KeyBinding ACCELERATE_KEY = new KeyBinding( @@ -55,18 +67,6 @@ public class ModKeybinds { GLFW.GLFW_KEY_S, "key.categories.land_vehicle_controls" ); - public static KeyBinding TURN_LEFT_KEY = new KeyBinding( - "key.hals_vehicle_framework.turn_left", - InputMappings.Type.KEYSYM, - GLFW.GLFW_KEY_A, - "key.categories.land_vehicle_controls" - ); - public static KeyBinding TURN_RIGHT_KEY = new KeyBinding( - "key.hals_vehicle_framework.turn_right", - InputMappings.Type.KEYSYM, - GLFW.GLFW_KEY_D, - "key.categories.land_vehicle_controls" - ); public static KeyBinding CLUTCH_KEY = new KeyBinding( "key.hals_vehicle_framework.clutch", KeyConflictContext.IN_GAME, diff --git a/src/main/java/net/halbear/hvf/UsageExamples/Aeroplane/Aeroplane.java b/src/main/java/net/halbear/hvf/UsageExamples/Aeroplane/Aeroplane.java index 4a56c69..be0f4a8 100644 --- a/src/main/java/net/halbear/hvf/UsageExamples/Aeroplane/Aeroplane.java +++ b/src/main/java/net/halbear/hvf/UsageExamples/Aeroplane/Aeroplane.java @@ -1,6 +1,7 @@ package net.halbear.hvf.UsageExamples.Aeroplane; import net.halbear.hvf.Entity.VehicleBaseEntity; +import net.halbear.hvf.Registry.Input.InputCategory; import net.halbear.hvf.Util.Client.VehicleCameraPreset; import net.halbear.hvf.Util.Client.VehicleCameraSettings; import net.halbear.hvf.Util.VehicleData.EngineCategories; @@ -13,7 +14,7 @@ import net.minecraft.world.World; public class Aeroplane extends VehicleBaseEntity { - private static final VehicleBuildInfo buildInfo = new VehicleBuildInfo(VehicleClassification.Aeroplane) + public static final VehicleBuildInfo buildInfo = new VehicleBuildInfo(VehicleClassification.Aeroplane) .SetEngineCount(1) .SetEngineType(EngineCategories.Aircraft_Propeller) .SetMaxEngineRPM(3000) @@ -21,8 +22,12 @@ public class Aeroplane extends VehicleBaseEntity { .SetMaxSpeedMS(70) .SetCentreOfMass(new Vector3d(0,0,2)) .SetPilotSeat(new Vector3d(0.0D, -1D, 0.0D)) - .AddPassengerSeat(new Vector3d(0.0D, -1D, 1.0D)) - .SetGravityStrength(9.8) + .AddPassengerSeat(new Vector3d(2.0D, 0.5D, 0.25D)) + .AddPassengerSeat(new Vector3d(-2.0D, 0.5D, 0.25D)) + .SetGravityStrength(3.8) + .SetAtRestAngleOffsets(new Vector3d(0,20,0)) + .SetRotateAngleOffsets(new Vector3d(0,0,0)) + .SetRotateVelocity(0.7) .AdhereToGravity(true); public Aeroplane(EntityType Type, World WorldIn) { @@ -31,6 +36,15 @@ public class Aeroplane extends VehicleBaseEntity { new VehicleCameraPreset(new Vector3f(0,0,4.5f), new Vector3f(0,0,0),70,60)); SetFloatDataValue("PROPELLER_ROTATION_SPEED",(float)(Math.random() * 40)); + GetVehicleController().AddInputFunction("Forward",0.029f, new Vector3d(1,90,1), InputCategory.MoveForward); + GetVehicleController().AddInputFunction("Backward",0.049f, new Vector3d(1,90,1), InputCategory.MoveBackward); + GetVehicleController().AddInputFunction("StrafeLeft",0.049f, new Vector3d(1,90,1), InputCategory.StrafeLeft); + GetVehicleController().AddInputFunction("StrafeRight",0.049f, new Vector3d(1,90,1), InputCategory.StrafeRight); + + GetVehicleController().AddInputFunction("GearShiftUp",()-> SetFloatDataValue("ORIENTATION_ROLL", GetFloatDataValue("ORIENTATION_ROLL") + 5)); + GetVehicleController().AddInputFunction("GearShiftDown",()-> SetFloatDataValue("ORIENTATION_ROLL", GetFloatDataValue("ORIENTATION_ROLL") - 5)); + GetVehicleController().AddInputFunction("TurnLeft",()-> SetFloatDataValue("ORIENTATION_YAW", GetFloatDataValue("ORIENTATION_YAW") + 5)); + GetVehicleController().AddInputFunction("TurnRight",()-> SetFloatDataValue("ORIENTATION_YAW", GetFloatDataValue("ORIENTATION_YAW") - 5)); } @Override diff --git a/src/main/java/net/halbear/hvf/UsageExamples/Aeroplane/Renderer/AeroplaneRenderer.java b/src/main/java/net/halbear/hvf/UsageExamples/Aeroplane/Renderer/AeroplaneRenderer.java index a6008ed..731d78c 100644 --- a/src/main/java/net/halbear/hvf/UsageExamples/Aeroplane/Renderer/AeroplaneRenderer.java +++ b/src/main/java/net/halbear/hvf/UsageExamples/Aeroplane/Renderer/AeroplaneRenderer.java @@ -6,6 +6,7 @@ import net.halbear.hvf.Halsvehicleframework; import net.halbear.hvf.UsageExamples.Aeroplane.Renderer.Models.AeroplaneModel; import net.halbear.hvf.Entity.Renderer.VehicleBaseRenderer; import net.halbear.hvf.UsageExamples.Aeroplane.Renderer.Models.DamagedPlane; +import net.halbear.hvf.UsageExamples.Aeroplane.Renderer.Models.Updatedbiplane; import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.entity.model.EntityModel; @@ -16,18 +17,8 @@ import net.minecraftforge.api.distmarker.OnlyIn; public class AeroplaneRenderer extends VehicleBaseRenderer { public AeroplaneRenderer(EntityRendererManager renderManagerIn) { - super(renderManagerIn, new EntityModel[]{new AeroplaneModel()},"textures/entities/biplaneupdated.png", Halsvehicleframework.MOD_ID); + super(renderManagerIn, new EntityModel[]{new Updatedbiplane()},"textures/entities/biplaneupdated.png", Halsvehicleframework.MOD_ID); AddRendererState("DAMAGED",new EntityModel[]{new DamagedPlane()}); AddRendererState("SUPER_DAMAGED",new EntityModel[]{new DamagedPlane()},"textures/entities/biplaneupdated_DAMAGED.png"); } - - @Override - public void EventBeforeRender(VehicleBaseEntity entity, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight){ - - } - - @Override - public void EventAfterRender(VehicleBaseEntity entity, float entityYaw, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int packedLight){ - - } } diff --git a/src/main/java/net/halbear/hvf/UsageExamples/Airboat/Airboat.java b/src/main/java/net/halbear/hvf/UsageExamples/Airboat/Airboat.java index 4edfc4f..ca7c8e7 100644 --- a/src/main/java/net/halbear/hvf/UsageExamples/Airboat/Airboat.java +++ b/src/main/java/net/halbear/hvf/UsageExamples/Airboat/Airboat.java @@ -21,9 +21,9 @@ public class Airboat extends VehicleBaseEntity { .SetGasCelCount(8) .SetGasCelCapacity(1000) .SetCentreOfMass(new Vector3d(0,0,1)) - .SetPilotSeat(new Vector3d(0.0D, -2D, 0.0D)) - .AddPassengerSeat(new Vector3d(0.0D, -2D, 2.0D)) - .AddPassengerSeat(new Vector3d(0.0D, -2D, -2.0D)); + .SetPilotSeat(new Vector3d(0.0D, -1D, 0.0D)) + .AddPassengerSeat(new Vector3d(0.0D, -1D, 2.0D)) + .AddPassengerSeat(new Vector3d(0.0D, -1D, -2.0D)); public Airboat(EntityType Type, World WorldIn) { super(Type, WorldIn, buildInfo); diff --git a/src/main/java/net/halbear/hvf/Util/Client/VehicleCameraSettings.java b/src/main/java/net/halbear/hvf/Util/Client/VehicleCameraSettings.java index bc873a0..2a54af3 100644 --- a/src/main/java/net/halbear/hvf/Util/Client/VehicleCameraSettings.java +++ b/src/main/java/net/halbear/hvf/Util/Client/VehicleCameraSettings.java @@ -19,7 +19,7 @@ public class VehicleCameraSettings { private static EntityType CurrentEntity; private static boolean HvfVehicle = false; public static Vector3f GetCameraOffsets(){ - return CurrentPreset.GetCameraOffsets(); + return CurrentPreset == null ? null : CurrentPreset.GetCameraOffsets(); } public static Map, VehicleCameraPreset> CameraPresets = new HashMap<>(); diff --git a/src/main/java/net/halbear/hvf/Util/Math/CommonFunctions.java b/src/main/java/net/halbear/hvf/Util/Math/CommonFunctions.java new file mode 100644 index 0000000..c29eabe --- /dev/null +++ b/src/main/java/net/halbear/hvf/Util/Math/CommonFunctions.java @@ -0,0 +1,37 @@ +package net.halbear.hvf.Util.Math; + +import net.halbear.hvf.Util.Math.ExtendedVectors.Vector3; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.vector.Vector3f; + +public class CommonFunctions { + + public static Vector3d RotateIn3dSpaceFromOrigin(Vector3d Point, Vector3d Origin, double YawRad, double PitchRad, double RollRad){ + Vector3d relativeOffset = Point.subtract(Origin); + + double CosYaw = Math.cos(YawRad); + double SinYaw = Math.sin(YawRad); + double CosPitch = Math.cos(PitchRad); + double SinPitch = Math.sin(PitchRad); + double CosRoll = Math.cos(RollRad); + double SinRoll = Math.sin(RollRad); + + Vector3d Forward = new Vector3d(SinYaw * CosPitch, -SinPitch, CosYaw * CosPitch); + + Vector3d Up = new Vector3d( + -CosYaw * SinRoll + SinYaw * SinPitch * CosRoll, + CosPitch * CosRoll, + SinYaw * SinRoll + CosYaw * SinPitch * CosRoll + ); + + Vector3d Right = new Vector3d(Forward.x,Forward.y,Forward.z); + Right.crossProduct(Up); + + Vector3d Rotated = new Vector3d( + (Right.getX() * relativeOffset.x) + (Up.getX() * relativeOffset.y) + (Forward.getX() * relativeOffset.z), + (Right.getY() * relativeOffset.x) + (Up.getY() * relativeOffset.y) + (Forward.getY() * relativeOffset.z), + (Right.getZ() * relativeOffset.x) + (Up.getZ() * relativeOffset.y) + (Forward.getZ() * relativeOffset.z)); + return Rotated.add(Origin); + } +} 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 new file mode 100644 index 0000000..d4cf659 --- /dev/null +++ b/src/main/java/net/halbear/hvf/Util/Math/ExtendedVectors/Vector3.java @@ -0,0 +1,150 @@ +package net.halbear.hvf.Util.Math.ExtendedVectors; + +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.vector.Vector3f; +import net.minecraft.util.math.vector.Vector3i; +import org.lwjgl.system.CallbackI; + +public class Vector3 { + public double x, y, z; + + public Vector3(double x, double y, double z){ + this.x = x; + this.y = y; + this.z = z; + } + + public Vector3(Vector3d vectorIn) { + this.x = vectorIn.x; + this.y = vectorIn.y; + this.z = vectorIn.z; + } + + public double GetX(){return x;} + public double GetY(){return y;} + public double GetZ(){return z;} + public float GetXF(){return (float)x;} + public float GetYF(){return (float)y;} + public float GetZF(){return (float)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()); + } + public static Vector3f Positive(Vector3f in){ + return new Vector3f(in.getX() < 0 ? -in.getX(): in.getX(),in.getY() < 0 ? -in.getY() : in.getY(),in.getZ() < 0 ? -in.getZ() : in.getZ()); + } + public static Vector3d Positive(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 Vector3 Positive(Vector3 in){ + return new Vector3(in.x < 0 ? -in.x : in.x,in.y < 0 ? -in.y : in.y,in.z < 0 ? -in.z : in.z); + } + public Vector3 Positive(){ + return new Vector3(x < 0 ? -x : x,y < 0 ? -y : y,z < 0 ? -z : z); + } + + public static Vector3i Lerp(Vector3i a,Vector3i b, int t){ + return new Vector3i(MathHelper.lerp(t,a.getX(),b.getX()),MathHelper.lerp(t,a.getY(),b.getY()),MathHelper.lerp(t,a.getZ(),b.getZ())); + } + public static Vector3f Lerp(Vector3f a,Vector3f b, float t){ + return new Vector3f(MathHelper.lerp(t,a.getX(),b.getX()),MathHelper.lerp(t,a.getY(),b.getY()),MathHelper.lerp(t,a.getZ(),b.getZ())); + } + public static Vector3d Lerp(Vector3d a,Vector3d b, double t){ + return new Vector3d(MathHelper.lerp(t,a.x,b.x),MathHelper.lerp(t,a.y,b.y),MathHelper.lerp(t,a.z,b.z)); + } + public static Vector3 Lerp(Vector3 a,Vector3 b, double t){ + return new Vector3(MathHelper.lerp(t,a.x,b.x),MathHelper.lerp(t,a.y,b.y),MathHelper.lerp(t,a.z,b.z)); + } + public Vector3 Lerp(Vector3 b, double t){ + return new Vector3(MathHelper.lerp(t,x,b.x),MathHelper.lerp(t,y,b.y),MathHelper.lerp(t,z,b.z)); + } + + public static Vector3 Clamp(double MaxX, double MaxY, double MaxZ,double MinX, double MinY, double MinZ, Vector3 vectorIn){ + return new Vector3( Math.min(Math.max(vectorIn.x, MaxX),MinX), Math.min(Math.max(vectorIn.y, MaxY),MinY), Math.min(Math.max(vectorIn.z, MaxZ),MinZ)); + } + public static Vector3f Clamp(float MaxX, float MaxY, float MaxZ,float MinX, float MinY, float MinZ, Vector3f vectorIn){ + return new Vector3f( Math.min(Math.max(vectorIn.getX(), MaxX),MinX), Math.min(Math.max(vectorIn.getY(), MaxY),MinY), Math.min(Math.max(vectorIn.getZ(), MaxZ),MinZ)); + } + public static Vector3i Clamp(int MaxX, int MaxY, int MaxZ,int MinX, int MinY, int MinZ, Vector3i vectorIn){ + return new Vector3i( Math.min(Math.max(vectorIn.getX(), MaxX),MinX), Math.min(Math.max(vectorIn.getY(), MaxY),MinY), Math.min(Math.max(vectorIn.getZ(), MaxZ),MinZ)); + } + public static Vector3d Clamp(double MaxX, double MaxY, double MaxZ,double MinX, double MinY, double MinZ, Vector3d vectorIn){ + return new Vector3d( Math.min(Math.max(vectorIn.x, MaxX),MinX), Math.min(Math.max(vectorIn.y, MaxY),MinY), Math.min(Math.max(vectorIn.z, MaxZ),MinZ)); + } + public void Clamp(double MaxX, double MaxY, double MaxZ,double MinX, double MinY, double MinZ){ + this.x = Math.min(Math.max(this.x, MaxX),MinX); + this.y = Math.min(Math.max(this.y, MaxY),MinY); + this.z = Math.min(Math.max(this.z, MaxZ),MinZ); + } + + public static Vector3d Max(double MaxX, double MaxY, double MaxZ, Vector3d vectorIn){ + return new Vector3d(Math.max(vectorIn.x, MaxX),Math.max(vectorIn.y, MaxY),Math.max(vectorIn.z, MaxZ)); + } + public static Vector3i Max(int MaxX, int MaxY, int MaxZ, Vector3i vectorIn){ + return new Vector3i(Math.max(vectorIn.getX(), MaxX),Math.max(vectorIn.getY(), MaxY),Math.max(vectorIn.getZ(), MaxZ)); + } + public static Vector3f Max(float MaxX, float MaxY, float MaxZ, Vector3f vectorIn){ + return new Vector3f(Math.max(vectorIn.getX(), MaxX),Math.max(vectorIn.getY(), MaxY),Math.max(vectorIn.getZ(), MaxZ)); + } + public static Vector3 Max(double MaxX, double MaxY, double MaxZ, Vector3 vectorIn){ + return new Vector3(Math.max(vectorIn.x, MaxX),Math.max(vectorIn.y, MaxY),Math.max(vectorIn.z, MaxZ)); + } + public void Max(double MaxX, double MaxY, double MaxZ){ + this.x = Math.max(this.x, MaxX); + this.y = Math.max(this.y, MaxY); + this.z = Math.max(this.z, MaxZ); + } + public static Vector3d Min(double MinX, double MinY, double MinZ, Vector3d vectorIn){ + return new Vector3d(Math.min(vectorIn.x, MinX),Math.min(vectorIn.y, MinY),Math.min(vectorIn.z, MinZ)); + } + public static Vector3i Min(int MinX, int MinY, int MinZ, Vector3i vectorIn){ + return new Vector3i(Math.min(vectorIn.getX(), MinX),Math.min(vectorIn.getY(), MinY),Math.min(vectorIn.getZ(), MinZ)); + } + public static Vector3f Min(float MinX, float MinY, float MinZ, Vector3f vectorIn){ + return new Vector3f(Math.min(vectorIn.getX(), MinX),Math.min(vectorIn.getY(), MinY),Math.min(vectorIn.getZ(), MinZ)); + } + public static Vector3 Min(double MinX, double MinY, double MinZ, Vector3 vectorIn){ + return new Vector3(Math.min(vectorIn.x, MinX),Math.min(vectorIn.y, MinY),Math.min(vectorIn.z, MinZ)); + } + public void Min(double MinX, double MinY, double MinZ){ + this.x = Math.min(this.x, MinX); + this.y = Math.min(this.y, MinY); + this.z = Math.min(this.z, MinZ); + } + + public Vector3 Set(Vector3 VectorIn){ + this.x = VectorIn.x; + this.y = VectorIn.y; + this.z = VectorIn.z; + return this; + } + public Vector3 Set(Vector3d VectorIn){ + this.x = VectorIn.x; + this.y = VectorIn.y; + this.z = VectorIn.z; + return this; + } + public Vector3 Set(Vector3f VectorIn){ + this.x = VectorIn.getX(); + this.y = VectorIn.getY(); + this.z = VectorIn.getZ(); + return this; + } + public Vector3 Set(Vector3i VectorIn){ + this.x = VectorIn.getX(); + this.y = VectorIn.getY(); + this.z = VectorIn.getZ(); + return this; + } + + public Vector3f GetFloat(){ + return new Vector3f((float)x,(float)y,(float)z); + } + public Vector3d GetDouble(){ + return new Vector3d(x,y,z); + } + public Vector3i GetInt(){ + return new Vector3i((int)x,(int)y,(int)z); + } +} diff --git a/src/main/java/net/halbear/hvf/Util/Mixin/CameraMixin.java b/src/main/java/net/halbear/hvf/Util/Mixin/CameraMixin.java index 0f17a9c..e2fe186 100644 --- a/src/main/java/net/halbear/hvf/Util/Mixin/CameraMixin.java +++ b/src/main/java/net/halbear/hvf/Util/Mixin/CameraMixin.java @@ -18,10 +18,6 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.Arrays; - -import static net.halbear.hvf.Registry.ModEntityTags.doesEntityHaveCameraPreset; import static net.halbear.hvf.Util.Client.VehicleCameraSettings.GetCameraOffsets; @Mixin(ActiveRenderInfo.class) @@ -29,10 +25,9 @@ public abstract class CameraMixin { @Inject(method = {"update", "func_216772_a","setup"}, at = @At(value = "TAIL"),cancellable = true, remap = true) private void update(IBlockReader currentRenderedLevel, Entity entity, boolean isDetached, boolean isMirrored, float partialTicks, CallbackInfo ci){ if(entity.isPassenger() && Minecraft.getInstance().gameSettings.getPointOfView() != PointOfView.FIRST_PERSON) { - //ITag> myEntityTag = EntityTypeTags.getTagById(new ResourceLocation("forge", "hvf_camera_affected_vehicle").toString()); - boolean entityHaveCameraPreset = entity.getRidingEntity() instanceof VehicleBaseEntity;//myEntityTag.contains(entity.getRidingEntity().getType()); + boolean entityHaveCameraPreset = entity.getRidingEntity() instanceof VehicleBaseEntity; if (entityHaveCameraPreset) { - Vector3f Position = GetCameraOffsets(); + Vector3f Position = GetCameraOffsets() != null ? GetCameraOffsets() : new Vector3f(0,0,0); this.movePosition(-this.calcCameraDistance(Position.getZ()), Position.getY(), Position.getX()); } } diff --git a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java index f5915c0..c02f385 100644 --- a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java @@ -1,5 +1,7 @@ package net.halbear.hvf.Util.VehicleData; +import net.halbear.hvf.Entity.Renderer.PivotOrigin; +import net.halbear.hvf.Util.Math.ExtendedVectors.Vector3; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.util.math.vector.Vector3f; @@ -23,19 +25,62 @@ public class VehicleBuildInfo { private List BuiltInVehicleInputActions = new ArrayList<>(); private List PassengerSeats = new ArrayList<>(); private List FuelTanks = new ArrayList<>(); - private Vector3d AtRestAngleOffsets; - private Vector3d AtSpeedOnGroundAngleOffsets; + private Vector3d AtRestAngleOffsets = new Vector3d(0,0,0); + private Vector3d AtSpeedOnGroundAngleOffsets = new Vector3d(0,0,0); private double RotationVelocity = 1.2; + private float StepHeight = 1.0f; + private PivotOrigin OriginType = PivotOrigin.RelativeToEntityCenter; + private Vector3d OriginOffset = new Vector3d(0,0,0); private PhysicsPreset physicsPreset = PhysicsPreset.AdvancedMinecraft; + public VehicleBuildInfo SetOrigin(PivotOrigin OriginType, Vector3d OriginOffset){ + this.OriginType = OriginType; + this.OriginOffset = OriginOffset; + return this; + } + public VehicleBuildInfo SetOriginType(PivotOrigin OriginType){ + this.OriginType = OriginType; + return this; + } + public PivotOrigin GetOriginType(){return OriginType;} + public Vector3d GetOriginOffset(){return OriginOffset;} + public VehicleBuildInfo SetOriginOffset(Vector3d OriginOffset){ + this.OriginOffset = OriginOffset; + return this; + } + public VehicleBuildInfo SetPhysicsPreset(PhysicsPreset newPreset){ this.physicsPreset = newPreset; return this; } + + public VehicleBuildInfo SetStepHeight(float StepHeight){ + this.StepHeight = StepHeight; + return this; + } + public float GetStepHeight(){return StepHeight;} + + public PhysicsPreset GetPhysicsPreset(){return physicsPreset;} + + public VehicleBuildInfo SetRotateAngleOffsets(Vector3d AtSpeedOnGroundAngleOffsets){ + this.AtSpeedOnGroundAngleOffsets = AtSpeedOnGroundAngleOffsets; + return this; + } + + public Vector3d GetRotateAngleOffsets(){return AtSpeedOnGroundAngleOffsets;} + + public VehicleBuildInfo SetAtRestAngleOffsets(Vector3d AtRestAngleOffsets){ + this.AtRestAngleOffsets = AtRestAngleOffsets; + return this; + } + + public Vector3d GetAtRestAngleOffsets(){return AtRestAngleOffsets;} + public VehicleBuildInfo SetRotateVelocity(double VelocityIn){ this.RotationVelocity = VelocityIn; return this; } + public double GetRotateVelocity(){return RotationVelocity;} public VehicleBuildInfo RegisterInputAction(String ActionName){ BuiltInVehicleInputActions.add(ActionName); 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 7f584fc..edda321 100644 --- a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleController.java +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleController.java @@ -1,8 +1,12 @@ package net.halbear.hvf.Util.VehicleData; +import net.halbear.hvf.Entity.Renderer.VehicleAnimationManager; +import net.halbear.hvf.Entity.Renderer.VehicleBaseRenderer; import net.halbear.hvf.Entity.VehicleBaseEntity; import net.halbear.hvf.Registry.Input.InputCategory; import net.halbear.hvf.Registry.Input.InputManager; +import net.halbear.hvf.Util.Math.ExtendedVectors.Vector3; +import net.minecraft.util.math.vector.Vector3d; import java.util.HashMap; import java.util.Map; @@ -12,7 +16,7 @@ import java.util.function.Supplier; public class VehicleController { @FunctionalInterface - interface Action { + public interface Action { void execute(); } @@ -36,8 +40,56 @@ public class VehicleController { } } } - public VehicleController AddInputFunction(String Input, String VariableName, InputCategory functionType){ - + 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()))))); + 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()))))); + 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()))))); + 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()))))); + break; + } + return this; + } + public VehicleController AddInputFunction(String Input, String VariableName, float ChangeAmount, InputCategory functionType){ + switch(functionType){ + case Accelerate: + break; + case Brake: + break; + case TurnLeft: + break; + case TurnRight: + break; + case PressClutch: + break; + case ShiftGearUp: + break; + case ShiftGearDown: + break; + case ThrottleUp: + break; + case ThrottleDown: + break; + case PitchUp: + break; + case PitchDown: + break; + case YawLeft: + break; + case YawRight: + break; + case RollLeft: + break; + case RollRight: + break; + } return this; } }