Hi
I’m using parameterized types in the entity container, and something is breaking. As far as I can see in the git-repo, it’s already checking on the type of the parameter - but the cast error is occuring in the initialize of the container:
19:36:15,696 ERROR [LegacyApplication] Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
at com.simsilica.es.EntityContainer.<init>(EntityContainer.java:96) ~[sio2-1.1.0.jar:?]
at com.simsilica.es.EntityContainer.<init>(EntityContainer.java:83) ~[sio2-1.1.0.jar:?]
at example.es.states.GDXAIState$MobSeekers.<init>(GDXAIState.java:160) ~[main/:?]
Here’s my container:
//Map entities to seeking behaviours
private class MobSeekers extends EntityContainer<SteeringBehavior<com.badlogic.gdx.math.Vector2>> {
public MobSeekers(EntityData ed) {
super(ed, SteeringSeek.class);
}
@Override
protected SteeringBehavior<com.badlogic.gdx.math.Vector2>[] getArray() {
return super.getArray();
}
@Override
protected SteeringBehavior<com.badlogic.gdx.math.Vector2> addObject(Entity e) {
SteeringSeek ss = e.get(SteeringSeek.class);
//The driver to create a behaviour for
MobDriver steerable = mobSteerables.getObject(e.getId());
//The target location
Entity targetEntity = ed.getEntity(ss.getTarget(), Position.class);
Location seekable = mobSeekables.getObject(targetEntity.getId());
SteeringBehavior<com.badlogic.gdx.math.Vector2> behaviour = new Seek(steerable, seekable);
mobSeekerMap.put(e.getId(), behaviour);
return behaviour;
}
@Override
protected void updateObject(SteeringBehavior<Vector2> object, Entity e) {
}
@Override
protected void removeObject(SteeringBehavior<Vector2> object, Entity e) {
mobSeekerMap.remove(e.getId());
}
public void calculateSteeringAndCreateForces() {
mobSeekerMap.entrySet().forEach((entry) -> {
EntityId eId = entry.getKey();
SteeringBehavior<Vector2> behaviour = entry.getValue();
SteeringAcceleration<Vector2> steeringOutput = new SteeringAcceleration<>(new Vector2());
behaviour.calculateSteering(steeringOutput);
Force f = new Force(steeringOutput.linear.x, steeringOutput.linear.y);
GameEntities.createForce(eId, f, convert(behaviour.getOwner().getPosition()), ed);
});
}
}
And the EntityComponent is simple:
public class SteeringSeek implements EntityComponent {
EntityId target;
public EntityId getTarget() {
return target;
}
public SteeringSeek(EntityId target) {
this.target = target;
}
}
This is where the error occurs in EntityContainer:
If anyone has any idea of a workaround or fix, let me know.