From 41504fc1f97b76d877bb56ef7e4d11e1e154f0a0 Mon Sep 17 00:00:00 2001 From: Halbear Date: Mon, 25 May 2026 23:34:07 +0100 Subject: [PATCH] update ReadME, as well as some extra stuff for setting up functionality --- ReadMe.md | 104 ++++++++++++------ .../hvf/Util/VehicleData/FuelType.java | 11 ++ .../VehicleData}/PhysicsPreset.java | 2 +- .../Util/VehicleData/VehicleBuildInfo.java | 14 ++- 4 files changed, 96 insertions(+), 35 deletions(-) create mode 100644 src/main/java/net/halbear/hvf/Util/VehicleData/FuelType.java rename src/main/java/net/halbear/hvf/{Entity/Renderer => Util/VehicleData}/PhysicsPreset.java (72%) diff --git a/ReadMe.md b/ReadMe.md index ef73299..9c3e52c 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -4,37 +4,42 @@ a simple to use but powerful vehicle library for Minecraft Forge 1.16.5, 1.20.1, ## Getting Started after importing the library, to create an entity with the framework you structure it as so ### The entity itself: +this will be an example of an Aeroplane ``` -public class MyVehicleClass extends VehicleBaseEntity { +public class AeroplaneExample extends VehicleBaseEntity { - private static final VehicleBuildInfo buildInfo = new VehicleBuildInfo(VehicleClassification.Zepplin) - .SetEngineCount(2) //example properties - .SetEngineType(EngineCategories.Aircraft_Propeller) //this example uses the Zepplin vehicle properties - .SetMaxEngineRPM(3000) - .SetMaxSpeedMS(70) - .SetGasCelCount(8) - .SetGasCelCapacity(1000); + private static final VehicleBuildInfo buildInfo = new VehicleBuildInfo(VehicleClassification.Aeroplane) + .SetEngineCount(1) //Sets the number of engines a vehicle has + .SetEngineType(EngineCategories.Aircraft_Propeller) //Sets the engine type of the vehicle, such as propeller, jet, piston engine etc... + .SetMaxEngineRPM(3000) //Exceeding this RPM damages the engine + .SetWingSpan(2) //Aeroplane exclusive property, determines where the collision points for the wings are + .SetMaxSpeedMS(70) //Sets the fastest the vehicle can go under its own power + .SetCentreOfMass(new Vector3d(0,0,2)) //Offsets the pivot point for physics based rotation added with advanced physics + .SetPilotSeat(new Vector3d(0.0D, -1D, 0.0D)) //Sets the seat that controls the vehicle when a player sits in it, a vehicle with no pilot seat but passenger seats will use the first passenger seat as a pilot seat + .AddPassengerSeat(new Vector3d(0.0D,-1D,-1D)) //Specifies seats players can sit in which can't control the vehicle, You can add an infinite number of passenger seats + .SetFuelType(FuelType.AviationPetrol) //Fuel type, controlled by tags, this framework does not include the actual fluids/fuels so you can decide on what fuel it uses + .AddFuelTank(1000F); //Adds a fillable fuel tank, vehicles can have multiple separate fillable fuel tanks - public MyVehicleClass(EntityType Type, World WorldIn) { - //The parameters in this super are the Type, the World, an array of seat positions and the vehicle build info - //specify as many seat positions as you want in this array as it loads all of them as player seats on the entity - - super(Type, WorldIn, new Vector3d[]{new Vector3d(0.0D, -1D, 0.0D)}, buildInfo); // The super class handles everything entity related - - //this allows you to completely customise how the camera is structure for the vehicle, - //the first Vector is position offset, the 2nd vector is rotation, - //and then the first float value is 1st person FOV with the 2nd float value being 3rd person FOV - - VehicleCameraSettings.AddEntityCameraPreset(this.getType(), - new VehicleCameraPreset(new Vector3f(0,4.0f, 16.0f), - new Vector3f(0,0,0),70,65f)); + public AeroplaneExample(EntityType Type, World WorldIn) { + super(Type, WorldIn, buildInfo); //Super takes in the default entity parameters plus the build information of the vehicle + VehicleCameraSettings.AddEntityCameraPreset(this.getType(), //This sets the custom camera Offset, Rotation, External FOV and Internal FOV + new VehicleCameraPreset(new Vector3f(0,0,4.5f), + new Vector3f(0,0,0),70,60)); } - + @Override public void TickUpdateEvent(){ - //this is called by the super class every tick update - //and is a safer way to add code without overriding what happens in the parent class - //you can still @Override the normal tick update though + //Tick event that happens on both client and server + } + + @Override + public void ServerSideTickEvent(){ + //Tick event that happens on only the server + } + + @Override + public void ClientSideTickEvent(){ + //Tick event that happens on only the Client } } ``` @@ -42,20 +47,23 @@ public class MyVehicleClass extends VehicleBaseEntity { this you put an array of models in but for this example it's an array of 1 size, this is so you can put multiple models for a single vehicle in, or make it dynamically swappable in game ``` @OnlyIn(Dist.CLIENT) -public class MyVehicleRenderer extends VehicleBaseRenderer { - public AirboatRenderer(EntityRendererManager renderManagerIn) { - super(renderManagerIn, new EntityModel[]{new MyVehicleModel()},"textures/entities/MyVehicleTexture.png"); +public class AeroplaneRenderer extends VehicleBaseRenderer { + + public AeroplaneRenderer(EntityRendererManager renderManagerIn) { + super(renderManagerIn, new EntityModel[]{new AeroplaneModel()},"textures/entities/biplaneupdated.png"); } } ``` ### Registering the entity you register the entity as if it were any other entity ``` - public static DeferredRegister> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, MOD_ID); +public class ModEntities { + public static DeferredRegister> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, Halsvehicleframework.MOD_ID); - public static final RegistryObject> MY_VEHICLE = - ENTITY_TYPES.register("my_vehicle", ()-> EntityType.Builder.create(MyVehicleClass::new, - EntityClassification.MISC ).size(3f,2f).build(new ResourceLocation(MOD_ID, "my_vehicle").toString())); + public static final RegistryObject> AEROPLANE = + ENTITY_TYPES.register("aeroplane", ()-> EntityType.Builder.create(Aeroplane::new, + EntityClassification.MISC ).size(3f,2f).build(new ResourceLocation(Halsvehicleframework.MOD_ID, "aeroplane").toString())); +} ``` ### Registering the renderer this is also the same as if it were any other entity, it is put in the client event handler @@ -64,7 +72,37 @@ this is also the same as if it were any other entity, it is put in the client ev public class ClientEventHandler { @SubscribeEvent public static void init(final FMLClientSetupEvent event) { - RenderingRegistry.registerEntityRenderingHandler(ModEntities.MY_VEHICLE.get(), MyVehicleRenderer::new); + RenderingRegistry.registerEntityRenderingHandler(ModEntities.AEROPLANE.get(), AeroplaneRenderer::new); } } +``` + + +## Handling Animation +To animate the models you need to modify the "Model" class generated by Blockbench or similar software for creating Java models\ +firstly you need to modify it to extend the "VehicleBaseEntity" class:\ +Before: +``` +public class AeroplaneModel extends EntityModel { + private final ModelRenderer Body; + private final ModelRenderer cube_r1; + private final ModelRenderer cube_r2; + ... +``` +After: +``` +public class AeroplaneModel extends EntityModel { + private final ModelRenderer Body; + private final ModelRenderer cube_r1; + private final ModelRenderer cube_r2; + ... +``` + +then you add whatever animations you want in the `setRotationAngles` function using the Vehicle Entity Animation Manager which has a series of premade animations, you do this by passing through the ModelRenderer part for your animated part, as seen here: +``` + @Override + public void setRotationAngles(VehicleBaseEntity entity, float f, float f1, float f2, float f3, float f4) { + Aeroplane aeroplane = (Aeroplane)entity; + aeroplane.GetAnimationManager().PropellerAnimation(propeller, aeroplane, AnimationAxis.Z_AXIS, false); //propeller is the name of the ModelRenderer which has the 3d models propeller in it + } ``` \ No newline at end of file diff --git a/src/main/java/net/halbear/hvf/Util/VehicleData/FuelType.java b/src/main/java/net/halbear/hvf/Util/VehicleData/FuelType.java new file mode 100644 index 0000000..c018178 --- /dev/null +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/FuelType.java @@ -0,0 +1,11 @@ +package net.halbear.hvf.Util.VehicleData; + +public enum FuelType { + FossilFuelsIncludingWood, + FossilFuelsExcludingWood, + Kerosene, + AviationPetrol, + Diesel, + Petrol, + SolidPropellant +} diff --git a/src/main/java/net/halbear/hvf/Entity/Renderer/PhysicsPreset.java b/src/main/java/net/halbear/hvf/Util/VehicleData/PhysicsPreset.java similarity index 72% rename from src/main/java/net/halbear/hvf/Entity/Renderer/PhysicsPreset.java rename to src/main/java/net/halbear/hvf/Util/VehicleData/PhysicsPreset.java index 8429891..ce8cd9d 100644 --- a/src/main/java/net/halbear/hvf/Entity/Renderer/PhysicsPreset.java +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/PhysicsPreset.java @@ -1,4 +1,4 @@ -package net.halbear.hvf.Entity.Renderer; +package net.halbear.hvf.Util.VehicleData; public enum PhysicsPreset { SimpleMinecraft, 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 0993820..d595e67 100644 --- a/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java +++ b/src/main/java/net/halbear/hvf/Util/VehicleData/VehicleBuildInfo.java @@ -11,6 +11,7 @@ public class VehicleBuildInfo { private Vector3d CentreOfMassOffset = new Vector3d(0,0,0); private int EngineCount; private EngineCategories EngineType; + private FuelType FuelType; private int GasCelCount; private float MaxSpeedMS; private float MaxEngineRPM; @@ -20,10 +21,19 @@ public class VehicleBuildInfo { private boolean AdheresToGravity = true; private Vector3d PilotSeat; private List PassengerSeats = new ArrayList<>(); + private List FuelTanks = new ArrayList<>(); public VehicleBuildInfo AddPassengerSeat(Vector3d SeatIn){ PassengerSeats.add(SeatIn); - return this; + return this; + } + public VehicleBuildInfo AddFuelTank(Float CapacityLitres){ + FuelTanks.add(CapacityLitres); + return this; + } + public VehicleBuildInfo SetFuelType(FuelType fuelType){ + this.FuelType = fuelType; + return this; } public VehicleBuildInfo SetPilotSeat(Vector3d SeatIn){ PilotSeat = SeatIn; @@ -90,6 +100,8 @@ public class VehicleBuildInfo { public double GetGravityStrength(){return Gravity;} public Vector3d GetPilotSeat(){return PilotSeat;} public List GetPassengerSeats(){return PassengerSeats;} + public List GetFuelTanks(){return FuelTanks;} + public FuelType GetFuelType(){return this.FuelType;} public float GetMaxSpeedMS(){return MaxSpeedMS;} public float GetMaxEngineRPM(){return MaxEngineRPM;} public float GetWingSpan(){return WingSpanMeters;}