Animation Handling and client/server tick events
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package net.halbear.hvf.Entity.Renderer;
|
||||
|
||||
public enum AnimationAxis {
|
||||
X_AXIS,
|
||||
Y_AXIS,
|
||||
Z_AXIS
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.halbear.hvf.Entity.Renderer;
|
||||
|
||||
public enum AnimationAxis {
|
||||
MINECRAFT,
|
||||
EULER,
|
||||
CARTESIAN
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package net.halbear.hvf.Entity.Renderer;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import net.halbear.hvf.Entity.*;
|
||||
import net.halbear.hvf.Halsvehicleframework;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererManager;
|
||||
import net.minecraft.client.renderer.entity.model.EntityModel;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraft.client.renderer.model.ModelRenderer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class VehicleAnimationManager<T extends VehicleBaseEntity> {
|
||||
public static float DegToRad = (float)Math.PI/180.0F;
|
||||
|
||||
public static ModelRenderer PropellerAnimation(ModelRenderer BoneIn, T entity, AnimationAxis axis, boolean invertAnimation){
|
||||
float TargetPropRotation = entity.GetFloatValue("TARGET_PROPELLER_ROTATION");
|
||||
float CurrentPropRotation = entity.GetFloatValue("PROPELLER_ROTATION");
|
||||
float CurrentPropRotationRadians = CurrentPropRotation * (invertAnimation ? -DegToRad : DegToRad);
|
||||
float PropIncrementAmount = entity.GetFloatValue("PROPELLER_ROTATION_SPEED");
|
||||
boolean modifiedAngle = false;
|
||||
if(TargetPropRotation < CurrentPropRotation){
|
||||
CurrentPropRotation = Math.max(CurrentPropRotation - PropIncrementAmount, TargetPropRotation) % 360;
|
||||
modifiedAngle = true;
|
||||
}
|
||||
if(TargetPropRotation > CurrentPropRotation){
|
||||
CurrentPropRotation = modifiedAngle ? TargetPropRotation : Math.min(CurrentPropRotation + PropIncrementAmount,TargetPropRotation) % 360;
|
||||
}
|
||||
entity.SetFloatValue("PROPELLER_ROTATION",CurrentPropRotation);
|
||||
switch(axis){
|
||||
case X_AXIS:
|
||||
BoneIn.rotateAngleX = CurrentPropRotationRadians;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
BoneIn.rotateAngleY = CurrentPropRotationRadians;
|
||||
break;
|
||||
case Z_AXIS:
|
||||
BoneIn.rotateAngleZ = CurrentPropRotationRadians;
|
||||
break;
|
||||
}
|
||||
return BoneIn;
|
||||
}
|
||||
|
||||
public static Vector3f ConvertCartesianToEuler(Vector3f VectorIn){
|
||||
Vector3f NewAxis = new Vector3f(VectorIn.z,VectorIn.y,VectorIn,x);
|
||||
return NewAxis;
|
||||
}
|
||||
|
||||
public static Vector3f ConvertEulerToCartesian(Vector3f VectorIn){
|
||||
return ConvertCartesianToEuler(VectorIn);
|
||||
}
|
||||
|
||||
public static Vector3f ConvertCartesianToMinecraft(Vector3f VectorIn){
|
||||
Vector3f NewAxis = new Vector3f(VectorIn.y,VectorIn.x,VectorIn,z);
|
||||
return NewAxis;
|
||||
}
|
||||
|
||||
public static Vector3f ConvertMinecraftToCartesian(Vector3f VectorIn){
|
||||
return ConvertMinecraftToCartesian(VectorIn);
|
||||
}
|
||||
|
||||
|
||||
public static Vector3f ConvertMinecraftToEuler(Vector3f VectorIn){
|
||||
Vector3f NewAxis = new Vector3f(VectorIn.z,VectorIn.x,VectorIn,y);
|
||||
return NewAxis;
|
||||
}
|
||||
|
||||
public static Vector3f ConvertEulerToMinecraft(Vector3f VectorIn){
|
||||
Vector3f NewAxis = new Vector3f(VectorIn.y,VectorIn.x,VectorIn.z);
|
||||
return NewAxis;
|
||||
}
|
||||
|
||||
public static AnimationAxis ConvertMinecraftToCartesian(AnimationAxis axisIn){
|
||||
switch(axis){
|
||||
case X_AXIS:
|
||||
return Y_AXIS;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
return X_AXIS
|
||||
break;
|
||||
case Z_AXIS:
|
||||
return Z_AXIS
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static AnimationAxis ConvertEulerToCartesian(AnimationAxis axisIn){
|
||||
switch(axis){
|
||||
case X_AXIS:
|
||||
return Z_AXIS;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
return Y_AXIS
|
||||
break;
|
||||
case Z_AXIS:
|
||||
return X_AXIS
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static AnimationAxis ConvertCartesianToMinecraft(AnimationAxis axisIn){
|
||||
switch(axis){
|
||||
case X_AXIS:
|
||||
return Y_AXIS;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
return X_AXIS
|
||||
break;
|
||||
case Z_AXIS:
|
||||
return Z_AXIS
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static AnimationAxis ConvertCartesianToEuler(AnimationAxis axisIn){
|
||||
switch(axis){
|
||||
case X_AXIS:
|
||||
return Z_AXIS;
|
||||
break;
|
||||
case Y_AXIS:
|
||||
return Y_AXIS
|
||||
break;
|
||||
case Z_AXIS:
|
||||
return X_AXIS
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,13 @@ public class VehicleBaseEntity extends Entity {
|
||||
EngineType = vehicleBuildInfo.GetEngineType();
|
||||
VEHICLE_SYNCHED_FLOAT_PARAMETERS.put("ORIENTATION_ROLL", EntityDataManager.createKey(VehicleBaseEntity.class, DataSerializers.FLOAT));
|
||||
BASE_FLOAT_PARAMETERS.put("ORIENTATION_ROLL",0f);
|
||||
float PropRotation = (float)(360 * Math.random());
|
||||
VEHICLE_SYNCHED_FLOAT_PARAMETERS.put("PROPELLER_ROTATION", EntityDataManager.createKey(VehicleBaseEntity.class, DataSerializers.FLOAT));
|
||||
BASE_FLOAT_PARAMETERS.put("PROPELLER_ROTATION",PropRotation);
|
||||
VEHICLE_SYNCHED_FLOAT_PARAMETERS.put("TARGET_PROPELLER_ROTATION", EntityDataManager.createKey(VehicleBaseEntity.class, DataSerializers.FLOAT));
|
||||
BASE_FLOAT_PARAMETERS.put("TARGET_PROPELLER_ROTATION",PropRotation);
|
||||
VEHICLE_SYNCHED_FLOAT_PARAMETERS.put("PROPELLER_ROTATION_SPEED", EntityDataManager.createKey(VehicleBaseEntity.class, DataSerializers.FLOAT));
|
||||
BASE_FLOAT_PARAMETERS.put("PROPELLER_ROTATION_SPEED",0F);
|
||||
VEHICLE_SYNCHED_FLOAT_PARAMETERS.put("ORIENTATION_YAW", EntityDataManager.createKey(VehicleBaseEntity.class, DataSerializers.FLOAT));
|
||||
BASE_FLOAT_PARAMETERS.put("ORIENTATION_YAW",0f);
|
||||
VEHICLE_SYNCHED_FLOAT_PARAMETERS.put("ORIENTATION_PITCH", EntityDataManager.createKey(VehicleBaseEntity.class, DataSerializers.FLOAT));
|
||||
@@ -125,6 +132,19 @@ public class VehicleBaseEntity extends Entity {
|
||||
public void tick() {
|
||||
super.tick();
|
||||
TickUpdateEvent();
|
||||
if(this.world.isRemote()){
|
||||
ClientSideTickEvent();
|
||||
} else{
|
||||
ServerSideTickEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public void ServerSideTickEvent(){
|
||||
|
||||
}
|
||||
|
||||
public void ClientSideTickEvent(){
|
||||
|
||||
}
|
||||
|
||||
public void TickUpdateEvent() {
|
||||
|
||||
@@ -31,5 +31,15 @@ public class Aeroplane extends VehicleBaseEntity {
|
||||
public void TickUpdateEvent(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ServerSideTickEvent(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ClientSideTickEvent(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,4 +32,14 @@ public class Airboat extends VehicleBaseEntity {
|
||||
public void TickUpdateEvent(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ServerSideTickEvent(){
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ClientSideTickEvent(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user