Skip to content

Commit

Permalink
qa: address PMD AvoidBranchingStatementAsLastInLoop findings
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrueckert committed Aug 18, 2024
1 parent ae226a2 commit 6fcb9bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,15 @@ private Component getNext() {
if (componentsToAdd.containsKey(result.getClass())) {
throw new IllegalStateException("Requested to add component that was already defined for this entity");
}
if (componentsToRemove.contains(result.getClass())) {
continue;
if (!componentsToRemove.contains(result.getClass())) {
return result;
}
return result;
}
while (addedIterator.hasNext()) {
final Component result = addedIterator.next();
if (componentsToRemove.contains(result.getClass())) {
continue;
if (!componentsToRemove.contains(result.getClass())) {
return result;
}
return result;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@ protected Vector3f findSpawnPosition(World world, Vector2i pos, int searchRadius
// nothing above sea level found
for (Vector2ic test : spiral) {
Optional<Float> val = getWorld.apply(test);
if (!val.isPresent()) {
continue;
if (val.isPresent()) {
return new Vector3f(test.x(), TeraMath.floorToInt(val.get()), test.y());
}
return new Vector3f(test.x(), TeraMath.floorToInt(val.get()), test.y());
}

throw new IllegalStateException("No spawn location found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.engine.world.time;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.core.PathManager;
import org.terasology.engine.core.Time;
import org.terasology.engine.entitySystem.entity.EntityManager;
import org.terasology.engine.entitySystem.entity.EntityRef;
Expand All @@ -10,9 +13,12 @@
import org.terasology.engine.registry.In;
import org.terasology.engine.world.WorldComponent;

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicLong;

public class WorldTimeImpl extends BaseComponentSystem implements WorldTime, UpdateSubscriberSystem {
private static final Logger LOGGER = LoggerFactory.getLogger(WorldTimeImpl.class);

private static final float WORLD_TIME_MULTIPLIER = 48f;

Expand Down Expand Up @@ -68,17 +74,14 @@ public void update(float delta) {

if (startTick != endTick) {
long tick = endTime - endTime % TICK_EVENT_RATE;
getWorldEntity().send(new WorldTimeEvent(tick));
for (EntityRef e : entityManager.getEntitiesWith(WorldComponent.class)) {
// this may not be called if there's no entity with World Component (yet)
// TODO: consider catching / logging this case (someplace better than here)
e.send(new WorldTimeEvent(tick));
}
}

// TODO: consider sending a DailyTick (independent from solar events such as midnight)
}
}

private EntityRef getWorldEntity() {
for (EntityRef entity : entityManager.getEntitiesWith(WorldComponent.class)) {
return entity;
}
return EntityRef.NULL;
}
}

0 comments on commit 6fcb9bd

Please sign in to comment.