Starting work on States (separate to render states)
States are presets of level rotation and functionality
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package net.halbear.hvf.Entity.Renderer;
|
||||
|
||||
public enum Angle {
|
||||
ANGLE_0,
|
||||
ANGLE_90,
|
||||
ANGLE_180,
|
||||
ANGLE_270,
|
||||
ANGLE_360
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package net.halbear.hvf.Entity.Renderer;
|
||||
|
||||
public enum TransitionType {
|
||||
LinearInterpolate,
|
||||
InstantTransition
|
||||
}
|
||||
@@ -91,10 +91,7 @@ public class VehicleBaseRenderer<T extends VehicleBaseEntity, M extends EntityMo
|
||||
EventBeforeRender(entity, entityYaw, partialTicks, matrixStack, buffer, packedLight);
|
||||
Vector3d OriginPosition = new Vector3d(0,0,0).add(OriginOffset);
|
||||
Vector3f RotationsToAdd = new Vector3f(-entity.GetFloatDataValue("ADD_ORIENTATION_YAW_NEXT_TICK") * partialTicks,entity.GetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK") * partialTicks,entity.GetFloatDataValue("ADD_ORIENTATION_ROLL_NEXT_TICK") * partialTicks);
|
||||
Vector3 Offsets = entity.TouchingGround() ? new Vector3(entity.GetDoubleDataValue("ANGLE_OFFSET_YAW"),entity.GetDoubleDataValue("ANGLE_OFFSET_PITCH"),entity.GetDoubleDataValue("ANGLE_OFFSET_ROLL")) : new Vector3(0,0,0);
|
||||
float PitchModifier = (float)Math.cos(entity.GetFloatDataValue("ORIENTATION_ROLL") * DegToRad);
|
||||
Offsets.multiply(new Vector3(1,PitchModifier,1));
|
||||
Vector3f Rotations = new Vector3f(entity.GetVehicleYaw() + Offsets.GetXF(),entity.GetVehiclePitch()+ Offsets.GetYF(),entity.GetVehicleRoll()+ Offsets.GetZF());
|
||||
Vector3f Rotations = new Vector3f(entity.GetVehicleYaw(),entity.GetVehiclePitch(),entity.GetVehicleRoll());
|
||||
Rotations.add(RotationsToAdd);
|
||||
VehicleCameraSettings.CameraPresets.get(entity.getType()).SetCameraTransformations(Rotations);
|
||||
VehicleCameraSettings.RefreshPreset();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.halbear.hvf.Entity;
|
||||
|
||||
import net.halbear.hvf.Entity.Renderer.AnimationAxis;
|
||||
import net.halbear.hvf.Entity.Renderer.PivotOrigin;
|
||||
import net.halbear.hvf.Entity.Renderer.VehicleAnimationManager;
|
||||
import net.halbear.hvf.Registry.Input.InputManager;
|
||||
@@ -24,6 +25,7 @@ import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.vector.*;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import org.lwjgl.system.CallbackI;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.*;
|
||||
@@ -44,11 +46,26 @@ public class VehicleBaseEntity extends Entity {
|
||||
private final Vector3d[] VehicleSeatOffsets;
|
||||
private float PartialTick = 1.0f;
|
||||
private EngineCategories EngineType;
|
||||
private Vector3d LastPositionVector = new Vector3d(0,0,0);
|
||||
private Vector3d CurrentPositionVector = new Vector3d(0,0,0);
|
||||
private final VehicleController Controller;
|
||||
public Vector3d LastPositionVector = new Vector3d(0,0,0);
|
||||
public Vector3d CurrentPositionVector = new Vector3d(0,0,0);
|
||||
public final VehicleController Controller;
|
||||
public VehicleBuildInfo vehicleBuildInfo;
|
||||
private Vector3 VehicleVelocity = new Vector3(0,0,0);
|
||||
public Vector3 VehicleVelocity = new Vector3(0,0,0);
|
||||
public Map<String, VehicleEntityState> VehicleStates = new HashMap<>();
|
||||
public String CurrentState = "DEFAULT";
|
||||
|
||||
public void SetCurrentState(String StateName){
|
||||
CurrentState = StateName;
|
||||
}
|
||||
public void AddVehicleState(String StateName, VehicleEntityState newState){
|
||||
VehicleStates.put(StateName, newState);
|
||||
}
|
||||
public void SetCurrentState(String StateName,VehicleEntityState newState){
|
||||
AddVehicleState(StateName, newState);
|
||||
CurrentState = StateName;
|
||||
}
|
||||
public String GetCurrentStateName(){return CurrentState;}
|
||||
public VehicleEntityState GetCurrentState(){return VehicleStates.get(CurrentState);}
|
||||
|
||||
public VehicleBaseEntity(EntityType<?> entityTypeIn, World worldIn, VehicleBuildInfo vehicleBuildInfo) {
|
||||
super(entityTypeIn, worldIn);
|
||||
@@ -69,18 +86,9 @@ public class VehicleBaseEntity extends Entity {
|
||||
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("VELOCITY_X",0d);
|
||||
BASE_DOUBLE_PARAMETERS.put("VELOCITY_Y",0d);
|
||||
BASE_DOUBLE_PARAMETERS.put("VELOCITY_Z",0d);
|
||||
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);
|
||||
@@ -127,6 +135,20 @@ public class VehicleBaseEntity extends Entity {
|
||||
case Ship:
|
||||
break;
|
||||
}
|
||||
VehicleStates.put("DEFAULT",
|
||||
new VehicleEntityState("DEFAULT")
|
||||
.SetBaseRotations(AnimationAxis.X_AXIS,new double[]{vehicleBuildInfo.GetAtRestAngleOffsets().x,90,180,270})
|
||||
.SetBaseRotations(AnimationAxis.Y_AXIS,new double[]{vehicleBuildInfo.GetAtRestAngleOffsets().y,90,180,270})
|
||||
.SetBaseRotations(AnimationAxis.Z_AXIS,new double[]{vehicleBuildInfo.GetAtRestAngleOffsets().z,90,180,270})
|
||||
.SetAllowedInputs(VehicleByteActions)
|
||||
);
|
||||
VehicleStates.put("NO_MODIFICATIONS",
|
||||
new VehicleEntityState("NO_MODIFICATIONS")
|
||||
.SetBaseRotations(AnimationAxis.X_AXIS,new double[]{0,90,180,270})
|
||||
.SetBaseRotations(AnimationAxis.Y_AXIS,new double[]{0,90,180,270})
|
||||
.SetBaseRotations(AnimationAxis.Z_AXIS,new double[]{0,90,180,270})
|
||||
.SetAllowedInputs(VehicleByteActions)
|
||||
);
|
||||
this.stepHeight = vehicleBuildInfo.GetStepHeight();
|
||||
CompoundNBT SyncedData = this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS).copy();
|
||||
BASE_FLOAT_PARAMETERS.forEach(SyncedData::putFloat);
|
||||
@@ -316,7 +338,12 @@ public class VehicleBaseEntity extends Entity {
|
||||
VehicleVelocity = new Vector3(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z"));
|
||||
}
|
||||
public boolean TouchingGround(){return GetBooleanDataValue("ON_GROUND");}
|
||||
public void StartPhysicsTick(double RotateScalar, double HorizontalVelocity,Vector3d Velocity, Vector3d NormalisedVelocity){
|
||||
|
||||
}
|
||||
public void EndPhysicsTick(double RotateScalar, double HorizontalVelocity,Vector3d Velocity, Vector3d NormalisedVelocity){
|
||||
|
||||
}
|
||||
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"));
|
||||
@@ -324,19 +351,14 @@ public class VehicleBaseEntity extends Entity {
|
||||
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);
|
||||
StartPhysicsTick(Scalar,OverallVelocity,Velocity,NormalisedVelocity);
|
||||
if(GetBooleanDataValue("ADHERES_TO_GRAVITY")) {
|
||||
if (!this.isOnGround()) {
|
||||
SetDoubleDataValue("VELOCITY_Y",GetDoubleDataValue("VELOCITY_Y") - GetDoubleDataValue("GRAVITY"));
|
||||
} else {
|
||||
if (GetFloatDataValue("ORIENTATION_PITCH") % 90 != 0) {
|
||||
SetFloatDataValue("ORIENTATION_PITCH", Math.round(GetFloatDataValue("ORIENTATION_PITCH") / 90.0f) * 90.0f);
|
||||
}
|
||||
if (VehicleStates.get(CurrentState).GetYRotation(GetFloatDataValue("ORIENTATION_PITCH")) != GetFloatDataValue("ORIENTATION_PITCH")) SetFloatDataValue("ORIENTATION_PITCH", (float) VehicleStates.get(CurrentState).GetYRotation(GetFloatDataValue("ORIENTATION_PITCH")));
|
||||
// if (VehicleStates.get(CurrentState).GetXRotation(GetFloatDataValue("ORIENTATION_YAW")) != GetFloatDataValue("ORIENTATION_YAW")) SetFloatDataValue("ORIENTATION_YAW", (float) VehicleStates.get(CurrentState).GetXRotation(GetFloatDataValue("ORIENTATION_YAW")));
|
||||
// if (VehicleStates.get(CurrentState).GetZRotation(GetFloatDataValue("ORIENTATION_ROLL")) != GetFloatDataValue("ORIENTATION_ROLL")) SetFloatDataValue("ORIENTATION_ROLL", (float) VehicleStates.get(CurrentState).GetZRotation(GetFloatDataValue("ORIENTATION_ROLL")));
|
||||
}
|
||||
}
|
||||
VehicleVelocity = new Vector3(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z"));
|
||||
@@ -348,10 +370,11 @@ public class VehicleBaseEntity extends Entity {
|
||||
markVelocityChanged();
|
||||
RotationTick();
|
||||
if(Scalar < 1&& !GetBooleanDataValue("ON_GROUND") && GetDoubleDataValue("VELOCITY_Y") < 0.015){
|
||||
double CenterOfMass = GetDoubleDataValue("CENTRE_OF_MASS_Z");
|
||||
float CenterOfMassFloat = (float) CenterOfMass;
|
||||
SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", (float) (-CenterOfMassFloat * (Math.max(1-Scalar,0))));
|
||||
Vector3f CenterOfMass = new Vector3(GetDoubleDataValue("CENTRE_OF_MASS_X"),GetDoubleDataValue("CENTRE_OF_MASS_Y"),GetDoubleDataValue("CENTRE_OF_MASS_Z")).GetFloat();
|
||||
if(CenterOfMass.getZ() != 0)SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", (float) (-CenterOfMass.getZ() * (Math.max(1-Scalar,0))));
|
||||
if(CenterOfMass.getX() != 0)SetFloatDataValue("ADD_ORIENTATION_ROLL_NEXT_TICK", (float) (-CenterOfMass.getX() * (Math.max(1-Scalar,0))));
|
||||
}
|
||||
EndPhysicsTick(Scalar,OverallVelocity,new Vector3d(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z")),new Vector3d(GetDoubleDataValue("VELOCITY_X"),GetDoubleDataValue("VELOCITY_Y"),GetDoubleDataValue("VELOCITY_Z")).normalize());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,9 +1,93 @@
|
||||
package net.halbear.hvf.Entity;
|
||||
|
||||
import net.halbear.hvf.Entity.Renderer.Angle;
|
||||
import net.halbear.hvf.Entity.Renderer.AnimationAxis;
|
||||
import net.halbear.hvf.Entity.Renderer.AxisType;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static net.halbear.hvf.Entity.Renderer.Angle.*;
|
||||
import static net.halbear.hvf.Entity.Renderer.AnimationAxis.*;
|
||||
|
||||
public class VehicleEntityState {
|
||||
|
||||
private double BaseRotationX = 0.0d;
|
||||
private double BaseRotationY = 0.0d;
|
||||
private double BaseRotationZ = 0.0d;
|
||||
private double[] BaseRotationX = new double[4];
|
||||
private double[] BaseRotationY = new double[4];
|
||||
private double[] BaseRotationZ = new double[4];
|
||||
private byte[] AllowedInputs;
|
||||
private Map<String,Float> AnimationSpeeds;
|
||||
private String StateName = "DEFAULT";
|
||||
private int TransitionTicks = 0;
|
||||
|
||||
public String GetStateName(){return StateName;}
|
||||
public byte[] GetAllowedInputs(){return AllowedInputs;}
|
||||
public double[] GetXRotations(){return BaseRotationX;}
|
||||
public double[] GetYRotations(){return BaseRotationY;}
|
||||
public double[] GetZRotations(){return BaseRotationZ;}
|
||||
public double GetXRotation(double Angle){
|
||||
int Index = (int)(Math.abs(Angle)/90.0)%4;
|
||||
return BaseRotationX[Index];
|
||||
}
|
||||
public double GetYRotation(double Angle){
|
||||
int Index = (int)(Math.abs(Angle)/90.0)%4;
|
||||
return BaseRotationY[Index];
|
||||
}
|
||||
public double GetZRotation(double Angle){
|
||||
int Index = (int)(Math.abs(Angle)/90.0)%4;
|
||||
return BaseRotationZ[Index];
|
||||
}
|
||||
public Vector3d GetBaseRotations(double AngleX, double AngleY, double AngleZ){
|
||||
int IndexX = (int)(Math.abs(AngleX)/90.0)%4;
|
||||
int IndexY = (int)(Math.abs(AngleY)/90.0)%4;
|
||||
int IndexZ = (int)(Math.abs(AngleZ)/90.0)%4;
|
||||
return new Vector3d(BaseRotationX[IndexX],BaseRotationY[IndexY],BaseRotationZ[IndexZ]);
|
||||
}
|
||||
public int GetTransitionTime(){
|
||||
return TransitionTicks;
|
||||
}
|
||||
public VehicleEntityState SetTransitionTime(int TransitionTicks){
|
||||
this.TransitionTicks = TransitionTicks;
|
||||
return this;
|
||||
}
|
||||
public VehicleEntityState(String StateName){
|
||||
this.StateName = StateName;
|
||||
}
|
||||
public VehicleEntityState AddAnimationModifier(String AnimationName, float AnimationSpeed){
|
||||
AnimationSpeeds.put(AnimationName,AnimationSpeed);
|
||||
return this;
|
||||
}
|
||||
public VehicleEntityState SetAllowedInputs(byte[] AllowedInputs){
|
||||
this.AllowedInputs = AllowedInputs;
|
||||
return this;
|
||||
}
|
||||
public VehicleEntityState SetBaseRotations(AnimationAxis Axis, double[] value){
|
||||
switch (Axis){
|
||||
case X_AXIS:
|
||||
BaseRotationX = value;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
BaseRotationY = value;
|
||||
break;
|
||||
case Z_AXIS:
|
||||
BaseRotationZ = value;
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public VehicleEntityState SetBaseRotation(Angle BaseAngle, AnimationAxis Axis, double value){
|
||||
int Angle = BaseAngle == ANGLE_90 ? 1 : BaseAngle == ANGLE_180 ? 2 : BaseAngle == ANGLE_270 ? 3 : 0;
|
||||
switch (Axis){
|
||||
case X_AXIS:
|
||||
BaseRotationX[Angle] = value;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
BaseRotationY[Angle] = value;
|
||||
break;
|
||||
case Z_AXIS:
|
||||
BaseRotationZ[Angle] = value;
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.halbear.hvf.Entity;
|
||||
|
||||
import net.halbear.hvf.Entity.Renderer.TransitionType;
|
||||
|
||||
public class VehicleStateSwitch {
|
||||
public String NextState = "DEFAULT";
|
||||
public TransitionType TransitionType = net.halbear.hvf.Entity.Renderer.TransitionType.LinearInterpolate;
|
||||
}
|
||||
+2
-2
@@ -3,8 +3,8 @@ 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) {
|
||||
public class GlobalData extends WorldSavedData {
|
||||
public GlobalData(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,13 @@ public class Aeroplane extends VehicleBaseEntity {
|
||||
GetVehicleController().AddInputFunction("TurnRight",()-> SetFloatDataValue("ADD_ORIENTATION_YAW_NEXT_TICK", GetFloatDataValue("ADD_ORIENTATION_YAW_NEXT_TICK") + 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void StartPhysicsTick(double RotateScalar, double HorizontalVelocity,Vector3d Velocity, Vector3d NormalisedVelocity){
|
||||
if(RotateScalar >= 1){
|
||||
SetCurrentState("NO_MODIFICATIONS");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnPunchedEvent(){
|
||||
SetRenderState("DAMAGED");
|
||||
|
||||
Reference in New Issue
Block a user