update ReadME, as well as some extra stuff for setting up functionality
This commit is contained in:
@@ -4,37 +4,42 @@ a simple to use but powerful vehicle library for Minecraft Forge 1.16.5, 1.20.1,
|
|||||||
## Getting Started
|
## Getting Started
|
||||||
after importing the library, to create an entity with the framework you structure it as so
|
after importing the library, to create an entity with the framework you structure it as so
|
||||||
### The entity itself:
|
### 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)
|
private static final VehicleBuildInfo buildInfo = new VehicleBuildInfo(VehicleClassification.Aeroplane)
|
||||||
.SetEngineCount(2) //example properties
|
.SetEngineCount(1) //Sets the number of engines a vehicle has
|
||||||
.SetEngineType(EngineCategories.Aircraft_Propeller) //this example uses the Zepplin vehicle properties
|
.SetEngineType(EngineCategories.Aircraft_Propeller) //Sets the engine type of the vehicle, such as propeller, jet, piston engine etc...
|
||||||
.SetMaxEngineRPM(3000)
|
.SetMaxEngineRPM(3000) //Exceeding this RPM damages the engine
|
||||||
.SetMaxSpeedMS(70)
|
.SetWingSpan(2) //Aeroplane exclusive property, determines where the collision points for the wings are
|
||||||
.SetGasCelCount(8)
|
.SetMaxSpeedMS(70) //Sets the fastest the vehicle can go under its own power
|
||||||
.SetGasCelCapacity(1000);
|
.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) {
|
public AeroplaneExample(EntityType<?> Type, World WorldIn) {
|
||||||
//The parameters in this super are the Type, the World, an array of seat positions and the vehicle build info
|
super(Type, WorldIn, buildInfo); //Super takes in the default entity parameters plus the build information of the vehicle
|
||||||
//specify as many seat positions as you want in this array as it loads all of them as player seats on the entity
|
VehicleCameraSettings.AddEntityCameraPreset(this.getType(), //This sets the custom camera Offset, Rotation, External FOV and Internal FOV
|
||||||
|
new VehicleCameraPreset(new Vector3f(0,0,4.5f),
|
||||||
super(Type, WorldIn, new Vector3d[]{new Vector3d(0.0D, -1D, 0.0D)}, buildInfo); // The super class handles everything entity related
|
new Vector3f(0,0,0),70,60));
|
||||||
|
|
||||||
//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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void TickUpdateEvent(){
|
public void TickUpdateEvent(){
|
||||||
//this is called by the super class every tick update
|
//Tick event that happens on both client and server
|
||||||
//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
|
|
||||||
|
@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
|
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)
|
@OnlyIn(Dist.CLIENT)
|
||||||
public class MyVehicleRenderer extends VehicleBaseRenderer {
|
public class AeroplaneRenderer extends VehicleBaseRenderer {
|
||||||
public AirboatRenderer(EntityRendererManager renderManagerIn) {
|
|
||||||
super(renderManagerIn, new EntityModel<?>[]{new MyVehicleModel()},"textures/entities/MyVehicleTexture.png");
|
public AeroplaneRenderer(EntityRendererManager renderManagerIn) {
|
||||||
|
super(renderManagerIn, new EntityModel<?>[]{new AeroplaneModel()},"textures/entities/biplaneupdated.png");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### Registering the entity
|
### Registering the entity
|
||||||
you register the entity as if it were any other entity
|
you register the entity as if it were any other entity
|
||||||
```
|
```
|
||||||
public static DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, MOD_ID);
|
public class ModEntities {
|
||||||
|
public static DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES, Halsvehicleframework.MOD_ID);
|
||||||
|
|
||||||
public static final RegistryObject<EntityType<MyVehicleClass>> MY_VEHICLE =
|
public static final RegistryObject<EntityType<Aeroplane>> AEROPLANE =
|
||||||
ENTITY_TYPES.register("my_vehicle", ()-> EntityType.Builder.create(MyVehicleClass::new,
|
ENTITY_TYPES.register("aeroplane", ()-> EntityType.Builder.create(Aeroplane::new,
|
||||||
EntityClassification.MISC ).size(3f,2f).build(new ResourceLocation(MOD_ID, "my_vehicle").toString()));
|
EntityClassification.MISC ).size(3f,2f).build(new ResourceLocation(Halsvehicleframework.MOD_ID, "aeroplane").toString()));
|
||||||
|
}
|
||||||
```
|
```
|
||||||
### Registering the renderer
|
### Registering the renderer
|
||||||
this is also the same as if it were any other entity, it is put in the client event handler
|
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 {
|
public class ClientEventHandler {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void init(final FMLClientSetupEvent event) {
|
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<Entity> {
|
||||||
|
private final ModelRenderer Body;
|
||||||
|
private final ModelRenderer cube_r1;
|
||||||
|
private final ModelRenderer cube_r2;
|
||||||
|
...
|
||||||
|
```
|
||||||
|
After:
|
||||||
|
```
|
||||||
|
public class AeroplaneModel extends EntityModel<VehicleBaseEntity> {
|
||||||
|
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
|
||||||
|
}
|
||||||
```
|
```
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package net.halbear.hvf.Util.VehicleData;
|
||||||
|
|
||||||
|
public enum FuelType {
|
||||||
|
FossilFuelsIncludingWood,
|
||||||
|
FossilFuelsExcludingWood,
|
||||||
|
Kerosene,
|
||||||
|
AviationPetrol,
|
||||||
|
Diesel,
|
||||||
|
Petrol,
|
||||||
|
SolidPropellant
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.halbear.hvf.Entity.Renderer;
|
package net.halbear.hvf.Util.VehicleData;
|
||||||
|
|
||||||
public enum PhysicsPreset {
|
public enum PhysicsPreset {
|
||||||
SimpleMinecraft,
|
SimpleMinecraft,
|
||||||
@@ -11,6 +11,7 @@ public class VehicleBuildInfo {
|
|||||||
private Vector3d CentreOfMassOffset = new Vector3d(0,0,0);
|
private Vector3d CentreOfMassOffset = new Vector3d(0,0,0);
|
||||||
private int EngineCount;
|
private int EngineCount;
|
||||||
private EngineCategories EngineType;
|
private EngineCategories EngineType;
|
||||||
|
private FuelType FuelType;
|
||||||
private int GasCelCount;
|
private int GasCelCount;
|
||||||
private float MaxSpeedMS;
|
private float MaxSpeedMS;
|
||||||
private float MaxEngineRPM;
|
private float MaxEngineRPM;
|
||||||
@@ -20,10 +21,19 @@ public class VehicleBuildInfo {
|
|||||||
private boolean AdheresToGravity = true;
|
private boolean AdheresToGravity = true;
|
||||||
private Vector3d PilotSeat;
|
private Vector3d PilotSeat;
|
||||||
private List<Vector3d> PassengerSeats = new ArrayList<>();
|
private List<Vector3d> PassengerSeats = new ArrayList<>();
|
||||||
|
private List<Float> FuelTanks = new ArrayList<>();
|
||||||
|
|
||||||
public VehicleBuildInfo AddPassengerSeat(Vector3d SeatIn){
|
public VehicleBuildInfo AddPassengerSeat(Vector3d SeatIn){
|
||||||
PassengerSeats.add(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){
|
public VehicleBuildInfo SetPilotSeat(Vector3d SeatIn){
|
||||||
PilotSeat = SeatIn;
|
PilotSeat = SeatIn;
|
||||||
@@ -90,6 +100,8 @@ public class VehicleBuildInfo {
|
|||||||
public double GetGravityStrength(){return Gravity;}
|
public double GetGravityStrength(){return Gravity;}
|
||||||
public Vector3d GetPilotSeat(){return PilotSeat;}
|
public Vector3d GetPilotSeat(){return PilotSeat;}
|
||||||
public List<Vector3d> GetPassengerSeats(){return PassengerSeats;}
|
public List<Vector3d> GetPassengerSeats(){return PassengerSeats;}
|
||||||
|
public List<Float> GetFuelTanks(){return FuelTanks;}
|
||||||
|
public FuelType GetFuelType(){return this.FuelType;}
|
||||||
public float GetMaxSpeedMS(){return MaxSpeedMS;}
|
public float GetMaxSpeedMS(){return MaxSpeedMS;}
|
||||||
public float GetMaxEngineRPM(){return MaxEngineRPM;}
|
public float GetMaxEngineRPM(){return MaxEngineRPM;}
|
||||||
public float GetWingSpan(){return WingSpanMeters;}
|
public float GetWingSpan(){return WingSpanMeters;}
|
||||||
|
|||||||
Reference in New Issue
Block a user