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
|
||||
public boolean tick(Caster<?> source, Situation situation) {
|
||||
|
||||
if (!source.isClient()) {
|
||||
World world = source.getReferenceWorld();
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<Livin
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
|
|||
@Override
|
||||
public void tick() {
|
||||
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) {
|
||||
Unicopia.LOGGER.error("Error whilst ticking spell on entity {}", getEntity(), e);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ public class EffectSync implements SpellContainer {
|
|||
|
||||
@Override
|
||||
public boolean removeWhere(Predicate<Spell> test, boolean update) {
|
||||
return reduce((initial, effect) -> {
|
||||
return reduce(update, (initial, effect) -> {
|
||||
if (!test.test(effect)) {
|
||||
return initial;
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class EffectSync implements SpellContainer {
|
|||
|
||||
@Override
|
||||
public boolean forEach(Function<Spell, Operation> test, boolean update) {
|
||||
return reduce((initial, effect) -> {
|
||||
return reduce(update, (initial, effect) -> {
|
||||
Operation op = test.apply(effect);
|
||||
if (op == Operation.REMOVE) {
|
||||
spells.removeReference(effect);
|
||||
|
@ -122,11 +122,9 @@ public class EffectSync implements SpellContainer {
|
|||
return (Stream<T>)spells.getReferences().flatMap(s -> s.findMatches(type));
|
||||
}
|
||||
|
||||
public boolean reduce(Alteration alteration) {
|
||||
spells.fromNbt(owner.getEntity().getDataTracker().get(param));
|
||||
|
||||
private boolean reduce(boolean update, Alteration alteration) {
|
||||
boolean initial = false;
|
||||
for (Spell i : spells.getReferences().toList()) {
|
||||
for (Spell i : read(null, update, false).toList()) {
|
||||
initial = alteration.apply(initial, i);
|
||||
}
|
||||
|
||||
|
|
|
@ -301,7 +301,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster<Li
|
|||
consumer.accept((ProjectileDelegate)spell);
|
||||
}
|
||||
return Operation.SKIP;
|
||||
}, true);
|
||||
}, world.isClient);
|
||||
if (getItem().getItem() instanceof ProjectileDelegate) {
|
||||
consumer.accept(((ProjectileDelegate)getItem().getItem()));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue