Skip to content

Added some features #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ This addon adds new features to DynamX :
- Klaxon and siren
- Fuel tank
- Immatriculation plates
- Speed display on the vehicle
- Speed, gear and speed limit display on the vehicle
- Needle

### How to add modules:

Expand Down Expand Up @@ -71,6 +72,55 @@ FuelTank#Op{
}
```

#### Better speed-display

```
TextInfo#Op{
Position: 0 0 0
Scale: 1 1 1
Rotation: 0 0 0
Color: 0 0 0
DetailToShow: GEAR
CarStartedReact: True
}
```

The `DetailToShow` can be one of the following:
- GEAR
- SPEED
- SPEEDLIMITOR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPEED_LIMITER*


It will display the current gear, speed or speedlimitor value at the position.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

speed limiter aussi du coup


The `CarStartedReact` can be `True` or `False` and will enable or disable the display when the car is started.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça veut pas dire grand chose "CarStartedReact"


### DashboardNeedle

```
DashboardNeedle_2 {
Position: 0 0 0
Rotation: 0 0 -120
ObjectName: speedneedle
NeedleMaxTurn: 160
DashboardMaxValue: 6000
NeedleType: RPM
}
```

| Key | Value |
|------------------- |------------------------------------------ |
| Rotation | Default rotation |
| Position | Default position |
| ObjectName | Name of the object in the 3D model |
| NeedleMaxTurn | Max rotation in degrees on the dashboard |
| DashboardMaxValue | Max value displayed on dashboard |
| NeedleType | It can be `RPM` or `SPEED` |

<img src="exemple.png" width="50%">
<br>

> Here for RPM, max DashboardMaxValue is 6000 and max NeedleMaxTurn is 160.

## Links

DynamX website: https://dynamx.fr
Expand Down
Binary file added exemple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion src/main/java/fr/dynamx/addons/basics/BasicsAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import fr.dynamx.addons.basics.client.BasicsAddonController;
import fr.dynamx.addons.basics.client.InteractionKeyController;
import fr.dynamx.addons.basics.common.infos.BasicsItemInfo;
import fr.dynamx.addons.basics.common.infos.DashboardNeedleInfo.EnumDashboardNeedleType;
import fr.dynamx.addons.basics.common.infos.DashboardTextInfos.EnumDashboardTextType;
import fr.dynamx.addons.basics.server.CommandBasicsSpawn;
import fr.dynamx.addons.basics.utils.FuelJerrycanUtils;
import fr.dynamx.addons.basics.utils.VehicleKeyUtils;
import fr.dynamx.api.contentpack.DynamXAddon;
import fr.dynamx.api.contentpack.registry.DefinitionType;
import fr.dynamx.common.contentpack.type.objects.ItemObject;
import fr.dynamx.common.items.DynamXItem;
import fr.dynamx.common.items.DynamXItemRegistry;
Expand All @@ -20,7 +23,6 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.relauncher.Side;
Expand All @@ -47,6 +49,8 @@ public static void initAddon() {
}
registerKey();
registerJerrycan();
new DefinitionType<>(EnumDashboardNeedleType.class, EnumDashboardNeedleType::fromString, "type.dashboardneedletype");
new DefinitionType<>(EnumDashboardTextType.class, EnumDashboardTextType::fromString, "type.dashboardtexttype");
}

private static void registerKey() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package fr.dynamx.addons.basics.common.infos;

import com.jme3.math.Vector3f;
import fr.dynamx.addons.basics.utils.TextUtils;
import fr.dynamx.api.contentpack.object.part.BasePart;
import fr.dynamx.api.contentpack.object.part.IDrawablePart;
import fr.dynamx.api.contentpack.registry.DefinitionType;
import fr.dynamx.api.contentpack.registry.PackFileProperty;
import fr.dynamx.api.contentpack.registry.RegisteredSubInfoType;
import fr.dynamx.api.contentpack.registry.SubInfoTypeRegistries;
import fr.dynamx.api.entities.VehicleEntityProperties;
import fr.dynamx.client.renders.model.renderer.DxModelRenderer;
import fr.dynamx.client.renders.scene.EntityRenderContext;
import fr.dynamx.client.renders.scene.SceneBuilder;
import fr.dynamx.client.renders.scene.SceneGraph;
import fr.dynamx.common.contentpack.type.vehicle.ModularVehicleInfo;
import fr.dynamx.common.entities.BaseVehicleEntity;
import fr.dynamx.common.entities.modules.engines.CarEngineModule;
import fr.dynamx.utils.DynamXUtils;
import net.minecraft.client.renderer.GlStateManager;
import org.lwjgl.opengl.GL11;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;

@RegisteredSubInfoType(name = "DashboardNeedle", registries = SubInfoTypeRegistries.WHEELED_VEHICLES, strictName = false)
public class DashboardNeedleInfo extends BasePart<ModularVehicleInfo> implements IDrawablePart<BaseVehicleEntity<?>, ModularVehicleInfo> {
@PackFileProperty(configNames = "Rotation", type = DefinitionType.DynamXDefinitionTypes.VECTOR3F)
protected Vector3f rotation;

@PackFileProperty(configNames = "ObjectName", required = false, defaultValue = "speedneedle")
protected String objectName;

@PackFileProperty(configNames = "NeedleMaxTurn", required = false, defaultValue = "140", description = "common.NeedleMaxTurn")
protected int needleMaxTurn;

@PackFileProperty(configNames = "DashboardMaxValue", required = false, defaultValue = "140", description = "common.DashboardMaxSpeed")
protected int dashboardMaxValue;

@PackFileProperty(configNames = "DependsOnNode", required = false, description = "common.DependsOnNode")
protected String nodeDependingOnName;

@PackFileProperty(configNames = "NeedleType", required = false, defaultValue = "SPEED", description = "common.NeedleType")
protected EnumDashboardNeedleType needleType;

@Override
public String getNodeName() {
return getPartName();
}

@Override
public String getObjectName() {
return this.objectName;
}

@Override
public void addToSceneGraph(ModularVehicleInfo packInfo, SceneBuilder<BaseVehicleEntity<?>, ModularVehicleInfo> sceneBuilder) {
if (nodeDependingOnName != null) {
sceneBuilder.addNode(this, nodeDependingOnName, getNodeName());
} else {
sceneBuilder.addNode(this, getNodeName());
}
}

@Override
public SceneGraph<BaseVehicleEntity<?>, ModularVehicleInfo> createSceneGraph(Vector3f modelScale, List<SceneGraph<BaseVehicleEntity<?>, ModularVehicleInfo>> childGraph) {
if (childGraph != null) throw new IllegalArgumentException("DashboardNeedleInfo can't have children parts");
return new SpeedNeedleNode<>(modelScale, null);
}

@Override
public String getName() {
return "PartShape named " + getPartName() + " in " + Objects.requireNonNull(getOwner()).getName();
}

public int getNeedleMaxTurn() {
return needleMaxTurn;
}

public int getDashboardMaxValue() {
return dashboardMaxValue;
}

public EnumDashboardNeedleType getNeedleType() {
return needleType;
}

public Vector3f getRotation() {
return rotation;
}

public String getNodeDependingOnName() {
return this.nodeDependingOnName;
}

Comment on lines +77 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lombok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Précision : il est pas configuré sur l'env du BasicsAddon, donc on l'ajoutera surement nous-mêmes

public DashboardNeedleInfo(ModularVehicleInfo owner, String partName) {
super(owner, partName);
}


class SpeedNeedleNode<T extends BaseVehicleEntity<?>, A extends ModularVehicleInfo> extends SceneGraph.Node<T, A> {

public SpeedNeedleNode(Vector3f scale, List<SceneGraph<T, A>> linkedChilds) {
super(null, null, scale, linkedChilds);
}

@Override
public void render(@Nullable T entity, EntityRenderContext entityRenderContext, A packInfo) {
if (entity == null) return;
DxModelRenderer vehicleModel = entityRenderContext.getModel();
byte b = entityRenderContext.getTextureId();
if (entityRenderContext.getModel().containsObjectOrNode(DashboardNeedleInfo.this.getObjectName()) && entity.getModuleByType(CarEngineModule.class) != null && DashboardNeedleInfo.this.getPosition() != null) {
GlStateManager.pushMatrix();
Vector3f pos = DashboardNeedleInfo.this.getPosition();
GL11.glTranslatef(pos.x, pos.y, pos.z);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GlStateManager au lei de GL11

TextUtils.makeGLRotation(getRotation());
switch (DashboardNeedleInfo.this.getNeedleType()) {
case RPM:
int rpms = Math.round(entity.getModuleByType(CarEngineModule.class).getEngineProperty(VehicleEntityProperties.EnumEngineProperties.REVS) * 10000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux faire une variable interne de entity.getModuleByType(CarEngineModule.class) et l'utiliser plusieurs fois au lieu de rappeler chaque fois

GlStateManager.rotate((float) DashboardNeedleInfo.this.needleMaxTurn * rpms / DashboardNeedleInfo.this.dashboardMaxValue, 0, 0, 1);
break;
case SPEED:
GlStateManager.rotate((float) DashboardNeedleInfo.this.needleMaxTurn * DynamXUtils.getSpeed(entity) / DashboardNeedleInfo.this.dashboardMaxValue, 0, 0, 1);
break;
}
vehicleModel.renderGroup(DashboardNeedleInfo.this.getObjectName(), b, entityRenderContext.isUseVanillaRender());
GlStateManager.popMatrix();
}
}
}

public enum EnumDashboardNeedleType {
SPEED, RPM;

public static EnumDashboardNeedleType fromString(String targetName) {
for (EnumDashboardNeedleType dashboardNeedleType : values()) {
if (dashboardNeedleType.name().equalsIgnoreCase(targetName)) {
return dashboardNeedleType;
}
}
throw new IllegalArgumentException("Invalid DashboardNeedleType value '" + targetName + "'");
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package fr.dynamx.addons.basics.common.infos;

import com.jme3.math.Vector3f;
import fr.dynamx.addons.basics.BasicsAddon;
import fr.dynamx.addons.basics.utils.TextUtils;
import fr.dynamx.api.contentpack.object.part.BasePart;
import fr.dynamx.api.contentpack.object.part.IDrawablePart;
import fr.dynamx.api.contentpack.registry.DefinitionType;
import fr.dynamx.api.contentpack.registry.PackFileProperty;
import fr.dynamx.api.contentpack.registry.RegisteredSubInfoType;
import fr.dynamx.api.contentpack.registry.SubInfoTypeRegistries;
import fr.dynamx.api.entities.VehicleEntityProperties;
import fr.dynamx.client.renders.scene.EntityRenderContext;
import fr.dynamx.client.renders.scene.SceneBuilder;
import fr.dynamx.client.renders.scene.SceneGraph;
import fr.dynamx.common.contentpack.type.vehicle.ModularVehicleInfo;
import fr.dynamx.common.entities.BaseVehicleEntity;
import fr.dynamx.common.entities.modules.engines.CarEngineModule;
import fr.dynamx.utils.DynamXUtils;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;

@RegisteredSubInfoType(name = "TextInfo", registries = {SubInfoTypeRegistries.WHEELED_VEHICLES}, strictName = false)
public class DashboardTextInfos extends BasePart<ModularVehicleInfo> implements IDrawablePart<BaseVehicleEntity<?>, ModularVehicleInfo> {
@PackFileProperty(configNames = "Rotation", type = DefinitionType.DynamXDefinitionTypes.VECTOR3F, description = "common.rotation")
protected Vector3f rotation;

@PackFileProperty(configNames = "Font", required = false)
protected String font = BasicsAddon.ID + ":e";

@PackFileProperty(configNames = "DetailToShow", required = false, defaultValue = "GEAR")
protected EnumDashboardTextType detailToShow;
@PackFileProperty(configNames = "CarStartedReact", required = false, defaultValue = "false", type = DefinitionType.DynamXDefinitionTypes.BOOL)
protected boolean carStartedReact;

@PackFileProperty(configNames = "Color", description = "common.color", required = false)
protected int[] color = new int[]{10, 10, 10};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilise un Vector3f please


@PackFileProperty(configNames = "DependsOnNode", required = false, description = "common.DependsOnNode")
protected String nodeDependingOnName;

public DashboardTextInfos(ModularVehicleInfo owner, String partName) {
super(owner, partName);
}

@Override
public void appendTo(ModularVehicleInfo owner) {
owner.addSubProperty(this);
}

public Vector3f getRotation() {
return rotation;
}

public int[] getColor() {
return color;
}

public boolean isCarStartedReact() {
return carStartedReact;
}

public String getFont() {
return font;
}

public EnumDashboardTextType getDetailToShow() {
return detailToShow;
}
Comment on lines +53 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lombok


@Override
public String getName() {
return "PartShape named " + getPartName() + " in " + getOwner().getName();
}

@Override
public String getObjectName() {
return null;
}


@Override
public String getNodeName() {

return getPartName();
}

@Override
public void addToSceneGraph(ModularVehicleInfo packInfo, SceneBuilder<BaseVehicleEntity<?>, ModularVehicleInfo> sceneBuilder) {
if (nodeDependingOnName != null) {
sceneBuilder.addNode(this, nodeDependingOnName, getNodeName());
} else {
sceneBuilder.addNode(this, getNodeName());
}
}

@Override
public SceneGraph<BaseVehicleEntity<?>, ModularVehicleInfo> createSceneGraph(Vector3f modelScale, List<SceneGraph<BaseVehicleEntity<?>, ModularVehicleInfo>> childGraph) {
if (childGraph != null) throw new IllegalArgumentException("TextInfo can't have children parts");
return new SpeedDisplayNode<>(modelScale, null);
}

class SpeedDisplayNode<T extends BaseVehicleEntity<?>, A extends ModularVehicleInfo> extends SceneGraph.Node<T, A> {
public SpeedDisplayNode(Vector3f scale, List<SceneGraph<T, A>> linkedChilds) {
super(null, null, scale, linkedChilds);
}

@Override
public void render(@Nullable T entity, EntityRenderContext entityRenderContext, A packInfo) {
if (entity == null) return;
if (DashboardTextInfos.this.getRotation() != null) {
if (entity.getModuleByType(CarEngineModule.class).getPhysicsHandler().getEngine().isStarted() && DashboardTextInfos.this.isCarStartedReact()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meme chose pour entity.getModuleByType(CarEngineModule.class)

String value = "";
switch (DashboardTextInfos.this.getDetailToShow()) {
case GEAR:
float gear = entity.getModuleByType(CarEngineModule.class).getEngineProperty(VehicleEntityProperties.EnumEngineProperties.ACTIVE_GEAR);
if (gear == 0) value = "N";
else if (gear == -1) value = "R" + (int) Math.abs(gear);
else value = "D" + (int) gear;
break;
case SPEEDLIMITOR:
int tempvalue = Math.round(entity.getModuleByType(CarEngineModule.class).getSpeedLimit());
if (tempvalue != 0 & tempvalue < 10000000) value = String.valueOf(tempvalue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu peux utiliser une condition ternaire et peut être utiliser Integer.MAX_VALUE au lieu de 100000

else value = "";
break;
case SPEED:
value = String.valueOf(DynamXUtils.getSpeed(entity));
break;
}
TextUtils.drawText(DashboardTextInfos.this.getPosition(), DashboardTextInfos.this.getScale(), DashboardTextInfos.this.getRotation(), value, getColor(), getFont());
}
}
}
}

public enum EnumDashboardTextType {
SPEED, GEAR, SPEEDLIMITOR;

public static EnumDashboardTextType fromString(String targetName) {
for (EnumDashboardTextType dashboardNeedleType : values()) {
if (dashboardNeedleType.name().equalsIgnoreCase(targetName)) {
return dashboardNeedleType;
}
}
throw new IllegalArgumentException("Invalid EnumDashboardTextType value '" + targetName + "'");
}
}
}
Loading