Minor cleanup

This commit is contained in:
Sollace 2022-09-16 17:52:28 +02:00
parent b1f64b9f9f
commit 8d2639b69b
7 changed files with 34 additions and 11 deletions

View file

@ -12,6 +12,7 @@ import com.minelittlepony.unicopia.entity.UEntities;
import com.minelittlepony.unicopia.particle.OrientedBillboardParticleEffect;
import com.minelittlepony.unicopia.particle.ParticleHandle;
import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment;
import net.minecraft.nbt.*;
import net.minecraft.util.Identifier;
@ -98,7 +99,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell {
particlEffect.update(getUuid(), source, spawner -> {
spawner.addParticle(new OrientedBillboardParticleEffect(UParticles.MAGIC_RUNES, 90, 0), source.getOriginVector(), Vec3d.ZERO);
}).ifPresent(p -> {
p.setAttribute(1, spell.getType().getColor());
p.setAttribute(Attachment.ATTR_COLOR, spell.getType().getColor());
});
return super.tick(source, Situation.GROUND);
@ -137,7 +138,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell {
@Override
public void fromNBT(NbtCompound compound) {
super.fromNBT(compound);
if (compound.contains("dimension")) {
if (compound.contains("dimension", NbtElement.STRING_TYPE)) {
Identifier id = Identifier.tryParse(compound.getString("dimension"));
if (id != null) {
dimension = RegistryKey.of(Registry.WORLD_KEY, id);

View file

@ -1,8 +1,24 @@
package com.minelittlepony.unicopia.ability.magic.spell;
/**
* The situation of the spell being ticked.
*/
public enum Situation {
/**
* Ticks coming from living entities like the player and animals.
*/
BODY,
/**
* Ticks coming from flying projectiles.
*/
PROJECTILE,
/**
* Ticks coming from a PlaceableSpell that's being updated as a ground entity.
*/
GROUND,
/**
* Ticks coming directly from the ground SpellCastEntity.
* Handled only by PlaceableSpell. No other spell should receive this.
*/
GROUND_ENTITY
}

View file

@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.ProjectileSpell;
import com.minelittlepony.unicopia.ability.magic.spell.Situation;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.SphereParticleEffect;
import com.minelittlepony.unicopia.particle.UParticles;
@ -116,13 +117,13 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileSpell
particlEffect.update(getUuid(), source, spawner -> {
spawner.addParticle(new SphereParticleEffect(UParticles.SPHERE, getType().getColor(), 0.99F, radius, SPHERE_OFFSET), source.getOriginVector(), Vec3d.ZERO);
}).ifPresent(p -> {
p.setAttribute(0, radius);
p.setAttribute(Attachment.ATTR_RADIUS, radius);
});
particlEffect.update(getUuid(), "_ring", source, spawner -> {
spawner.addParticle(new SphereParticleEffect(UParticles.DISK, 0xFFFFFFFF, 0.4F, radius + 1, SPHERE_OFFSET), getOrigin(source), Vec3d.ZERO);
}).ifPresent(p -> {
p.setAttribute(0, radius * 2F);
p.setAttribute(1, 0xAAAAAA);
p.setAttribute(Attachment.ATTR_RADIUS, radius * 2F);
p.setAttribute(Attachment.ATTR_COLOR, 0xAAAAAA);
});
double angle = age % 260;

View file

@ -12,6 +12,7 @@ import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.particle.ParticleHandle;
import com.minelittlepony.unicopia.particle.SphereParticleEffect;
import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.particle.ParticleHandle.Attachment;
import com.minelittlepony.unicopia.projectile.ProjectileUtil;
import com.minelittlepony.unicopia.util.shape.Sphere;
@ -75,8 +76,8 @@ public class ShieldSpell extends AbstractSpell {
particlEffect.update(getUuid(), source, spawner -> {
spawner.addParticle(new SphereParticleEffect(UParticles.SPHERE, getType().getColor(), 0.3F, radius), origin, Vec3d.ZERO);
}).ifPresent(p -> {
p.setAttribute(0, radius);
p.setAttribute(1, getType().getColor());
p.setAttribute(Attachment.ATTR_RADIUS, radius);
p.setAttribute(Attachment.ATTR_COLOR, getType().getColor());
});
}

View file

@ -71,7 +71,7 @@ public class RunesParticle extends OrientedBillboardParticle implements Attachme
@Override
public void setAttribute(int key, Object value) {
if (key == 1) {
if (key == ATTR_COLOR) {
int tint = (int)value;
red = Color.r(tint);
green = Color.g(tint);

View file

@ -75,18 +75,18 @@ public class SphereParticle extends Particle implements Attachment {
@Override
public void setAttribute(int key, Object value) {
if (key == 0) {
if (key == ATTR_RADIUS) {
toRadius = (float)value;
steps = 20;
lerpIncrement = (toRadius - radius) / steps;
}
if (key == 1) {
if (key == ATTR_COLOR) {
int tint = (int)value;
red = Color.r(tint);
green = Color.g(tint);
blue = Color.b(tint);
}
if (key == 2) {
if (key == ATTR_OPACITY) {
alpha = (float)value;
}
}

View file

@ -85,6 +85,10 @@ public class ParticleHandle {
}
public interface Attachment {
int ATTR_RADIUS = 0;
int ATTR_COLOR = 1;
int ATTR_OPACITY = 2;
boolean isStillAlive();
void attach(Link link);