The siphoning spell can now get angry if you misuse it

This commit is contained in:
Sollace 2021-03-05 21:07:49 +02:00
parent b27ff8c5f0
commit d27de0f690
2 changed files with 26 additions and 3 deletions

View file

@ -86,7 +86,6 @@ public abstract class AbstractPlacedSpell extends AbstractSpell implements Attac
@Override @Override
public void fromNBT(CompoundTag compound) { public void fromNBT(CompoundTag compound) {
super.fromNBT(compound); super.fromNBT(compound);
System.out.println("Loaded!");
if (compound.contains("dimension")) { if (compound.contains("dimension")) {
dimension = new Identifier(compound.getString("dimension")); dimension = new Identifier(compound.getString("dimension"));
} }

View file

@ -17,6 +17,7 @@ import com.minelittlepony.unicopia.util.shape.Sphere;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -26,6 +27,8 @@ import net.minecraft.util.math.Vec3d;
*/ */
public class SiphoningSpell extends AbstractPlacedSpell { public class SiphoningSpell extends AbstractPlacedSpell {
private int ticksUpset;
protected SiphoningSpell(SpellType<?> type) { protected SiphoningSpell(SpellType<?> type) {
super(type); super(type);
} }
@ -34,6 +37,10 @@ public class SiphoningSpell extends AbstractPlacedSpell {
public boolean onGroundTick(Caster<?> source) { public boolean onGroundTick(Caster<?> source) {
super.onGroundTick(source); super.onGroundTick(source);
if (ticksUpset > 0) {
ticksUpset--;
}
if (source.isClient()) { if (source.isClient()) {
int radius = 4 + source.getLevel().get(); int radius = 4 + source.getLevel().get();
int direction = isFriendlyTogether(source) ? 1 : -1; int direction = isFriendlyTogether(source) ? 1 : -1;
@ -44,7 +51,7 @@ public class SiphoningSpell extends AbstractPlacedSpell {
double dist = pos.distanceTo(source.getOriginVector()); double dist = pos.distanceTo(source.getOriginVector());
Vec3d velocity = pos.subtract(source.getOriginVector()).normalize().multiply(direction * dist); Vec3d velocity = pos.subtract(source.getOriginVector()).normalize().multiply(direction * dist);
source.addParticle(direction == 1 ? ParticleTypes.HEART : ParticleTypes.ANGRY_VILLAGER, pos, velocity); source.addParticle(direction == 1 && ticksUpset == 0 ? ParticleTypes.HEART : ParticleTypes.ANGRY_VILLAGER, pos, velocity);
} }
}); });
} else { } else {
@ -77,12 +84,16 @@ public class SiphoningSpell extends AbstractPlacedSpell {
source.subtractEnergyCost(0.2F); source.subtractEnergyCost(0.2F);
if (maxHealthGain <= 0) { if (ticksUpset > 0 || maxHealthGain <= 0) {
if (source.getWorld().random.nextInt(3000) == 0) { if (source.getWorld().random.nextInt(3000) == 0) {
onDestroyed(source); onDestroyed(source);
} else { } else {
e.damage(damage, e.getHealth() / 4); e.damage(damage, e.getHealth() / 4);
} }
if (maxHealthGain <= 0) {
ticksUpset = 100;
}
setDirty(true);
} else { } else {
e.heal((float)Math.min(0.5F * (1 + source.getLevel().get()), maxHealthGain * 0.6)); e.heal((float)Math.min(0.5F * (1 + source.getLevel().get()), maxHealthGain * 0.6));
ParticleUtils.spawnParticle(new FollowingParticleEffect(UParticles.HEALTH_DRAIN, e, 0.2F), e.world, e.getPos(), Vec3d.ZERO); ParticleUtils.spawnParticle(new FollowingParticleEffect(UParticles.HEALTH_DRAIN, e, 0.2F), e.world, e.getPos(), Vec3d.ZERO);
@ -135,4 +146,17 @@ public class SiphoningSpell extends AbstractPlacedSpell {
owner.heal(healthGain); owner.heal(healthGain);
} }
@Override
public void toNBT(CompoundTag compound) {
super.toNBT(compound);
compound.putInt("upset", ticksUpset);
}
@Override
public void fromNBT(CompoundTag compound) {
super.fromNBT(compound);
ticksUpset = compound.getInt("upset");
}
} }