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
Handle less than 1 regen and removing Regen logic #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Structure of the system looks good, only small issues here and there.
invokeRegenOperations(currentTime); | ||
if (currentTime > lastTick + CHECK_INTERVAL) { | ||
invokeRegenOperations(currentTime); | ||
lastTick = currentTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very minor point but to reduce the work done every frame you should do the addition of CHECK_INTERVAL
here and not in the if condition
entity.removeComponent(RegenComponent.class); | ||
entity.send(new OnFullyHealedEvent(entity)); | ||
} | ||
entity.saveComponent(health); | ||
} | ||
} | ||
for (Long endTime : regenToBeRemoved) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you feel like being fancy you can use a lambda here.
Not suggesting that you do do this, leaving it as a loop is clear. But just giving you more info.
public void onRegenRemoved(DeactivateRegenEvent event, EntityRef entity, HealthComponent health, | ||
RegenComponent regen) { | ||
regenSortedByTime.remove(regen.getLowestEndTime(), entity); | ||
if (event.id.equals("all")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get these strings ("all"
and "baseRegen"
) as public static fields.
for (float value: regenValue.values()) { | ||
totalValue += value; | ||
} | ||
if (totalValue < 0) { | ||
totalValue = 0; | ||
remainder = Math.min(1, remainder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can actually do
remainder = totalValue % 1 //modulo 1
To get the remainder when dividing by 1.
This saves you having to floor to int and then subtract to get the return value
src/main/java/org/terasology/logic/health/event/DeactivateRegenEvent.java
Show resolved
Hide resolved
RegenComponent regen = entity.getComponent(RegenComponent.class); | ||
HealthComponent health = entity.getComponent(HealthComponent.class); | ||
if (health.nextRegenTick < currentTime) { | ||
if (health != null && health.nextRegenTick < currentTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added null check because NPE is thrown when blocks are destroyed.
@@ -33,6 +33,7 @@ | |||
import org.terasology.logic.health.event.OnFullyHealedEvent; | |||
import org.terasology.protobuf.EntityData; | |||
import org.terasology.registry.In; | |||
import org.terasology.world.generation.BaseFacetedWorldGenerator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidental import?
Tested out and merged :-) I added a tiny commit to remove a few unused bits. |
Solves #9
How to test:
How to test multiplayer