From d34d1ddd60f0f5f057e533eb88cb17afc549108c Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 15 Mar 2019 14:16:56 +0200 Subject: [PATCH] Added functionality for cuccoons --- .../unicopia/entity/EntityCuccoon.java | 65 +++++++++++++++++++ .../unicopia/power/PowerFeed.java | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityCuccoon.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityCuccoon.java index 9354c324..b1a6aed7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityCuccoon.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityCuccoon.java @@ -7,13 +7,18 @@ import javax.annotation.Nullable; import com.google.common.collect.Lists; import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.init.UParticles; import com.minelittlepony.unicopia.init.USounds; +import com.minelittlepony.unicopia.power.IPower; +import com.minelittlepony.util.MagicalDamageSource; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; +import net.minecraft.init.MobEffects; import net.minecraft.init.SoundEvents; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemStack; @@ -21,12 +26,16 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; +import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; +import net.minecraft.util.EnumActionResult; +import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHandSide; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.event.ForgeEventFactory; @@ -124,6 +133,18 @@ public class EntityCuccoon extends EntityLivingBase implements IMagicals, IInAni } captiveLastSneakState = sneaking; + + if (passenger instanceof EntityLivingBase) { + EntityLivingBase living = (EntityLivingBase)passenger; + + if (!living.isPotionActive(MobEffects.REGENERATION) && living.getHealth() < living.getMaxHealth()) { + living.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 20, 2)); + } + + if (!living.isPotionActive(MobEffects.SLOWNESS) && living.getHealth() < living.getMaxHealth()) { + living.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 2000, 4)); + } + } } if (world.isRemote) { @@ -135,6 +156,50 @@ public class EntityCuccoon extends EntityLivingBase implements IMagicals, IInAni } } + @Override + public EnumActionResult applyPlayerInteraction(EntityPlayer player, Vec3d vec, EnumHand hand) { + + if (hand == EnumHand.MAIN_HAND && Predicates.BUGGY.test(player)) { + + if (isBeingRidden()) { + Entity passenger = getPassengers().get(0); + + if (player.canEat(false) || player.getHealth() < player.getMaxHealth()) { + DamageSource d = MagicalDamageSource.causePlayerDamage("feed", player); + + + IPower.spawnParticles(UParticles.CHANGELING_MAGIC, this, 7); + + if (passenger instanceof EntityLivingBase) { + if (player.isPotionActive(MobEffects.NAUSEA)) { + ((EntityLivingBase)passenger).addPotionEffect(player.removeActivePotionEffect(MobEffects.NAUSEA)); + } else if (world.rand.nextInt(2300) == 0) { + ((EntityLivingBase)passenger).addPotionEffect(new PotionEffect(MobEffects.WITHER, 20, 1)); + } + } + + if (passenger instanceof EntityPlayer) { + if (!player.isPotionActive(MobEffects.HEALTH_BOOST)) { + player.addPotionEffect(new PotionEffect(MobEffects.HEALTH_BOOST, 13000, 1)); + } + } + + passenger.attackEntityFrom(d, 5); + + if (player.canEat(false)) { + player.getFoodStats().addStats(5, 0); + } else { + player.heal(5); + } + + return EnumActionResult.SUCCESS; + } + } + } + + return super.applyPlayerInteraction(player, vec, hand); + } + public float getBreatheAmount(float stutter) { return MathHelper.sin((ticksExisted + stutter) / 40) / 2 + hurtTime / 10F; diff --git a/src/main/java/com/minelittlepony/unicopia/power/PowerFeed.java b/src/main/java/com/minelittlepony/unicopia/power/PowerFeed.java index 6a70c866..b2f2f3d6 100644 --- a/src/main/java/com/minelittlepony/unicopia/power/PowerFeed.java +++ b/src/main/java/com/minelittlepony/unicopia/power/PowerFeed.java @@ -124,7 +124,7 @@ public class PowerFeed implements IPower { } } - protected float drainFrom(EntityPlayer changeling, EntityLivingBase living) { + public float drainFrom(EntityPlayer changeling, EntityLivingBase living) { DamageSource d = MagicalDamageSource.causePlayerDamage("feed", changeling); float damage = living.getHealth()/2;