mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-20 03:44:23 +01:00
Limit status effect stacking
This commit is contained in:
parent
7c62e56d1d
commit
d22140eccd
2 changed files with 18 additions and 11 deletions
|
@ -121,10 +121,10 @@ public interface Toxics {
|
||||||
|
|
||||||
Toxic BAT_PONYS_DELIGHT = register("bat_ponys_delight", new Toxic.Builder(Ailment.INNERT)
|
Toxic BAT_PONYS_DELIGHT = register("bat_ponys_delight", new Toxic.Builder(Ailment.INNERT)
|
||||||
.with(Race.BAT, Ailment.of(Toxicity.SAFE,
|
.with(Race.BAT, Ailment.of(Toxicity.SAFE,
|
||||||
Toxin.of(StatusEffects.HEALTH_BOOST, 30, 2)
|
Toxin.of(StatusEffects.HEALTH_BOOST, 30, 60, 2, 6)
|
||||||
.and(Toxin.of(StatusEffects.JUMP_BOOST, 30, 1))
|
.and(Toxin.of(StatusEffects.JUMP_BOOST, 30, 60, 1, 6))
|
||||||
.and(Toxin.of(StatusEffects.SPEED, 30, 1))
|
.and(Toxin.of(StatusEffects.SPEED, 30, 30, 1, 6))
|
||||||
.and(Toxin.of(StatusEffects.REGENERATION, 3, 3))
|
.and(Toxin.of(StatusEffects.REGENERATION, 3, 30, 3, 6))
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,12 @@ public interface Toxin extends Affliction {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Toxin of(StatusEffect effect, int seconds, int amplifier) {
|
static Toxin of(StatusEffect effect, int seconds, int amplifier) {
|
||||||
int ticks = seconds * 20;
|
return of(effect, seconds, -1, amplifier, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Toxin of(StatusEffect effect, int seconds, int maxSeconds, int amplifier, int maxAmplifier) {
|
||||||
|
final int ticks = seconds * 20;
|
||||||
|
final int maxTicks = maxSeconds * 20;
|
||||||
|
|
||||||
MutableText text = effect.getName().copy();
|
MutableText text = effect.getName().copy();
|
||||||
|
|
||||||
|
@ -112,13 +117,11 @@ public interface Toxin extends Affliction {
|
||||||
text = Text.translatable("potion.withDuration", text, StringHelper.formatTicks(ticks));
|
text = Text.translatable("potion.withDuration", text, StringHelper.formatTicks(ticks));
|
||||||
|
|
||||||
return of(text, (player, stack) -> {
|
return of(text, (player, stack) -> {
|
||||||
StatusEffectInstance current = player.getStatusEffect(effect);
|
|
||||||
float health = player.getHealth();
|
float health = player.getHealth();
|
||||||
if (current != null) {
|
StatusEffectInstance current = player.getStatusEffect(effect);
|
||||||
player.addStatusEffect(new StatusEffectInstance(effect, ticks + current.getDuration(), amplifier + current.getAmplifier(), false, false, false));
|
int t = applyLimit(ticks + (current == null ? 0 : current.getDuration()), maxTicks);
|
||||||
} else {
|
int a = applyLimit(amplifier + (current == null ? 0 : current.getAmplifier()), maxAmplifier);
|
||||||
player.addStatusEffect(new StatusEffectInstance(effect, ticks, amplifier, false, false, false));
|
player.addStatusEffect(new StatusEffectInstance(effect, t, a, false, false, false));
|
||||||
}
|
|
||||||
// keep original health
|
// keep original health
|
||||||
if (effect.getAttributeModifiers().containsKey(EntityAttributes.GENERIC_MAX_HEALTH)) {
|
if (effect.getAttributeModifiers().containsKey(EntityAttributes.GENERIC_MAX_HEALTH)) {
|
||||||
player.setHealth(MathHelper.clamp(health, 0, player.getMaxHealth()));
|
player.setHealth(MathHelper.clamp(health, 0, player.getMaxHealth()));
|
||||||
|
@ -126,6 +129,10 @@ public interface Toxin extends Affliction {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int applyLimit(int value, int max) {
|
||||||
|
return max > 0 ? Math.min(value, max) : value;
|
||||||
|
}
|
||||||
|
|
||||||
interface Predicate {
|
interface Predicate {
|
||||||
static Predicate of(Text name, Affliction.Predicate predicate) {
|
static Predicate of(Text name, Affliction.Predicate predicate) {
|
||||||
return new Predicate() {
|
return new Predicate() {
|
||||||
|
|
Loading…
Reference in a new issue