starting work on Input Manager
This commit is contained in:
@@ -5,6 +5,7 @@ import net.halbear.hvf.Registry.Input.InputManager;
|
|||||||
import net.halbear.hvf.Util.VehicleData.EngineCategories;
|
import net.halbear.hvf.Util.VehicleData.EngineCategories;
|
||||||
import net.halbear.hvf.Util.VehicleData.VehicleBuildInfo;
|
import net.halbear.hvf.Util.VehicleData.VehicleBuildInfo;
|
||||||
import net.halbear.hvf.Util.VehicleData.VehicleClassification;
|
import net.halbear.hvf.Util.VehicleData.VehicleClassification;
|
||||||
|
import net.halbear.hvf.Util.VehicleData.VehicleController;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
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.ActionResultType;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.vector.Vector3d;
|
import net.minecraft.util.math.vector.Vector3d;
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fml.network.NetworkHooks;
|
import net.minecraftforge.fml.network.NetworkHooks;
|
||||||
|
|
||||||
@@ -39,6 +39,7 @@ public class VehicleBaseEntity extends Entity {
|
|||||||
private EngineCategories EngineType;
|
private EngineCategories EngineType;
|
||||||
private Vector3d LastPositionVector = new Vector3d(0,0,0);
|
private Vector3d LastPositionVector = new Vector3d(0,0,0);
|
||||||
private Vector3d CurrentPositionVector = 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 void SetPartialTick(float PartialTick){this.PartialTick = PartialTick;}
|
||||||
public float GetPartialTick(){return 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 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) {
|
public VehicleBaseEntity(EntityType<?> entityTypeIn, World worldIn, VehicleBuildInfo vehicleBuildInfo) {
|
||||||
super(entityTypeIn, worldIn);
|
super(entityTypeIn, worldIn);
|
||||||
|
Controller = new VehicleController(this);
|
||||||
this.setNoGravity(vehicleBuildInfo.GetAdheresToGravity());
|
this.setNoGravity(vehicleBuildInfo.GetAdheresToGravity());
|
||||||
List<Vector3d> VehicleSeats = new ArrayList<Vector3d>();
|
List<Vector3d> VehicleSeats = new ArrayList<Vector3d>();
|
||||||
VehicleSeats.add(vehicleBuildInfo.GetPilotSeat());
|
VehicleSeats.add(vehicleBuildInfo.GetPilotSeat());
|
||||||
@@ -71,7 +77,8 @@ public class VehicleBaseEntity extends Entity {
|
|||||||
BASE_FLOAT_PARAMETERS.put("PROPELLER_ROTATION",PropRotation);
|
BASE_FLOAT_PARAMETERS.put("PROPELLER_ROTATION",PropRotation);
|
||||||
BASE_FLOAT_PARAMETERS.put("TARGET_PROPELLER_ROTATION",PropRotation);
|
BASE_FLOAT_PARAMETERS.put("TARGET_PROPELLER_ROTATION",PropRotation);
|
||||||
BASE_FLOAT_PARAMETERS.put("PROPELLER_ROTATION_SPEED",0F);
|
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("THROTTLE",0);
|
||||||
BASE_INT_PARAMETERS.put("FUEL_TANK_COUNT",vehicleBuildInfo.GetFuelTanks().size());
|
BASE_INT_PARAMETERS.put("FUEL_TANK_COUNT",vehicleBuildInfo.GetFuelTanks().size());
|
||||||
for(int i = 0; i < vehicleBuildInfo.GetFuelTanks().size(); i++){
|
for(int i = 0; i < vehicleBuildInfo.GetFuelTanks().size(); i++){
|
||||||
@@ -207,10 +214,6 @@ public class VehicleBaseEntity extends Entity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPunchedEvent(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerData() {
|
protected void registerData() {
|
||||||
this.dataManager.register(VEHICLE_SYNCHED_PARAMETERS, new CompoundNBT());
|
this.dataManager.register(VEHICLE_SYNCHED_PARAMETERS, new CompoundNBT());
|
||||||
@@ -238,6 +241,7 @@ public class VehicleBaseEntity extends Entity {
|
|||||||
this.LastPositionVector = CurrentPositionVector;
|
this.LastPositionVector = CurrentPositionVector;
|
||||||
CurrentPositionVector = getPositionVec();
|
CurrentPositionVector = getPositionVec();
|
||||||
super.tick();
|
super.tick();
|
||||||
|
Controller.PollInputs(GetByteArrayValue("INPUT_DATA"));
|
||||||
if(GetBooleanDataValue("ADHERES_TO_GRAVITY")){
|
if(GetBooleanDataValue("ADHERES_TO_GRAVITY")){
|
||||||
if (!this.isOnGround()) {
|
if (!this.isOnGround()) {
|
||||||
this.setMotion(this.getMotion().add(0, -GetDoubleDataValue("GRAVITY"), 0));
|
this.setMotion(this.getMotion().add(0, -GetDoubleDataValue("GRAVITY"), 0));
|
||||||
@@ -284,14 +288,13 @@ public class VehicleBaseEntity extends Entity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!this.getPassengers().isEmpty()){
|
SubClassTickUpdateEvent();
|
||||||
//PlayerEntity player = (PlayerEntity) this.getControllingPassenger();
|
|
||||||
//player.sendMessage(new StringTextComponent(GetFloatDataValue("ORIENTATION_PITCH") + ""),player.getUniqueID());
|
|
||||||
}
|
|
||||||
TickUpdateEvent();
|
TickUpdateEvent();
|
||||||
if(this.world.isRemote()){
|
if(this.world.isRemote()){
|
||||||
|
SubClassServerSideTickEvent();
|
||||||
ClientSideTickEvent();
|
ClientSideTickEvent();
|
||||||
} else{
|
} else{
|
||||||
|
SubClassClientSideTickEvent();
|
||||||
ServerSideTickEvent();
|
ServerSideTickEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,17 +303,16 @@ public class VehicleBaseEntity extends Entity {
|
|||||||
this.setMotion(this.getMotion().add(dx,dy,dz));
|
this.setMotion(this.getMotion().add(dx,dy,dz));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ServerSideTickEvent(){
|
public void OnPunchedEvent(){}
|
||||||
|
public void ServerSideTickEvent(){}
|
||||||
|
public void ClientSideTickEvent(){}
|
||||||
|
public void TickUpdateEvent() {}
|
||||||
|
|
||||||
}
|
//Sub Class Events
|
||||||
|
public void SubClassOnPunchedEvent(){}
|
||||||
public void ClientSideTickEvent(){
|
public void SubClassServerSideTickEvent(){}
|
||||||
|
public void SubClassClientSideTickEvent(){}
|
||||||
}
|
public void SubClassTickUpdateEvent() {}
|
||||||
|
|
||||||
public void TickUpdateEvent() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBeCollidedWith(){return true;}
|
public boolean canBeCollidedWith(){return true;}
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ public class ModEventHandler {
|
|||||||
PlayerEntity player = event.getPlayer();
|
PlayerEntity player = event.getPlayer();
|
||||||
Entity Vehicle = event.getTarget();
|
Entity Vehicle = event.getTarget();
|
||||||
if (player.world.isRemote()) { return; }
|
if (player.world.isRemote()) { return; }
|
||||||
if (Vehicle instanceof VehicleBaseEntity) {((VehicleBaseEntity) Vehicle).OnPunchedEvent();}
|
if (Vehicle instanceof VehicleBaseEntity) {
|
||||||
|
((VehicleBaseEntity) Vehicle).OnPunchedEvent();
|
||||||
|
((VehicleBaseEntity) Vehicle).SubClassOnPunchedEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -54,6 +54,7 @@ public class InputManager {
|
|||||||
KEY_BINDING_MAP.put(ModKeybinds.CLUTCH_KEY, "ClutchToggle");
|
KEY_BINDING_MAP.put(ModKeybinds.CLUTCH_KEY, "ClutchToggle");
|
||||||
KEY_BINDING_MAP.put(ModKeybinds.GEAR_UP_KEY, "GearShiftUp");
|
KEY_BINDING_MAP.put(ModKeybinds.GEAR_UP_KEY, "GearShiftUp");
|
||||||
KEY_BINDING_MAP.put(ModKeybinds.GEAR_DOWN_KEY, "GearShiftDown");
|
KEY_BINDING_MAP.put(ModKeybinds.GEAR_DOWN_KEY, "GearShiftDown");
|
||||||
|
KEY_BINDING_MAP.put(ModKeybinds.GEAR_NEUTRAL_KEY, "GearResetNeutral");
|
||||||
ReCalculateByteArrays();
|
ReCalculateByteArrays();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,5 +88,12 @@ public class ModKeybinds {
|
|||||||
GLFW.GLFW_KEY_DOWN,
|
GLFW.GLFW_KEY_DOWN,
|
||||||
"key.categories.land_vehicle_controls"
|
"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"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,17 @@ public class VehicleBuildInfo {
|
|||||||
private List<Float> FuelTanks = new ArrayList<>();
|
private List<Float> FuelTanks = new ArrayList<>();
|
||||||
private Vector3d AtRestAngleOffsets;
|
private Vector3d AtRestAngleOffsets;
|
||||||
private Vector3d AtSpeedOnGroundAngleOffsets;
|
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){
|
public VehicleBuildInfo RegisterInputAction(String ActionName){
|
||||||
BuiltInVehicleInputActions.add(ActionName);
|
BuiltInVehicleInputActions.add(ActionName);
|
||||||
|
|||||||
@@ -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<T extends VehicleBaseEntity> {
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
interface Action {
|
||||||
|
void execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private final T Parent;
|
||||||
|
private final Map<Byte, Action> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user