From b1d5563a392cf72139ca061722caf757db8cec66 Mon Sep 17 00:00:00 2001 From: Halbear Date: Sun, 31 May 2026 21:00:15 +0100 Subject: [PATCH] starting work on Input Manager --- .../halbear/hvf/Entity/VehicleBaseEntity.java | 42 +++++++++--------- .../EventHandlers/ModEventHandler.java | 5 ++- .../hvf/Registry/Input/InputCategory.java | 30 +++++++++++++ .../hvf/Registry/Input/InputManager.java | 1 + .../hvf/Registry/Input/ModKeybinds.java | 7 +++ .../Util/VehicleData/VehicleBuildInfo.java | 11 +++++ .../Util/VehicleData/VehicleController.java | 43 +++++++++++++++++++ 7 files changed, 118 insertions(+), 21 deletions(-) create mode 100644 src/main/java/net/halbear/hvf/Registry/Input/InputCategory.java create mode 100644 src/main/java/net/halbear/hvf/Util/VehicleData/VehicleController.java diff --git a/src/main/java/net/halbear/hvf/Entity/VehicleBaseEntity.java b/src/main/java/net/halbear/hvf/Entity/VehicleBaseEntity.java index 290b254..fafe025 100644 --- a/src/main/java/net/halbear/hvf/Entity/VehicleBaseEntity.java +++ b/src/main/java/net/halbear/hvf/Entity/VehicleBaseEntity.java @@ -5,6 +5,7 @@ import net.halbear.hvf.Registry.Input.InputManager; import net.halbear.hvf.Util.VehicleData.EngineCategories; import net.halbear.hvf.Util.VehicleData.VehicleBuildInfo; import net.halbear.hvf.Util.VehicleData.VehicleClassification; +import net.halbear.hvf.Util.VehicleData.VehicleController; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.player.PlayerEntity; @@ -17,7 +18,6 @@ import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; @@ -39,6 +39,7 @@ public class VehicleBaseEntity extends Entity { private EngineCategories EngineType; 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;} @@ -47,8 +48,13 @@ public class VehicleBaseEntity extends Entity { public Vector3d GetPilotSeat(){return VehicleSeatOffsets.length > 0 ? VehicleSeatOffsets[0] : new Vector3d(0,0,0);} + public VehicleController GetVehicleController(){ + return Controller; + } + public VehicleBaseEntity(EntityType entityTypeIn, World worldIn, VehicleBuildInfo vehicleBuildInfo) { super(entityTypeIn, worldIn); + Controller = new VehicleController(this); this.setNoGravity(vehicleBuildInfo.GetAdheresToGravity()); List VehicleSeats = new ArrayList(); VehicleSeats.add(vehicleBuildInfo.GetPilotSeat()); @@ -71,7 +77,8 @@ public class VehicleBaseEntity extends Entity { BASE_FLOAT_PARAMETERS.put("PROPELLER_ROTATION",PropRotation); BASE_FLOAT_PARAMETERS.put("TARGET_PROPELLER_ROTATION",PropRotation); BASE_FLOAT_PARAMETERS.put("PROPELLER_ROTATION_SPEED",0F); - BASE_FLOAT_PARAMETERS.put("MAX_ENGINE_RPM",(float)vehicleBuildInfo.GetMaxEngineRPM()); + BASE_FLOAT_PARAMETERS.put("ENGINE_RPM",(0f)); + BASE_FLOAT_PARAMETERS.put("MAX_ENGINE_RPM",vehicleBuildInfo.GetMaxEngineRPM()); BASE_INT_PARAMETERS.put("THROTTLE",0); BASE_INT_PARAMETERS.put("FUEL_TANK_COUNT",vehicleBuildInfo.GetFuelTanks().size()); for(int i = 0; i < vehicleBuildInfo.GetFuelTanks().size(); i++){ @@ -207,10 +214,6 @@ public class VehicleBaseEntity extends Entity { return null; } - public void OnPunchedEvent(){ - - } - @Override protected void registerData() { this.dataManager.register(VEHICLE_SYNCHED_PARAMETERS, new CompoundNBT()); @@ -238,6 +241,7 @@ public class VehicleBaseEntity extends Entity { this.LastPositionVector = CurrentPositionVector; CurrentPositionVector = getPositionVec(); super.tick(); + Controller.PollInputs(GetByteArrayValue("INPUT_DATA")); if(GetBooleanDataValue("ADHERES_TO_GRAVITY")){ if (!this.isOnGround()) { this.setMotion(this.getMotion().add(0, -GetDoubleDataValue("GRAVITY"), 0)); @@ -284,14 +288,13 @@ public class VehicleBaseEntity extends Entity { } } } - if(!this.getPassengers().isEmpty()){ - //PlayerEntity player = (PlayerEntity) this.getControllingPassenger(); - //player.sendMessage(new StringTextComponent(GetFloatDataValue("ORIENTATION_PITCH") + ""),player.getUniqueID()); - } + SubClassTickUpdateEvent(); TickUpdateEvent(); if(this.world.isRemote()){ + SubClassServerSideTickEvent(); ClientSideTickEvent(); } else{ + SubClassClientSideTickEvent(); ServerSideTickEvent(); } } @@ -300,17 +303,16 @@ public class VehicleBaseEntity extends Entity { this.setMotion(this.getMotion().add(dx,dy,dz)); } - public void ServerSideTickEvent(){ + public void OnPunchedEvent(){} + public void ServerSideTickEvent(){} + public void ClientSideTickEvent(){} + public void TickUpdateEvent() {} - } - - public void ClientSideTickEvent(){ - - } - - public void TickUpdateEvent() { - - } + //Sub Class Events + public void SubClassOnPunchedEvent(){} + public void SubClassServerSideTickEvent(){} + public void SubClassClientSideTickEvent(){} + public void SubClassTickUpdateEvent() {} @Override public boolean canBeCollidedWith(){return true;} 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 daa9845..589081f 100644 --- a/src/main/java/net/halbear/hvf/Registry/EventHandlers/ModEventHandler.java +++ b/src/main/java/net/halbear/hvf/Registry/EventHandlers/ModEventHandler.java @@ -44,7 +44,10 @@ public class ModEventHandler { PlayerEntity player = event.getPlayer(); Entity Vehicle = event.getTarget(); if (player.world.isRemote()) { return; } - if (Vehicle instanceof VehicleBaseEntity) {((VehicleBaseEntity) Vehicle).OnPunchedEvent();} + if (Vehicle instanceof VehicleBaseEntity) { + ((VehicleBaseEntity) Vehicle).OnPunchedEvent(); + ((VehicleBaseEntity) Vehicle).SubClassOnPunchedEvent(); + } } } diff --git a/src/main/java/net/halbear/hvf/Registry/Input/InputCategory.java b/src/main/java/net/halbear/hvf/Registry/Input/InputCategory.java new file mode 100644 index 0000000..448e5fb --- /dev/null +++ b/src/main/java/net/halbear/hvf/Registry/Input/InputCategory.java @@ -0,0 +1,30 @@ +package net.halbear.hvf.Registry.Input; + +public enum InputCategory { + MoveForward, + MoveBackward, + StrafeLeft, + StrafeRight, + Accelerate, + Brake, + TurnLeft, + TurnRight, + PressClutch, + ShiftGearUp, + ShiftGearDown, + ResetGearToNeutral, + ThrottleUp, + ThrottleDown, + PitchUp, + PitchDown, + RollLeft, + RollRight, + YawLeft, + YawRight, + EngineStart, + IterativeEngineStart, + IncreaseReverser, + DecreaseReverser, + IncreaseRegulator, + DecreaseRegulator +} 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 136c029..bdda0e0 100644 --- a/src/main/java/net/halbear/hvf/Registry/Input/InputManager.java +++ b/src/main/java/net/halbear/hvf/Registry/Input/InputManager.java @@ -54,6 +54,7 @@ public class InputManager { KEY_BINDING_MAP.put(ModKeybinds.CLUTCH_KEY, "ClutchToggle"); KEY_BINDING_MAP.put(ModKeybinds.GEAR_UP_KEY, "GearShiftUp"); KEY_BINDING_MAP.put(ModKeybinds.GEAR_DOWN_KEY, "GearShiftDown"); + KEY_BINDING_MAP.put(ModKeybinds.GEAR_NEUTRAL_KEY, "GearResetNeutral"); 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 915b74d..04be946 100644 --- a/src/main/java/net/halbear/hvf/Registry/Input/ModKeybinds.java +++ b/src/main/java/net/halbear/hvf/Registry/Input/ModKeybinds.java @@ -88,5 +88,12 @@ public class ModKeybinds { GLFW.GLFW_KEY_DOWN, "key.categories.land_vehicle_controls" ); + public static KeyBinding GEAR_NEUTRAL_KEY = new KeyBinding( + "key.hals_vehicle_framework.reset_gear_to_neutral", + KeyConflictContext.IN_GAME, + InputMappings.Type.KEYSYM, + GLFW.GLFW_KEY_N, + "key.categories.land_vehicle_controls" + ); } 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 a5d04c3..f5915c0 100644 --- a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java @@ -25,6 +25,17 @@ public class VehicleBuildInfo { private List FuelTanks = new ArrayList<>(); private Vector3d AtRestAngleOffsets; private Vector3d AtSpeedOnGroundAngleOffsets; + private double RotationVelocity = 1.2; + private PhysicsPreset physicsPreset = PhysicsPreset.AdvancedMinecraft; + + public VehicleBuildInfo SetPhysicsPreset(PhysicsPreset newPreset){ + this.physicsPreset = newPreset; + return this; + } + public VehicleBuildInfo SetRotateVelocity(double VelocityIn){ + this.RotationVelocity = VelocityIn; + return this; + } 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 new file mode 100644 index 0000000..7f584fc --- /dev/null +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleController.java @@ -0,0 +1,43 @@ +package net.halbear.hvf.Util.VehicleData; + +import net.halbear.hvf.Entity.VehicleBaseEntity; +import net.halbear.hvf.Registry.Input.InputCategory; +import net.halbear.hvf.Registry.Input.InputManager; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; + +public class VehicleController { + + @FunctionalInterface + interface Action { + void execute(); + } + + private final T Parent; + private final Map Inputs = new HashMap<>(); + + public VehicleController(T parentEntity){ + Parent = parentEntity; + } + public VehicleController AddInputFunction(Byte Input, Action function){ + Inputs.put(Input, function); + return this; + } + public VehicleController AddInputFunction(String Input, Action function){ + return AddInputFunction(InputManager.INPUT_BYTE_VALUES.get(Input),function); + } + public void PollInputs(byte[] InputArray){ + for(int i = 0; i < InputArray.length; i++){ + if(Inputs.containsKey(InputArray[i])){ + Inputs.get(InputArray[i]).execute(); + } + } + } + public VehicleController AddInputFunction(String Input, String VariableName, InputCategory functionType){ + + return this; + } +}