2018-09-12 01:29:49 +02:00
|
|
|
package com.minelittlepony.unicopia.spell;
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
import com.minelittlepony.unicopia.Predicates;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
2019-01-28 18:42:18 +01:00
|
|
|
import com.minelittlepony.unicopia.UParticles;
|
|
|
|
import com.minelittlepony.unicopia.particle.Particles;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
|
|
|
import com.minelittlepony.unicopia.power.IPower;
|
|
|
|
import com.minelittlepony.util.ProjectileUtil;
|
|
|
|
import com.minelittlepony.util.shape.Sphere;
|
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.SoundEvents;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2018-09-24 21:37:16 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
|
|
|
|
|
public class SpellShield extends AbstractSpell {
|
|
|
|
|
|
|
|
private int strength = 0;
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
@Override
|
|
|
|
public int getCurrentLevel() {
|
|
|
|
return strength;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setCurrentLevel(int level) {
|
|
|
|
strength = level;
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "shield";
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:39:30 +01:00
|
|
|
@Override
|
|
|
|
public int getTint() {
|
|
|
|
return 0x66CDAA;
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
@Override
|
|
|
|
public int getMaxLevel() {
|
2018-09-26 17:53:12 +02:00
|
|
|
return 17;
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
@Override
|
|
|
|
public void render(ICaster<?> source, int level) {
|
2018-09-26 17:53:12 +02:00
|
|
|
spawnParticles(source, 4 + (level * 2));
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
protected void spawnParticles(ICaster<?> source, int strength) {
|
2019-01-20 00:07:59 +01:00
|
|
|
source.spawnParticles(new Sphere(true, strength), strength * 6, pos -> {
|
2019-01-28 18:42:18 +01:00
|
|
|
Particles.instance().spawnParticle(UParticles.MAGIC_PARTICLE, false, pos, 0, 0, 0);
|
2019-01-20 00:07:59 +01:00
|
|
|
});
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-26 17:53:12 +02:00
|
|
|
public boolean updateOnPerson(ICaster<?> source) {
|
2018-09-24 21:37:16 +02:00
|
|
|
update(source, strength);
|
2018-09-12 22:37:06 +02:00
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
if (source.getEntity().getEntityWorld().getWorldTime() % 50 == 0) {
|
2018-09-12 01:29:49 +02:00
|
|
|
double radius = 4 + (strength * 2);
|
2018-09-24 21:37:16 +02:00
|
|
|
if (!IPower.takeFromPlayer((EntityPlayer)source.getOwner(), radius/4)) {
|
2018-09-12 01:29:49 +02:00
|
|
|
setDead();
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 22:37:06 +02:00
|
|
|
|
2019-01-26 18:28:21 +01:00
|
|
|
return !getDead();
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-24 21:37:16 +02:00
|
|
|
public boolean update(ICaster<?> source, int level) {
|
2018-09-12 01:29:49 +02:00
|
|
|
double radius = 4 + (level * 2);
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
Entity owner = source.getOwner();
|
|
|
|
BlockPos pos = source.getOrigin();
|
|
|
|
|
|
|
|
int x = pos.getX(), y = pos.getY(), z = pos.getZ();
|
|
|
|
|
|
|
|
boolean ownerIsValid = Predicates.MAGI.test(owner);
|
|
|
|
|
2019-01-20 00:07:59 +01:00
|
|
|
source.findAllEntitiesInRange(radius).filter(entity -> !(ownerIsValid && entity.equals(owner))).forEach(i -> {
|
2018-09-24 21:37:16 +02:00
|
|
|
double dist = i.getDistance(x, y, z);
|
|
|
|
|
|
|
|
if (ProjectileUtil.isProjectile(i)) {
|
|
|
|
if (!ProjectileUtil.isProjectileThrownBy(i, owner)) {
|
|
|
|
if (dist < radius/2) {
|
|
|
|
i.playSound(SoundEvents.ENTITY_ZOMBIE_VILLAGER_CURE, 0.1F, 1);
|
|
|
|
i.setDead();
|
|
|
|
} else {
|
|
|
|
ricochet(i, pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (i instanceof EntityLivingBase) {
|
|
|
|
double force = Math.min(0.25F, dist);
|
|
|
|
|
|
|
|
if (i instanceof EntityPlayer) {
|
|
|
|
force = calculateForce((EntityPlayer)i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i.addVelocity(
|
|
|
|
-(x - i.posX) / force,
|
|
|
|
-(y - i.posY) / force + (dist < 1 ? dist : 0),
|
|
|
|
-(z - i.posZ) / force);
|
|
|
|
}
|
2019-01-20 00:07:59 +01:00
|
|
|
});
|
2018-09-24 21:37:16 +02:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected double calculateForce(EntityPlayer player) {
|
|
|
|
Race race = PlayerSpeciesList.instance().getPlayer(player).getPlayerSpecies();
|
|
|
|
|
|
|
|
double force = 4 * 8;
|
|
|
|
|
|
|
|
if (race.canUseEarth()) {
|
|
|
|
if (player.isSneaking()) {
|
|
|
|
force *= 16;
|
|
|
|
}
|
|
|
|
} else if (race.canFly()) {
|
|
|
|
force /= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return force;
|
|
|
|
}
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
private void ricochet(Entity projectile, BlockPos pos) {
|
2018-09-12 01:29:49 +02:00
|
|
|
Vec3d position = new Vec3d(projectile.posX, projectile.posY, projectile.posZ);
|
|
|
|
Vec3d motion = new Vec3d(projectile.motionX, projectile.motionY, projectile.motionZ);
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
Vec3d normal = position.subtract(pos.getX(), pos.getY(), pos.getZ()).normalize();
|
2018-09-12 01:29:49 +02:00
|
|
|
Vec3d approach = motion.subtract(normal);
|
|
|
|
|
|
|
|
if (approach.length() >= motion.length()) {
|
|
|
|
ProjectileUtil.setThrowableHeading(projectile, normal.x, normal.y, normal.z, (float)motion.length(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
@Override
|
2018-09-12 01:29:49 +02:00
|
|
|
public void writeToNBT(NBTTagCompound compound) {
|
|
|
|
compound.setInteger("spell_strength", strength);
|
|
|
|
}
|
|
|
|
|
2018-09-24 21:37:16 +02:00
|
|
|
@Override
|
2018-09-12 01:29:49 +02:00
|
|
|
public void readFromNBT(NBTTagCompound compound) {
|
|
|
|
strength = compound.getInteger("spell_strength");
|
|
|
|
}
|
|
|
|
}
|