Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,23 @@ public void add(EffectStack effectStack){

for (EffectStack effect : effects) {
if(effect.getEffect() == effectStack.getEffect()){
int amount;
if(effect.getAmount() + effectStack.getAmount() >= effect.getEffect().getMaxStack()){
amount = effect.getEffect().getMaxStack() - effect.getAmount();
}else{
amount = effectStack.getAmount();
}
int amount = Math.min(effectStack.getAmount(), effect.getEffect().getMaxStack() - effect.getAmount());
effect.add(amount,this);
if (EnvironmentHelper.isServerEnvironment()) NetworkHandler.sendToAllPlayers(new SyncEffectContainerForEntityNetworkMessage((Entity) this.getParent()));
syncEffectContainer();
return;
}
}

effects.add(effectStack);
if (EnvironmentHelper.isServerEnvironment()) NetworkHandler.sendToAllPlayers(new SyncEffectContainerForEntityNetworkMessage((Entity) this.getParent()));
syncEffectContainer();
}

public void subtract(EffectStack effectStack){
for (EffectStack effect : effects) {
if(effect.getEffect() == effectStack.getEffect()){
effect.subtract(effectStack.getAmount(),this);

if (EnvironmentHelper.isServerEnvironment()) NetworkHandler.sendToAllPlayers(new SyncEffectContainerForEntityNetworkMessage((Entity) this.getParent()));
syncEffectContainer();
return;
}
}
Expand All @@ -75,7 +70,7 @@ public void remove(Effect effect){
}
}

if (EnvironmentHelper.isServerEnvironment()) NetworkHandler.sendToAllPlayers(new SyncEffectContainerForEntityNetworkMessage((Entity) this.getParent()));
syncEffectContainer();
}
public void removeAll() {
List<EffectStack> copy = new ArrayList<>(effects);
Expand Down Expand Up @@ -129,4 +124,10 @@ public void loadFromNbt(CompoundTag tag){
}
}
}

private void syncEffectContainer() {
if (EnvironmentHelper.isServerEnvironment()) {
NetworkHandler.sendToAllPlayers(new SyncEffectContainerForEntityNetworkMessage((Entity) this.getParent()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,25 @@ public <T> void unpause(EffectContainer<T> container){
}
}

public <T> void finish(EffectContainer<T> effectContainer){
if(state == State.ACTIVE){
timeLeft = 0;
state = State.FINISHED;
effect.expired(this,effectContainer);
}
}

public <T> void tick(EffectContainer<T> effectContainer) {
if(state == State.ACTIVE){
if(effect.getTimeType() == EffectTimeType.PERMANENT){
effect.tick(this,effectContainer);
return;
}
if(timeLeft > 0){
if(effect.getTimeType() != EffectTimeType.PERMANENT) timeLeft--;
timeLeft--;
effect.tick(this,effectContainer);
} else {
state = State.FINISHED;
effect.expired(this,effectContainer);
this.finish(effectContainer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public static int getExtraHealth(Player player) {
* @param amount the amount of extra health they should have
*/
public static void setExtraHealth(Player player, int amount) {

EffectContainer<?> container = ((IHasEffects<?>) player).getContainer();

container.remove(Effects.EXTRA_HEALTH);
container.add(new EffectStack((IHasEffects<?>) player, Effects.EXTRA_HEALTH, amount));
EffectStack stack = new EffectStack((IHasEffects<?>) player, Effects.EXTRA_HEALTH, amount);
container.add(stack);
stack.start(container);
}

/**
Expand All @@ -40,9 +40,13 @@ public static void setExtraHealth(Player player, int amount) {
* @param amount the amount of extra health to add, on top of the amount they already have
*/
public static void addExtraHealth(Player player, int amount) {
((IHasEffects<?>) player).getContainer().add(new EffectStack((IHasEffects<?>) player, Effects.EXTRA_HEALTH, amount));
EffectStack stack = new EffectStack((IHasEffects<?>) player, Effects.EXTRA_HEALTH, amount);
EffectContainer<?> container = ((IHasEffects<?>) player).getContainer();
container.add(stack);
stack.start(container);
}


/**
* Get the total/max health of a player (20 + extra health)
*
Expand Down