Fixed shields and shield rendering

This commit is contained in:
Sollace 2019-02-27 16:16:45 +02:00
parent e31951b85d
commit d69d1fcfb7
2 changed files with 35 additions and 15 deletions

View file

@ -19,7 +19,7 @@ public interface IPower<T extends IData> extends IKeyBind {
/** /**
* Subtracts a given food amount from the player. * Subtracts a given food amount from the player.
* Harms the player if there is not enough enough hunger available. * Harms the player if there is not enough hunger available.
*/ */
static boolean takeFromPlayer(EntityPlayer player, double foodSubtract) { static boolean takeFromPlayer(EntityPlayer player, double foodSubtract) {
if (!player.capabilities.isCreativeMode) { if (!player.capabilities.isCreativeMode) {

View file

@ -1,5 +1,8 @@
package com.minelittlepony.unicopia.spell; package com.minelittlepony.unicopia.spell;
import java.util.List;
import java.util.stream.Collectors;
import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.Predicates;
import com.minelittlepony.unicopia.init.UParticles; import com.minelittlepony.unicopia.init.UParticles;
import com.minelittlepony.unicopia.particle.ParticleConnection; import com.minelittlepony.unicopia.particle.ParticleConnection;
@ -35,6 +38,11 @@ public class SpellShield extends AbstractSpell.RangedAreaSpell implements IAttac
return 0x66CDAA; return 0x66CDAA;
} }
@Override
public void renderOnPerson(IPlayer source) {
render(source);
}
@Override @Override
public void render(ICaster<?> source) { public void render(ICaster<?> source) {
float radius = 4 + (source.getCurrentLevel() * 2); float radius = 4 + (source.getCurrentLevel() * 2);
@ -50,10 +58,15 @@ public class SpellShield extends AbstractSpell.RangedAreaSpell implements IAttac
@Override @Override
public boolean updateOnPerson(IPlayer source) { public boolean updateOnPerson(IPlayer source) {
if (update(source)) { int costMultiplier = applyEntities(source);
if (source.getEntity().getEntityWorld().getWorldTime() % 50 == 0) { if (costMultiplier > 0) {
double radius = 4 + (source.getCurrentLevel() * 2); if (source.getOwner().ticksExisted % 20 == 0) {
if (!IPower.takeFromPlayer((EntityPlayer)source.getOwner(), radius/4)) { double cost = 4 + (source.getCurrentLevel() * 2);
cost *= costMultiplier / 5F;
System.out.println("Taking " + cost);
if (!IPower.takeFromPlayer(source.getOwner(), cost)) {
setDead(); setDead();
} }
} }
@ -68,6 +81,11 @@ public class SpellShield extends AbstractSpell.RangedAreaSpell implements IAttac
@Override @Override
public boolean update(ICaster<?> source) { public boolean update(ICaster<?> source) {
applyEntities(source);
return true;
}
protected int applyEntities(ICaster<?> source) {
double radius = getDrawDropOffRange(source); double radius = getDrawDropOffRange(source);
Entity owner = source.getOwner(); Entity owner = source.getOwner();
@ -76,19 +94,21 @@ public class SpellShield extends AbstractSpell.RangedAreaSpell implements IAttac
Vec3d origin = source.getOriginVector(); Vec3d origin = source.getOriginVector();
source.findAllEntitiesInRange(radius) List<Entity> targets = source.findAllEntitiesInRange(radius)
.filter(entity -> !(ownerIsValid && entity.equals(owner))) .filter(entity -> !(ownerIsValid && entity.equals(owner)))
.forEach(i -> { .collect(Collectors.toList());
try {
double dist = i.getPositionVector().distanceTo(origin);
applyRadialEffect(source, i, dist, radius); targets.forEach(i -> {
} catch (Throwable e) { try {
e.printStackTrace(); double dist = i.getPositionVector().distanceTo(origin);
}
});
return true; applyRadialEffect(source, i, dist, radius);
} catch (Throwable e) {
e.printStackTrace();
}
});
return targets.size();
} }
protected void applyRadialEffect(ICaster<?> source, Entity target, double distance, double radius) { protected void applyRadialEffect(ICaster<?> source, Entity target, double distance, double radius) {