Added the ability for the Sentient Specter to shoot arrows with status effects, depending on its typing.

This commit is contained in:
WayofTime 2016-08-16 18:22:05 -04:00
parent 007c6c5ace
commit 939e1c3946
2 changed files with 101 additions and 31 deletions

View file

@ -1,7 +1,7 @@
package WayofTime.bloodmagic.entity.mob; package WayofTime.bloodmagic.entity.mob;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.List;
import java.util.UUID; import java.util.UUID;
import lombok.Getter; import lombok.Getter;
@ -38,6 +38,7 @@ import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionEffect;
import net.minecraft.server.management.PreYggdrasilConverter; import net.minecraft.server.management.PreYggdrasilConverter;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundEvent; import net.minecraft.util.SoundEvent;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -143,7 +144,7 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
public boolean canStealEffectFromOwner(EntityLivingBase owner) public boolean canStealEffectFromOwner(EntityLivingBase owner)
{ {
if (this.type == EnumDemonWillType.CORROSIVE) if (this.type != EnumDemonWillType.CORROSIVE)
{ {
return false; return false;
} }
@ -161,64 +162,114 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
public boolean stealEffectsFromOwner(EntityLivingBase owner) public boolean stealEffectsFromOwner(EntityLivingBase owner)
{ {
if (this.type == EnumDemonWillType.CORROSIVE) if (this.type != EnumDemonWillType.CORROSIVE)
{ {
return false; return false;
} }
boolean hasStolenEffect = false; boolean hasStolenEffect = false;
Iterator<PotionEffect> itr = new ArrayList<PotionEffect>(owner.getActivePotionEffects()).iterator();
while (itr.hasNext()) List<PotionEffect> removedEffects = new ArrayList<PotionEffect>();
for (PotionEffect eff : owner.getActivePotionEffects())
{ {
PotionEffect eff = itr.next();
if (canStealEffectFromOwner(owner, eff)) if (canStealEffectFromOwner(owner, eff))
{ {
owner.removePotionEffect(eff.getPotion()); removedEffects.add(eff);
this.addPotionEffect(eff);
hasStolenEffect = true; hasStolenEffect = true;
} }
} }
for (PotionEffect eff : removedEffects)
{
owner.removePotionEffect(eff.getPotion());
this.addPotionEffect(eff);
}
return hasStolenEffect; return hasStolenEffect;
} }
public boolean applyNegativeEffectsToAttacked(EntityLivingBase attackedEntity, float percentTransmitted) public boolean applyNegativeEffectsToAttacked(EntityLivingBase attackedEntity, float percentTransmitted)
{ {
boolean hasProvidedEffect = false; boolean hasProvidedEffect = false;
Iterator<PotionEffect> itr = new ArrayList<PotionEffect>(this.getActivePotionEffects()).iterator(); List<PotionEffect> removedEffects = new ArrayList<PotionEffect>();
while (itr.hasNext()) for (PotionEffect eff : this.getActivePotionEffects())
{ {
PotionEffect eff = itr.next(); if (eff.getPotion().isBadEffect() && attackedEntity.isPotionApplicable(eff))
if (attackedEntity.isPotionApplicable(eff))
{ {
if (!attackedEntity.isPotionActive(eff.getPotion())) if (!attackedEntity.isPotionActive(eff.getPotion()))
{ {
PotionEffect newEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * percentTransmitted), eff.getAmplifier(), eff.getIsAmbient(), eff.doesShowParticles()); removedEffects.add(eff);
attackedEntity.addPotionEffect(newEffect);
PotionEffect newSentientEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * (1 - percentTransmitted)), eff.getAmplifier(), eff.getIsAmbient(), eff.doesShowParticles());
this.removePotionEffect(eff.getPotion());
this.addPotionEffect(newSentientEffect);
hasProvidedEffect = true; hasProvidedEffect = true;
} else } else
{ {
PotionEffect activeEffect = attackedEntity.getActivePotionEffect(eff.getPotion()); PotionEffect activeEffect = attackedEntity.getActivePotionEffect(eff.getPotion());
if (activeEffect.getAmplifier() < eff.getAmplifier() || activeEffect.getDuration() < eff.getDuration() * percentTransmitted) if (activeEffect.getAmplifier() < eff.getAmplifier() || activeEffect.getDuration() < eff.getDuration() * percentTransmitted)
{ {
PotionEffect newEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * percentTransmitted), eff.getAmplifier(), activeEffect.getIsAmbient(), activeEffect.doesShowParticles()); removedEffects.add(eff);
attackedEntity.addPotionEffect(newEffect);
PotionEffect newSentientEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * (1 - percentTransmitted)), eff.getAmplifier(), eff.getIsAmbient(), eff.doesShowParticles());
this.removePotionEffect(eff.getPotion());
this.addPotionEffect(newSentientEffect);
hasProvidedEffect = true; hasProvidedEffect = true;
} }
} }
} }
} }
for (PotionEffect eff : removedEffects)
{
if (!attackedEntity.isPotionActive(eff.getPotion()))
{
PotionEffect newEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * percentTransmitted), eff.getAmplifier(), eff.getIsAmbient(), eff.doesShowParticles());
attackedEntity.addPotionEffect(newEffect);
PotionEffect newSentientEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * (1 - percentTransmitted)), eff.getAmplifier(), eff.getIsAmbient(), eff.doesShowParticles());
this.removePotionEffect(eff.getPotion());
this.addPotionEffect(newSentientEffect);
} else
{
PotionEffect activeEffect = attackedEntity.getActivePotionEffect(eff.getPotion());
PotionEffect newEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * percentTransmitted), eff.getAmplifier(), activeEffect.getIsAmbient(), activeEffect.doesShowParticles());
attackedEntity.addPotionEffect(newEffect);
PotionEffect newSentientEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * (1 - percentTransmitted)), eff.getAmplifier(), eff.getIsAmbient(), eff.doesShowParticles());
this.removePotionEffect(eff.getPotion());
this.addPotionEffect(newSentientEffect);
}
}
return hasProvidedEffect; return hasProvidedEffect;
} }
public List<PotionEffect> getPotionEffectsForArrowRemovingDuration(float percentTransmitted)
{
List<PotionEffect> arrowEffects = new ArrayList<PotionEffect>();
if (type != EnumDemonWillType.CORROSIVE)
{
return arrowEffects;
}
List<PotionEffect> removedEffects = new ArrayList<PotionEffect>();
for (PotionEffect eff : this.getActivePotionEffects())
{
if (eff.getPotion().isBadEffect())
{
removedEffects.add(eff);
}
}
for (PotionEffect eff : removedEffects)
{
PotionEffect newEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * percentTransmitted), eff.getAmplifier(), eff.getIsAmbient(), eff.doesShowParticles());
arrowEffects.add(newEffect);
PotionEffect newSentientEffect = new PotionEffect(eff.getPotion(), (int) (eff.getDuration() * (1 - percentTransmitted)), eff.getAmplifier(), eff.getIsAmbient(), eff.doesShowParticles());
this.removePotionEffect(eff.getPotion());
this.addPotionEffect(newSentientEffect);
}
return arrowEffects;
}
@Override @Override
public boolean attackEntityAsMob(Entity attackedEntity) public boolean attackEntityAsMob(Entity attackedEntity)
{ {
@ -255,14 +306,27 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
public boolean absorbExplosion(Explosion explosion) public boolean absorbExplosion(Explosion explosion)
{ {
return true; if (this.type == EnumDemonWillType.DESTRUCTIVE)
{
this.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 600, 1));
explosion.doExplosionB(true);
return true;
}
return false;
}
public boolean isEntityInvulnerable(DamageSource source)
{
return super.isEntityInvulnerable(source) && (this.type == EnumDemonWillType.DESTRUCTIVE && source.isExplosion());
} }
@Override @Override
protected boolean canDespawn() protected boolean canDespawn()
{ {
//TODO: Change so that it despawns if not tamed after testing. return !this.isTamed() && super.canDespawn();
return false;
} }
@Override @Override
@ -350,6 +414,12 @@ public class EntitySentientSpecter extends EntityMob implements IEntityOwnable
EntityTippedArrow arrowEntity = ((ItemSentientBow) heldStack.getItem()).getArrowEntity(worldObj, heldStack, target, this, velocity); EntityTippedArrow arrowEntity = ((ItemSentientBow) heldStack.getItem()).getArrowEntity(worldObj, heldStack, target, this, velocity);
if (arrowEntity != null) if (arrowEntity != null)
{ {
List<PotionEffect> effects = getPotionEffectsForArrowRemovingDuration(0.2f);
for (PotionEffect eff : effects)
{
arrowEntity.addEffect(eff);
}
this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F)); this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
this.worldObj.spawnEntityInWorld(arrowEntity); this.worldObj.spawnEntityInWorld(arrowEntity);
} }

View file

@ -259,11 +259,11 @@ public class ItemSentientSword extends ItemSword implements IDemonWillWeapon, IM
world.spawnEntityInWorld(specterEntity); world.spawnEntityInWorld(specterEntity);
System.out.println("Spawning Specter..."); System.out.println("Spawning Specter...");
// ItemStack bowStack = new ItemStack(ModItems.sentientBow); ItemStack bowStack = new ItemStack(ModItems.sentientBow);
// ((ItemSentientBow) ModItems.sentientBow).recalculatePowers(bowStack, EnumDemonWillType.DEFAULT, 1025); ((ItemSentientBow) ModItems.sentientBow).recalculatePowers(bowStack, EnumDemonWillType.CORROSIVE, 1025);
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, bowStack); specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, bowStack);
specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, stack.copy()); // specterEntity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, stack.copy());
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(ModItems.sentientArmourHelmet)); // specterEntity.setItemStackToSlot(EntityEquipmentSlot.HEAD, new ItemStack(ModItems.sentientArmourHelmet));
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(ModItems.sentientArmourChest)); // specterEntity.setItemStackToSlot(EntityEquipmentSlot.CHEST, new ItemStack(ModItems.sentientArmourChest));
// specterEntity.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(ModItems.sentientArmourLegs)); // specterEntity.setItemStackToSlot(EntityEquipmentSlot.LEGS, new ItemStack(ModItems.sentientArmourLegs));