fixed incorrect input mappings for server players

This commit is contained in:
Halbear
2026-06-03 20:01:41 +01:00
parent 77741a3b37
commit 9364965e68
5 changed files with 78 additions and 28 deletions
@@ -285,7 +285,6 @@ public class VehicleBaseEntity extends Entity {
Controller.PollInputs(GetByteArrayValue("INPUT_DATA")); Controller.PollInputs(GetByteArrayValue("INPUT_DATA"));
SubClassTickUpdateEvent(); SubClassTickUpdateEvent();
TickUpdateEvent(); TickUpdateEvent();
SetBooleanDataValue("ON_GROUND",Math.abs(CurrentPositionVector.y - LastPositionVector.y) < 0.05D);
if(this.world.isRemote()){ if(this.world.isRemote()){
SubClassClientSideTickEvent(); SubClassClientSideTickEvent();
ClientSideTickEvent(); ClientSideTickEvent();
@@ -319,6 +318,7 @@ public class VehicleBaseEntity extends Entity {
public boolean TouchingGround(){return GetBooleanDataValue("ON_GROUND");} public boolean TouchingGround(){return GetBooleanDataValue("ON_GROUND");}
public void PhysicsTick(boolean ServerSided){ public void PhysicsTick(boolean ServerSided){
if(ServerSided) SetBooleanDataValue("ON_GROUND",Math.abs(CurrentPositionVector.y - LastPositionVector.y) < 0.05D);
VehicleVelocity = new Vector3(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z")); VehicleVelocity = new Vector3(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z"));
Vector3d Velocity = Vector3.Positive(VehicleVelocity).GetDouble(); Vector3d Velocity = Vector3.Positive(VehicleVelocity).GetDouble();
Vector3d NormalisedVelocity = Velocity.normalize(); Vector3d NormalisedVelocity = Velocity.normalize();
@@ -0,0 +1,9 @@
package net.halbear.hvf.Entity;
public class VehicleEntityState {
private double BaseRotationX = 0.0d;
private double BaseRotationY = 0.0d;
private double BaseRotationZ = 0.0d;
private String StateName = "DEFAULT";
}
@@ -14,7 +14,7 @@ public class InputHandler {
@SubscribeEvent @SubscribeEvent
public static void onKeyInput(InputEvent.KeyInputEvent event) { public static void onKeyInput(InputEvent.KeyInputEvent event) {
List<Byte> PressedKeys = new ArrayList<>(); List<Byte> PressedKeys = new ArrayList<>();
InputManager.KEY_BINDING_MAP.forEach((Binding, Name)->{ InputManager.KEY_BINDING_MAP.forEach((Name,Binding)->{
if(Binding.isKeyDown()){ if(Binding.isKeyDown()){
PressedKeys.add(InputManager.INPUT_BYTE_VALUES.get(Name)); PressedKeys.add(InputManager.INPUT_BYTE_VALUES.get(Name));
} }
@@ -2,6 +2,9 @@ package net.halbear.hvf.Registry.Input;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -11,7 +14,8 @@ import java.util.concurrent.atomic.AtomicReference;
public class InputManager { public class InputManager {
public static final Map<String, Byte> INPUT_BYTE_VALUES = new HashMap<>(); public static final Map<String, Byte> INPUT_BYTE_VALUES = new HashMap<>();
public static final Map<Byte, String> INPUT_BYTE_VALUES_REVERSE_LOOKUP = new HashMap<>(); public static final Map<Byte, String> INPUT_BYTE_VALUES_REVERSE_LOOKUP = new HashMap<>();
public static final Map<KeyBinding, String> KEY_BINDING_MAP = new HashMap<>(); public static final Map<String,KeyBinding> KEY_BINDING_MAP = new HashMap<>();
public static byte Iteration = -128;
public static List<Byte> ActiveKeys = new ArrayList<>(); public static List<Byte> ActiveKeys = new ArrayList<>();
public static List<Byte> LastActiveKeys = new ArrayList<>(); public static List<Byte> LastActiveKeys = new ArrayList<>();
@@ -28,40 +32,57 @@ public class InputManager {
} }
public static void AddBinding(KeyBinding keyBinding, String BindingName){ public static void AddBinding(KeyBinding keyBinding, String BindingName){
KEY_BINDING_MAP.put(keyBinding,BindingName); KEY_BINDING_MAP.put(BindingName,keyBinding);
ReCalculateByteArrays(); INPUT_BYTE_VALUES.put(BindingName, Iteration);
INPUT_BYTE_VALUES_REVERSE_LOOKUP.put(Iteration,BindingName);
Iteration++;
} }
public static void AddBindings(KeyBinding[] keyBinding, String[] BindingName){ public static void AddBindings(KeyBinding[] keyBinding, String[] BindingName){
for(int i = 0; i < (Math.min(keyBinding.length, BindingName.length)); i++) { for(int i = 0; i < (Math.min(keyBinding.length, BindingName.length)); i++) {
KEY_BINDING_MAP.put(keyBinding[i], BindingName[i]); AddBinding(keyBinding[i], BindingName[i]);
} }
ReCalculateByteArrays();
} }
public static void ReCalculateByteArrays(){ public static void ReCalculateByteArrays() {
INPUT_BYTE_VALUES.clear(); StringBuilder Log = new StringBuilder();
INPUT_BYTE_VALUES_REVERSE_LOOKUP.clear(); for(byte i = -128; i <= 126; i++) {
AtomicReference<Byte> Iterator = new AtomicReference<>((byte) -128); if (INPUT_BYTE_VALUES_REVERSE_LOOKUP.containsKey(i)) {
KEY_BINDING_MAP.forEach((Binding, Name )->{ String Name = INPUT_BYTE_VALUES_REVERSE_LOOKUP.get(i);
INPUT_BYTE_VALUES.put(Name, Iterator.get()); KeyBinding Binding = KEY_BINDING_MAP.get(Name);
INPUT_BYTE_VALUES_REVERSE_LOOKUP.put(Iterator.get(), Name); Log.append("\nKEY_BINDING: ").append(Binding.getKey().getTranslationKey()).append(" BINDING_NAME: ").append(Name).append(" BYTE INDICATOR: ").append(INPUT_BYTE_VALUES.get(Name)).append(" STRING_INDICATOR ").append(INPUT_BYTE_VALUES_REVERSE_LOOKUP.get(i));
Iterator.getAndSet((byte) (Iterator.get() + 1)); }
}); }
System.out.println(Log);
File newLogFile;
int Iterations = 0;
do {
newLogFile = new File("F:\\Hals Mod 1.0\\HVF_LOGS\\Log"+Iterations+".txt");
Iterations++;
} while(newLogFile.exists());
if(newLogFile != null ) {
try {
FileWriter FW = new FileWriter(newLogFile);
FW.write(Log.toString());
FW.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
} }
static{ static{
KEY_BINDING_MAP.put(ModKeybinds.FORWARD_KEY, "Forward"); AddBinding(ModKeybinds.FORWARD_KEY, "Forward");
KEY_BINDING_MAP.put(ModKeybinds.BACKWARD_KEY, "Backward"); AddBinding(ModKeybinds.BACKWARD_KEY, "Backward");
KEY_BINDING_MAP.put(ModKeybinds.STRAFE_LEFT_KEY, "StrafeLeft"); AddBinding(ModKeybinds.STRAFE_LEFT_KEY, "StrafeLeft");
KEY_BINDING_MAP.put(ModKeybinds.STRAFE_RIGHT_KEY, "StrafeRight"); AddBinding(ModKeybinds.STRAFE_RIGHT_KEY, "StrafeRight");
KEY_BINDING_MAP.put(ModKeybinds.ACCELERATE_KEY, "Accelerate"); AddBinding(ModKeybinds.ACCELERATE_KEY, "Accelerate");
KEY_BINDING_MAP.put(ModKeybinds.BRAKE_KEY, "Brake"); AddBinding(ModKeybinds.BRAKE_KEY, "Brake");
KEY_BINDING_MAP.put(ModKeybinds.TURN_LEFT_KEY, "TurnLeft"); AddBinding(ModKeybinds.TURN_LEFT_KEY, "TurnLeft");
KEY_BINDING_MAP.put(ModKeybinds.TURN_RIGHT_KEY, "TurnRight"); AddBinding(ModKeybinds.TURN_RIGHT_KEY, "TurnRight");
KEY_BINDING_MAP.put(ModKeybinds.CLUTCH_KEY, "ClutchToggle"); AddBinding(ModKeybinds.CLUTCH_KEY, "ClutchToggle");
KEY_BINDING_MAP.put(ModKeybinds.GEAR_UP_KEY, "GearShiftUp"); AddBinding(ModKeybinds.GEAR_UP_KEY, "GearShiftUp");
KEY_BINDING_MAP.put(ModKeybinds.GEAR_DOWN_KEY, "GearShiftDown"); AddBinding(ModKeybinds.GEAR_DOWN_KEY, "GearShiftDown");
KEY_BINDING_MAP.put(ModKeybinds.GEAR_NEUTRAL_KEY, "GearResetNeutral"); AddBinding(ModKeybinds.GEAR_NEUTRAL_KEY, "GearResetNeutral");
ReCalculateByteArrays(); ReCalculateByteArrays();
} }
} }
@@ -0,0 +1,20 @@
package net.halbear.hvf.Registry.ServerVariables;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.world.storage.WorldSavedData;
public class GlobalInputData extends WorldSavedData {
public GlobalInputData(String name) {
super(name);
}
@Override
public void read(CompoundNBT nbt) {
}
@Override
public CompoundNBT write(CompoundNBT compound) {
return null;
}
}