public class IncreasedDamageTakenProcessor extends BaseAppState {
static Logger log = LoggerFactory.getLogger(IncreasedDamageTakenProcessor.class);
private EntityData ed;
private EntitySet entities;
public static int increasedDamageTaken = 0;
@Override
protected void initialize(Application app) {
ed = getState(EntityDataState.class).getEntityData();
//entities = ed.getEntities(IncreasedDamageTaken.class, Touching.class);
entities = ed.getEntities(Filters.fieldEquals(Touching.class, "touched", FightAppState.pppp),IncreasedDamageTaken.class);
}
@Override
protected void cleanup(Application app) {
// Release the entity set we grabbed previously
entities.release();
entities = null;
}
@Override
public void update(float tpf) {
entities.applyChanges();
int idt = 0;
for (Entity e : entities) {
idt += ed.getComponent(e.getId(), IncreasedDamageTaken.class).getValue();
}
increasedDamageTaken = idt;
ed.setComponent(FightAppState.pppp, new IncreasedDamageTaken(idt));
System.out.println("IDT: "+increasedDamageTaken);
}
@Override
protected void onEnable() {
}
@Override
protected void onDisable() {
}
}
Basically I read the āincreaseddamageā component that are ātouchingā an element, and apply the sum as a component to the entity they were touching.
However, for each tpf the value is counted again. The explanation could be that the element is ātouchingā himself but thatās not the case:
He only needs that if he wants to track add/changed/removed⦠if you just iterate over the entities every frame then you donāt need that. Just applyChanges() is fine.
The rest is true, though. Just because you filter on something doesnāt mean itās included in the components list.
And Iām curious what FightAppState.pppp is because that looks super-duper strange for three or four different reasons.
The whole thing looks very strange. Like you are only trying to edit one entity⦠in which case EntitySet is like using a 20 ton truck to swat a fly. Edit: Except I think I know why now⦠but Iād still be curious why you are only doing this for one entity instead of all entities that might take damage.
If you donāt do it like that⦠then you might as well leave the filter out because it canāt be doing anything.
Itās still a bit unclear what you are actually trying to do and whether youāve actually added debugging to see whatās going on. My first step would have been to stick printlns in to see whatās going on.
public class Touching implements EntityComponent {
private final EntityId touched;
public Touching() {
touched = null;
}
public Touching(EntityId touched){
this.touched = touched;
}
public EntityId getTouched() {
return touched;
}
}
How is testing done with Filters.fieldEquals(Touching.class, "touched", FightAppState.pppp ?
It is always false⦠maybe it uses == instead of equals()? And if yes, how should I rectify it? Store the entityid as Long?
Canāt see how you are determining this. Because your earlier code would have definitely because you werenāt retrieving the component so the entity would never have had the component to test.
Iāll provide an example similar to things I use all the time just in case this isnāt clear still.
Letās say we have InContainer which points to a container and ContainerSlot which defines where in the container we might be. Now letās say I want to get all of a particular containers contents. I can use:
ā¦and I will get all of the entities that have all of those components and also have the InContainer component that has the ācontainerā Iām interested in.