fuck minecrafts shitty ass systems bro
This commit is contained in:
@@ -87,6 +87,8 @@ public class VehicleBaseRenderer<T extends VehicleBaseEntity, M extends EntityMo
|
||||
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") * VehicleAnimationManager.DegToRad);
|
||||
Offsets.multiply(new Vector3(1,PitchModifier,1));
|
||||
Vector3f Rotations = new Vector3f(180.0F - entity.GetVehicleYaw() + Offsets.GetXF(),entity.GetVehiclePitch()+ Offsets.GetYF(),entity.GetVehicleRoll()+ Offsets.GetZF());
|
||||
Rotations.add(RotationsToAdd);
|
||||
switch(OriginType) {
|
||||
|
||||
@@ -11,6 +11,7 @@ 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.MoverType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
@@ -46,6 +47,7 @@ public class VehicleBaseEntity extends Entity {
|
||||
private Vector3d CurrentPositionVector = new Vector3d(0,0,0);
|
||||
private final VehicleController Controller;
|
||||
public VehicleBuildInfo vehicleBuildInfo;
|
||||
private Vector3 VehicleVelocity = new Vector3(0,0,0);
|
||||
|
||||
public VehicleBaseEntity(EntityType<?> entityTypeIn, World worldIn, VehicleBuildInfo vehicleBuildInfo) {
|
||||
super(entityTypeIn, worldIn);
|
||||
@@ -258,20 +260,22 @@ public class VehicleBaseEntity extends Entity {
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
this.baseTick();
|
||||
this.LastPositionVector = CurrentPositionVector;
|
||||
CurrentPositionVector = getPositionVec();
|
||||
super.tick();
|
||||
Controller.PollInputs(GetByteArrayValue("INPUT_DATA"));
|
||||
PhysicsTick();
|
||||
this.setPosition(this.getPosX(), this.getPosY(), this.getPosZ());
|
||||
SubClassTickUpdateEvent();
|
||||
TickUpdateEvent();
|
||||
SetBooleanDataValue("ON_GROUND",getMotion().y == 0);
|
||||
if(this.world.isRemote()){
|
||||
SubClassServerSideTickEvent();
|
||||
SubClassClientSideTickEvent();
|
||||
ClientSideTickEvent();
|
||||
} else{
|
||||
SubClassClientSideTickEvent();
|
||||
SubClassServerSideTickEvent();
|
||||
ServerSideTickEvent();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,11 +287,12 @@ public class VehicleBaseEntity extends Entity {
|
||||
SetFloatDataValue("ORIENTATION_YAW",(GetFloatDataValue("ORIENTATION_YAW") + GetFloatDataValue("ADD_ORIENTATION_YAW_NEXT_TICK"))%360);
|
||||
SetFloatDataValue("ADD_ORIENTATION_YAW_NEXT_TICK",0f);
|
||||
}
|
||||
|
||||
public void AddVelocity(double x, double y, double z){
|
||||
VehicleVelocity.add(x,y,z);
|
||||
}
|
||||
public boolean TouchingGround(){return GetBooleanDataValue("ON_GROUND");}
|
||||
|
||||
public void PhysicsTick(){
|
||||
Vector3d Velocity = Vector3.Positive(getMotion());
|
||||
Vector3d Velocity = Vector3.Positive(VehicleVelocity).GetDouble();
|
||||
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);
|
||||
@@ -299,30 +304,45 @@ public class VehicleBaseEntity extends Entity {
|
||||
SetDoubleDataValue("ANGLE_OFFSET_ROLL",AngleOffsets.z);
|
||||
if(GetBooleanDataValue("ADHERES_TO_GRAVITY")) {
|
||||
if (!this.isOnGround()) {
|
||||
this.setMotion(this.getMotion().add(0, -GetDoubleDataValue("GRAVITY"), 0));
|
||||
VehicleVelocity.add(0, -GetDoubleDataValue("GRAVITY"), 0);
|
||||
} else {
|
||||
if (GetFloatDataValue("ORIENTATION_PITCH") % 90 != 0) {
|
||||
SetFloatDataValue("ORIENTATION_PITCH", Math.round(GetFloatDataValue("ORIENTATION_PITCH") / 90.0f) * 90.0f);
|
||||
}
|
||||
}
|
||||
this.move(net.minecraft.entity.MoverType.SELF, this.getMotion());
|
||||
this.setMotion(this.getMotion().mul(0.98D, 0.98D, 0.98D));
|
||||
}
|
||||
Vector3d currentMotion;
|
||||
//!!!!!
|
||||
//REMINDER FOR NEXT TIME
|
||||
//MAKE VehicleVelocity SERVER SIDED
|
||||
//BIG SYNC ISSUES IN MULTIPLAYER
|
||||
//!!!!!
|
||||
setMotion(VehicleVelocity.GetDouble());
|
||||
this.move(net.minecraft.entity.MoverType.SELF, VehicleVelocity.GetDouble());
|
||||
VehicleVelocity = new Vector3(this.getMotion());
|
||||
VehicleVelocity.multiply(0.98);
|
||||
markVelocityChanged();
|
||||
RotationTick();
|
||||
if(Scalar < 1&& this.getMotion().y < 0){
|
||||
if(Scalar < 1&& VehicleVelocity.y < 0){
|
||||
double CenterOfMass = GetDoubleDataValue("CENTRE_OF_MASS_Z");
|
||||
float CenterOfMassFloat = (float) CenterOfMass;
|
||||
float YVelocity = (float) this.getMotion().y;
|
||||
if(YVelocity < 0){
|
||||
SetFloatDataValue("ADD_ORIENTATION_PITCH_NEXT_TICK", (float) (-CenterOfMassFloat * (Math.max(1-Scalar,0))));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(MoverType type, Vector3d position) {
|
||||
Vector3d currentMotion = this.getMotion();
|
||||
super.move(type, position);
|
||||
}
|
||||
|
||||
public void ApplyForce(double dx, double dy, double dz){
|
||||
this.setMotion(this.getMotion().add(dx,dy,dz));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePushed() {
|
||||
return false;
|
||||
}
|
||||
public void OnPunchedEvent(){}
|
||||
public void ServerSideTickEvent(){}
|
||||
public void ClientSideTickEvent(){}
|
||||
@@ -414,19 +434,6 @@ public class VehicleBaseEntity extends Entity {
|
||||
);
|
||||
|
||||
SeatPosition.transform(TransformationMatrix);
|
||||
|
||||
/*Quaternion TotalRotation = new Quaternion(0.0F, 0.0F, 0.0F, 1.0F);
|
||||
TotalRotation.multiply(Vector3f.YP.rotation(yawRad));
|
||||
|
||||
Vector3f LocalPitchAxis = new Vector3f((float)Math.cos(yawRad), 0.0F, (float)Math.sin(yawRad));
|
||||
TotalRotation.multiply(LocalPitchAxis.rotation(pitchRad));
|
||||
|
||||
Vector3f LocalRollAxis = new Vector3f((float)-Math.sin(yawRad),0.0F,(float)Math.cos(yawRad));
|
||||
LocalRollAxis.transform(Vector3f.XP.rotation(pitchRad));
|
||||
TotalRotation.multiply(LocalRollAxis.rotation(rollRad));
|
||||
|
||||
Vector3f localOffsetFloat = new Vector3(RelativeSeatOffset).GetFloat();
|
||||
localOffsetFloat.transform(TotalRotation);*/
|
||||
passenger.setPosition(
|
||||
this.getPosX() + SeatPosition.getX() - OriginPosition.x,
|
||||
this.getPosY() + SeatPosition.getY() + passenger.getMountedYOffset() - OriginPosition.y,
|
||||
|
||||
@@ -28,6 +28,46 @@ public class Vector3 {
|
||||
public float GetYF(){return (float)y;}
|
||||
public float GetZF(){return (float)z;}
|
||||
|
||||
public static boolean inRange(Vector3d Lowest, Vector3d Highest, Vector3d Comparer){
|
||||
boolean InLowestRange = (Lowest.x <= Comparer.x) && (Lowest.y <= Comparer.y) && (Lowest.z <= Comparer.z);
|
||||
boolean InHighestRange = (Highest.x >= Comparer.x) && (Highest.y >= Comparer.y) && (Highest.z >= Comparer.z);
|
||||
return InLowestRange && InHighestRange;
|
||||
}
|
||||
|
||||
public void add(double vectorInx,double vectorIny,double vectorInz){
|
||||
this.x += vectorInx;
|
||||
this.y += vectorIny;
|
||||
this.z += vectorInz;
|
||||
}
|
||||
public void add(Vector3 vectorIn){
|
||||
this.x += vectorIn.x;
|
||||
this.y += vectorIn.y;
|
||||
this.z += vectorIn.z;
|
||||
}
|
||||
public void sub(Vector3 vectorIn){
|
||||
this.x -= vectorIn.x;
|
||||
this.y -= vectorIn.y;
|
||||
this.z -= vectorIn.z;
|
||||
}
|
||||
public void multiply(double value){
|
||||
this.x *= value;
|
||||
this.y *= value;
|
||||
this.z *= value;
|
||||
}
|
||||
public void multiply(Vector3 vectorIn){
|
||||
this.x *= vectorIn.x;
|
||||
this.y *= vectorIn.y;
|
||||
this.z *= vectorIn.z;
|
||||
}
|
||||
public void divide(Vector3 vectorIn){
|
||||
this.x /= vectorIn.x;
|
||||
this.y /= vectorIn.y;
|
||||
this.z /= vectorIn.z;
|
||||
}
|
||||
|
||||
public static Vector3d Negative(Vector3d in){
|
||||
return new Vector3d(in.x > 0 ? -in.x : in.x,in.y > 0 ? -in.y : in.y,in.z > 0 ? -in.z : in.z);
|
||||
}
|
||||
public static Vector3i Positive(Vector3i in){
|
||||
return new Vector3i(in.getX() < 0 ? -in.getX(): in.getX(),in.getY() < 0 ? -in.getY() : in.getY(),in.getZ() < 0 ? -in.getZ() : in.getZ());
|
||||
}
|
||||
|
||||
@@ -43,16 +43,31 @@ public class VehicleController<T extends VehicleBaseEntity> {
|
||||
public VehicleController AddInputFunction(String Input, float ChangeAmount, Vector3d TerminalVelocity, InputCategory functionType){
|
||||
switch(functionType){
|
||||
case MoveForward:
|
||||
AddInputFunction(Input,()-> Parent.setMotion(Vector3.Clamp(-TerminalVelocity.x,-TerminalVelocity.y,-TerminalVelocity.z,TerminalVelocity.x,TerminalVelocity.y,TerminalVelocity.z,Parent.getMotion().add(-ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw())))));
|
||||
AddInputFunction(Input,()->{ if(Vector3.inRange(Vector3.Negative(TerminalVelocity),TerminalVelocity, Parent.getMotion())){
|
||||
Parent.AddVelocity(-ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()));
|
||||
}
|
||||
});
|
||||
break;
|
||||
case MoveBackward:
|
||||
AddInputFunction(Input,()-> Parent.setMotion(Vector3.Clamp(-TerminalVelocity.x,-TerminalVelocity.y,-TerminalVelocity.z,TerminalVelocity.x,TerminalVelocity.y,TerminalVelocity.z,Parent.getMotion().add(ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * -(float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw())))));
|
||||
AddInputFunction(Input,()-> {
|
||||
if (Vector3.inRange(Vector3.Negative(TerminalVelocity), TerminalVelocity, Parent.getMotion())) {
|
||||
Parent.AddVelocity(ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * -(float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()));
|
||||
}
|
||||
});
|
||||
break;
|
||||
case StrafeLeft:
|
||||
AddInputFunction(Input,()-> Parent.setMotion(Vector3.Clamp(-TerminalVelocity.x,-TerminalVelocity.y,-TerminalVelocity.z,TerminalVelocity.x,TerminalVelocity.y,TerminalVelocity.z,Parent.getMotion().add(ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * -(float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw())))));
|
||||
AddInputFunction(Input,()-> {
|
||||
if (Vector3.inRange(Vector3.Negative(TerminalVelocity), TerminalVelocity, Parent.getMotion())) {
|
||||
Parent.AddVelocity(ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * -(float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()));
|
||||
}
|
||||
});
|
||||
break;
|
||||
case StrafeRight:
|
||||
AddInputFunction(Input,()-> Parent.setMotion(Vector3.Clamp(-TerminalVelocity.x,-TerminalVelocity.y,-TerminalVelocity.z,TerminalVelocity.x,TerminalVelocity.y,TerminalVelocity.z,Parent.getMotion().add(-ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw())))));
|
||||
AddInputFunction(Input,()-> {
|
||||
if (Vector3.inRange(Vector3.Negative(TerminalVelocity), TerminalVelocity, Parent.getMotion())) {
|
||||
Parent.AddVelocity(-ChangeAmount * (float)Math.cos(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()),0,ChangeAmount * (float)Math.sin(VehicleAnimationManager.DegToRad * Parent.GetVehicleYaw()));
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
|
||||
Reference in New Issue
Block a user