diff --git a/build.gradle b/build.gradle index e0fdefc..d7a500d 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ archivesBaseName = 'hals_vehicle_framework' java.toolchain.languageVersion = JavaLanguageVersion.of(8) minecraft { - mappings channel: 'snapshot', version: '20201028-1.16.3' + mappings channel: 'snapshot', version: '20210309-1.16.5' runs { client { diff --git a/src/main/java/net/halbear/hvf/Entity/Renderer/PhysicsPreset.java b/src/main/java/net/halbear/hvf/Entity/Renderer/PhysicsPreset.java new file mode 100644 index 0000000..8429891 --- /dev/null +++ b/src/main/java/net/halbear/hvf/Entity/Renderer/PhysicsPreset.java @@ -0,0 +1,8 @@ +package net.halbear.hvf.Entity.Renderer; + +public enum PhysicsPreset { + SimpleMinecraft, + AdvancedMinecraft, + SimpleReal, + AdvancedReal +} diff --git a/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java b/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java index 906621b..6609973 100644 --- a/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java +++ b/src/main/java/net/halbear/hvf/Entity/Renderer/VehicleBaseRenderer.java @@ -44,30 +44,39 @@ public class VehicleBaseRenderer{ IVertexBuilder vertexBuilder = buffer.getBuffer(model.getRenderType(getEntityTexture(entity))); model.setRotationAngles(entity, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F); @@ -75,6 +84,8 @@ public class VehicleBaseRenderer VEHICLE_SYNCHED_PARAMETERS = EntityDataManager.createKey(VehicleBaseEntity.class, DataSerializers.COMPOUND_NBT); private static final VehicleAnimationManager ANIMATION_MANAGER = new VehicleAnimationManager<>(); + private Map BASE_DOUBLE_PARAMETERS = new HashMap<>(); private Map BASE_FLOAT_PARAMETERS = new HashMap<>(); private Map BASE_INT_PARAMETERS = new HashMap<>(); private Map BASE_BOOL_PARAMETERS = new HashMap<>(); @@ -42,12 +47,20 @@ public class VehicleBaseEntity extends Entity { public Vector3d GetPilotSeat(){return VehicleSeatOffsets.length > 0 ? VehicleSeatOffsets[0] : new Vector3d(0,0,0);} - public VehicleBaseEntity(EntityType entityTypeIn, World worldIn, Vector3d[] VehicleSeatOffsets, VehicleBuildInfo vehicleBuildInfo) { + public VehicleBaseEntity(EntityType entityTypeIn, World worldIn, VehicleBuildInfo vehicleBuildInfo) { super(entityTypeIn, worldIn); - this.VehicleSeatOffsets = VehicleSeatOffsets; + this.setNoGravity(vehicleBuildInfo.GetAdheresToGravity()); + List VehicleSeats = new ArrayList(); + VehicleSeats.add(vehicleBuildInfo.GetPilotSeat()); + VehicleSeats.addAll(vehicleBuildInfo.GetPassengerSeats()); + this.VehicleSeatOffsets = VehicleSeats.toArray(new Vector3d[0]); vehicleClassification = vehicleBuildInfo.GetVehicleClassification(); EngineType = vehicleBuildInfo.GetEngineType(); float PropRotation = (float)(360 * Math.random()); + BASE_DOUBLE_PARAMETERS.put("GRAVITY",!vehicleBuildInfo.GetAdheresToGravity() ? 0 : vehicleBuildInfo.GetGravityStrength()); + 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_FLOAT_PARAMETERS.put("ORIENTATION_YAW",0f); BASE_FLOAT_PARAMETERS.put("ORIENTATION_PITCH",0f); BASE_FLOAT_PARAMETERS.put("ORIENTATION_ROLL",0f); @@ -66,8 +79,8 @@ public class VehicleBaseEntity extends Entity { break; case Zepplin: BASE_INT_PARAMETERS.put("ENGINE_COUNT",(Integer) vehicleBuildInfo.GetEngineCount()); - BASE_FLOAT_PARAMETERS.put("GAS_CEL_CAPACITY",(float)vehicleBuildInfo.GetGasCelCapacity()); - BASE_FLOAT_PARAMETERS.put("GAS_CEL_COUNT",(float)vehicleBuildInfo.GetGasCelCount()); + BASE_FLOAT_PARAMETERS.put("FLUID_COMPARTMENT_CAPACITY",(float)vehicleBuildInfo.GetGasCelCapacity()); + BASE_FLOAT_PARAMETERS.put("FLUID_COMPARTMENT_COUNT",(float)vehicleBuildInfo.GetGasCelCount()); break; case Ship: break; @@ -75,6 +88,7 @@ public class VehicleBaseEntity extends Entity { CompoundNBT SyncedData = this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS).copy(); BASE_FLOAT_PARAMETERS.forEach(SyncedData::putFloat); + BASE_DOUBLE_PARAMETERS.forEach(SyncedData::putDouble); BASE_INT_PARAMETERS.forEach(SyncedData::putInt); BASE_STRING_PARAMETERS.forEach(SyncedData::putString); BASE_BOOL_PARAMETERS.forEach(SyncedData::putBoolean); @@ -97,6 +111,14 @@ public class VehicleBaseEntity extends Entity { public String GetStringDataValue(String ValueName){ return this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS).getString(ValueName); } + public void SetDoubleDataValue(String ValueName, Double Value){ + CompoundNBT SyncedData = this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS).copy(); + SyncedData.putDouble(ValueName,Value); + this.dataManager.set(VEHICLE_SYNCHED_PARAMETERS,SyncedData); + } + public Double GetDoubleDataValue(String ValueName){ + return this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS).getDouble(ValueName); + } public void SetFloatDataValue(String ValueName, Float Value){ CompoundNBT SyncedData = this.dataManager.get(VEHICLE_SYNCHED_PARAMETERS).copy(); SyncedData.putFloat(ValueName,Value); @@ -157,10 +179,18 @@ public class VehicleBaseEntity extends Entity { if(this.world.isRemote()){ ClientSideTickEvent(); } else{ + float CurrentPropRotation = GetFloatDataValue("TARGET_PROPELLER_ROTATION"); + float PropIncrementAmount = GetFloatDataValue("PROPELLER_ROTATION_SPEED"); + SetFloatDataValue("TARGET_PROPELLER_ROTATION",(CurrentPropRotation + PropIncrementAmount) % 36000); + SetFloatDataValue("PROPELLER_ROTATION",CurrentPropRotation); ServerSideTickEvent(); } } + public void ApplyForce(double dx, double dy, double dz){ + this.setMotion(this.getMotion().add(dx,dy,dz)); + } + public void ServerSideTickEvent(){ } diff --git a/src/main/java/net/halbear/hvf/Example/Aeroplane.java b/src/main/java/net/halbear/hvf/Example/Aeroplane.java index 83dde0b..d173f10 100644 --- a/src/main/java/net/halbear/hvf/Example/Aeroplane.java +++ b/src/main/java/net/halbear/hvf/Example/Aeroplane.java @@ -19,10 +19,12 @@ public class Aeroplane extends VehicleBaseEntity { .SetEngineType(EngineCategories.Aircraft_Propeller) .SetMaxEngineRPM(3000) .SetWingSpan(2) - .SetMaxSpeedMS(70); + .SetMaxSpeedMS(70) + .SetCentreOfMass(new Vector3d(0,0,2)) + .SetPilotSeat(new Vector3d(0.0D, -1D, 0.0D)); public Aeroplane(EntityType Type, World WorldIn) { - super(Type, WorldIn, new Vector3d[]{new Vector3d(0.0D, -1D, 0.0D)}, buildInfo); + super(Type, WorldIn, buildInfo); VehicleCameraSettings.AddEntityCameraPreset(this.getType(), new VehicleCameraPreset(new Vector3f(0,0,4.5f), new Vector3f(0,0,0),70,60)); @@ -36,12 +38,7 @@ public class Aeroplane extends VehicleBaseEntity { @Override public void ServerSideTickEvent(){ - float CurrentPropRotation = GetFloatDataValue("TARGET_PROPELLER_ROTATION"); - float PropIncrementAmount = GetFloatDataValue("PROPELLER_ROTATION_SPEED"); - SetFloatDataValue("TARGET_PROPELLER_ROTATION",(CurrentPropRotation + PropIncrementAmount) % 36000); - SetFloatDataValue("ORIENTATION_ROLL",(GetFloatDataValue("ORIENTATION_ROLL") + (PropIncrementAmount < 10 ? (float)(Math.random()): -(float)(Math.random()))) % 360); - SetFloatDataValue("ORIENTATION_PITCH",(GetFloatDataValue("ORIENTATION_PITCH")+ (PropIncrementAmount < 10 ? (float)(Math.random()): -(float)(Math.random()))) % 360); - SetFloatDataValue("PROPELLER_ROTATION",CurrentPropRotation); + } @Override diff --git a/src/main/java/net/halbear/hvf/Example/Airboat.java b/src/main/java/net/halbear/hvf/Example/Airboat.java index 454bc9b..fd0ad5b 100644 --- a/src/main/java/net/halbear/hvf/Example/Airboat.java +++ b/src/main/java/net/halbear/hvf/Example/Airboat.java @@ -19,10 +19,13 @@ public class Airboat extends VehicleBaseEntity { .SetMaxEngineRPM(3000) .SetMaxSpeedMS(70) .SetGasCelCount(8) - .SetGasCelCapacity(1000); + .SetGasCelCapacity(1000) + .SetPilotSeat(new Vector3d(0.0D, -2D, 0.0D)) + .AddPassengerSeat(new Vector3d(0.0D, -2D, 2.0D)) + .AddPassengerSeat(new Vector3d(0.0D, -2D, -2.0D)); public Airboat(EntityType Type, World WorldIn) { - super(Type, WorldIn, new Vector3d[]{new Vector3d(0.0D, -2D, 0.0D)}, buildInfo); + super(Type, WorldIn, buildInfo); VehicleCameraSettings.AddEntityCameraPreset(this.getType(), new VehicleCameraPreset(new Vector3f(0,4.0f, 16.0f), new Vector3f(0,0,0),70,65f)); diff --git a/src/main/java/net/halbear/hvf/Registry/ModEntityTags.java b/src/main/java/net/halbear/hvf/Registry/ModEntityTags.java index c5028d4..9c12a3f 100644 --- a/src/main/java/net/halbear/hvf/Registry/ModEntityTags.java +++ b/src/main/java/net/halbear/hvf/Registry/ModEntityTags.java @@ -6,7 +6,7 @@ import net.minecraft.tags.ITag; import net.minecraft.util.ResourceLocation; public class ModEntityTags { - public static final ITag.INamedTag> CAMERA_AFFECTED_VEHICLE = EntityTypeTags.createOptional(new ResourceLocation("forge:hvf_camera_affected_vehicle")); + public static final ITag.INamedTag> CAMERA_AFFECTED_VEHICLE = EntityTypeTags.createOptional(new ResourceLocation("forge","hvf_camera_affected_vehicle")); public static boolean doesEntityHaveCameraPreset(EntityType EntityType){ return EntityType.isContained(CAMERA_AFFECTED_VEHICLE); diff --git a/src/main/java/net/halbear/hvf/Util/Mixin/CameraMixin.java b/src/main/java/net/halbear/hvf/Util/Mixin/CameraMixin.java index 092db18..bf31d46 100644 --- a/src/main/java/net/halbear/hvf/Util/Mixin/CameraMixin.java +++ b/src/main/java/net/halbear/hvf/Util/Mixin/CameraMixin.java @@ -5,25 +5,37 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.settings.PointOfView; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.tags.EntityTypeTags; +import net.minecraft.tags.ITag; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.vector.Vector3f; import net.minecraft.world.IBlockReader; +import net.minecraftforge.registries.ForgeRegistries; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Arrays; + +import static net.halbear.hvf.Registry.ModEntityTags.doesEntityHaveCameraPreset; import static net.halbear.hvf.Util.Client.VehicleCameraSettings.GetCameraOffsets; @Mixin(ActiveRenderInfo.class) public abstract class CameraMixin { @Inject(method = {"update", "func_216772_a"}, at = @At(value = "TAIL"),cancellable = true, remap = true) private void update(IBlockReader currentRenderedLevel, Entity entity, boolean isDetached, boolean isMirrored, float partialTicks, CallbackInfo ci){ - - if(entity.isPassenger() && Minecraft.getInstance().gameSettings.getPointOfView() != PointOfView.FIRST_PERSON && entity.getRidingEntity().getType().getRegistryName().getNamespace().equals(Halsvehicleframework.MOD_ID)){ - Vector3f Position = GetCameraOffsets(); - this.movePosition(-this.calcCameraDistance(Position.getZ()), Position.getY(), Position.getX()); + if(entity.isPassenger() && Minecraft.getInstance().gameSettings.getPointOfView() != PointOfView.FIRST_PERSON) { + ITag> myEntityTag = EntityTypeTags.getTagById(new ResourceLocation("forge", "hvf_camera_affected_vehicle").toString()); + boolean entityHaveCameraPreset = myEntityTag.contains(entity.getRidingEntity().getType()); + if (entityHaveCameraPreset) { + Vector3f Position = GetCameraOffsets(); + this.movePosition(-this.calcCameraDistance(Position.getZ()), Position.getY(), Position.getX()); + } } + } @Shadow(aliases = {"move", "func_216782_a"}) protected abstract void movePosition(double p_216782_1_, double p_216782_3_, double p_216782_5_); diff --git a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java index 155a9a3..0993820 100644 --- a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java @@ -1,7 +1,14 @@ package net.halbear.hvf.Util.VehicleData; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.util.math.vector.Vector3f; + +import java.util.ArrayList; +import java.util.List; + public class VehicleBuildInfo { private VehicleClassification vehicleClassification; + private Vector3d CentreOfMassOffset = new Vector3d(0,0,0); private int EngineCount; private EngineCategories EngineType; private int GasCelCount; @@ -9,7 +16,19 @@ public class VehicleBuildInfo { private float MaxEngineRPM; private float WingSpanMeters; private float GasCelCapacity; + private double Gravity = 4.9f; + private boolean AdheresToGravity = true; + private Vector3d PilotSeat; + private List PassengerSeats = new ArrayList<>(); + public VehicleBuildInfo AddPassengerSeat(Vector3d SeatIn){ + PassengerSeats.add(SeatIn); + return this; + } + public VehicleBuildInfo SetPilotSeat(Vector3d SeatIn){ + PilotSeat = SeatIn; + return this; + } public VehicleBuildInfo(VehicleClassification vehicleClassification){ this.vehicleClassification = vehicleClassification; } @@ -17,6 +36,14 @@ public class VehicleBuildInfo { this.EngineType = EngineType; return this; } + public VehicleBuildInfo SetCentreOfMass(Vector3d CentreOfMassOffset){ + this.CentreOfMassOffset = CentreOfMassOffset; + return this; + } + public VehicleBuildInfo SetGravityStrength(double Gravity){ + this.Gravity = Gravity; + return this; + } public VehicleBuildInfo SetGasCelCount(int GasCelCount){ this.GasCelCount = GasCelCount; return this; @@ -41,6 +68,10 @@ public class VehicleBuildInfo { this.GasCelCapacity = GasCelCapacity; return this; } + public VehicleBuildInfo AdhereToGravity(boolean AffectedByGravity){ + this.AdheresToGravity = AffectedByGravity; + return this; + } public VehicleClassification GetVehicleClassification(){ @@ -49,14 +80,19 @@ public class VehicleBuildInfo { public int GetEngineCount(){ return EngineCount; } - public EngineCategories GetEngineType(){ - return EngineType; + public Vector3d GetCentreOfMass(){ + return CentreOfMassOffset; } + public EngineCategories GetEngineType(){return EngineType;} public int GetGasCelCount(){ return GasCelCount; } + public double GetGravityStrength(){return Gravity;} + public Vector3d GetPilotSeat(){return PilotSeat;} + public List GetPassengerSeats(){return PassengerSeats;} public float GetMaxSpeedMS(){return MaxSpeedMS;} public float GetMaxEngineRPM(){return MaxEngineRPM;} public float GetWingSpan(){return WingSpanMeters;} public float GetGasCelCapacity(){return GasCelCapacity;} + public boolean GetAdheresToGravity(){return AdheresToGravity;} } diff --git a/src/main/resources/data/forge/tags/entity_types/hvf_camera_affected_vehicle.json b/src/main/resources/data/forge/tags/entity_types/hvf_camera_affected_vehicle.json index 357ebc1..061d3fe 100644 --- a/src/main/resources/data/forge/tags/entity_types/hvf_camera_affected_vehicle.json +++ b/src/main/resources/data/forge/tags/entity_types/hvf_camera_affected_vehicle.json @@ -1,6 +1,7 @@ { "replace": false, "values": [ - "hals_vehicle_framework:aeroplane" + "hals_vehicle_framework:aeroplane", + "hals_vehicle_framework:airboat" ] } \ No newline at end of file