mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Improve performance by removing unneccessary nbt reads of spells when ticking
This commit is contained in:
parent
7cb560802f
commit
b5f41d2244
5 changed files with 8 additions and 9 deletions
|
@ -48,6 +48,7 @@ public class HydrophobicSpell extends AbstractSpell {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean tick(Caster<?> source, Situation situation) {
|
public boolean tick(Caster<?> source, Situation situation) {
|
||||||
|
|
||||||
if (!source.isClient()) {
|
if (!source.isClient()) {
|
||||||
World world = source.getReferenceWorld();
|
World world = source.getReferenceWorld();
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<Livin
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!getSpellSlot().forEach(spell -> Operation.ofBoolean(spell.tick(this, Situation.GROUND_ENTITY)), true)) {
|
if (!getSpellSlot().forEach(spell -> Operation.ofBoolean(spell.tick(this, Situation.GROUND_ENTITY)), world.isClient)) {
|
||||||
discard();
|
discard();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
try {
|
try {
|
||||||
getSpellSlot().forEach(spell -> Operation.ofBoolean(spell.tick(this, Situation.BODY)), true);
|
getSpellSlot().forEach(spell -> Operation.ofBoolean(spell.tick(this, Situation.BODY)), entity.world.isClient);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Unicopia.LOGGER.error("Error whilst ticking spell on entity {}", getEntity(), e);
|
Unicopia.LOGGER.error("Error whilst ticking spell on entity {}", getEntity(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class EffectSync implements SpellContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeWhere(Predicate<Spell> test, boolean update) {
|
public boolean removeWhere(Predicate<Spell> test, boolean update) {
|
||||||
return reduce((initial, effect) -> {
|
return reduce(update, (initial, effect) -> {
|
||||||
if (!test.test(effect)) {
|
if (!test.test(effect)) {
|
||||||
return initial;
|
return initial;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class EffectSync implements SpellContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean forEach(Function<Spell, Operation> test, boolean update) {
|
public boolean forEach(Function<Spell, Operation> test, boolean update) {
|
||||||
return reduce((initial, effect) -> {
|
return reduce(update, (initial, effect) -> {
|
||||||
Operation op = test.apply(effect);
|
Operation op = test.apply(effect);
|
||||||
if (op == Operation.REMOVE) {
|
if (op == Operation.REMOVE) {
|
||||||
spells.removeReference(effect);
|
spells.removeReference(effect);
|
||||||
|
@ -122,11 +122,9 @@ public class EffectSync implements SpellContainer {
|
||||||
return (Stream<T>)spells.getReferences().flatMap(s -> s.findMatches(type));
|
return (Stream<T>)spells.getReferences().flatMap(s -> s.findMatches(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean reduce(Alteration alteration) {
|
private boolean reduce(boolean update, Alteration alteration) {
|
||||||
spells.fromNbt(owner.getEntity().getDataTracker().get(param));
|
|
||||||
|
|
||||||
boolean initial = false;
|
boolean initial = false;
|
||||||
for (Spell i : spells.getReferences().toList()) {
|
for (Spell i : read(null, update, false).toList()) {
|
||||||
initial = alteration.apply(initial, i);
|
initial = alteration.apply(initial, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster<Li
|
||||||
consumer.accept((ProjectileDelegate)spell);
|
consumer.accept((ProjectileDelegate)spell);
|
||||||
}
|
}
|
||||||
return Operation.SKIP;
|
return Operation.SKIP;
|
||||||
}, true);
|
}, world.isClient);
|
||||||
if (getItem().getItem() instanceof ProjectileDelegate) {
|
if (getItem().getItem() instanceof ProjectileDelegate) {
|
||||||
consumer.accept(((ProjectileDelegate)getItem().getItem()));
|
consumer.accept(((ProjectileDelegate)getItem().getItem()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue