From 214bd23b922ae499103f3d9fc87b305769f1ce2f Mon Sep 17 00:00:00 2001 From: FatherToast Date: Thu, 30 Jun 2022 12:40:43 -0500 Subject: [PATCH] Spitfire mobs --- .../common/bestiary/MobFamily.java | 4 +-- .../skeleton/SpitfireSkeletonEntity.java | 29 +++++++++++++++-- .../SpitfireWitherSkeletonEntity.java | 31 +++++++++++++++++-- .../entity/zombie/FireZombieEntity.java | 4 +++ 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/main/java/fathertoast/specialmobs/common/bestiary/MobFamily.java b/src/main/java/fathertoast/specialmobs/common/bestiary/MobFamily.java index 1a6e869..14e09b4 100644 --- a/src/main/java/fathertoast/specialmobs/common/bestiary/MobFamily.java +++ b/src/main/java/fathertoast/specialmobs/common/bestiary/MobFamily.java @@ -55,11 +55,11 @@ public class MobFamily { public static final MobFamily SKELETON = new MobFamily<>( "Skeleton", "skeletons", 0xC1C1C1, new EntityType[] { EntityType.SKELETON, EntityType.STRAY }, - "Brute", "Fire", "Gatling", "Giant", "Knight", "Ninja", "Poison", "Sniper", /*"Spitfire",*/ "Stray" + "Brute", "Fire", "Gatling", "Giant", "Knight", "Ninja", "Poison", "Sniper", "Spitfire", "Stray" ); public static final MobFamily WITHER_SKELETON = new MobFamily<>( "WitherSkeleton", "wither skeletons", 0x141414, new EntityType[] { EntityType.WITHER_SKELETON }, - "Brute", "Gatling", "Giant", "Knight", "Ninja", "Sniper"//, "Spitfire" + "Brute", "Gatling", "Giant", "Knight", "Ninja", "Sniper", "Spitfire" ); public static final MobFamily SLIME = new MobFamily<>( diff --git a/src/main/java/fathertoast/specialmobs/common/entity/skeleton/SpitfireSkeletonEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/skeleton/SpitfireSkeletonEntity.java index 7bd6a74..76b689f 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/skeleton/SpitfireSkeletonEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/skeleton/SpitfireSkeletonEntity.java @@ -12,8 +12,10 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.attributes.AttributeModifierMap; import net.minecraft.entity.ai.attributes.Attributes; +import net.minecraft.entity.projectile.SmallFireballEntity; import net.minecraft.item.Items; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import javax.annotation.ParametersAreNonnullByDefault; @@ -73,9 +75,12 @@ public class SpitfireSkeletonEntity extends _SpecialSkeletonEntity { @Override protected void registerVariantGoals() { getSpecialData().rangedAttackDamage += 2.0F; - getSpecialData().rangedAttackSpread *= 0.5F; } + /** Override to change this entity's chance to spawn with a melee weapon. */ + @Override + protected double getVariantMeleeChance() { return 0.0; } + /** Override to apply effects when this entity hits a target with a melee attack. */ @Override protected void onVariantAttack( Entity target ) { @@ -85,9 +90,29 @@ public class SpitfireSkeletonEntity extends _SpecialSkeletonEntity { /** Called to attack the target with a ranged attack. */ @Override public void performRangedAttack( LivingEntity target, float damageMulti ) { - //TODO + if( !isSilent() ) level.levelEvent( null, 1018, blockPosition(), 0 ); + + final float accelVariance = MathHelper.sqrt( distanceTo( target ) ) * 0.5F * getSpecialData().rangedAttackSpread; + + for( int i = 0; i < 3; i++ ) { + final double dX = target.getX() - getX() + getRandom().nextGaussian() * accelVariance; + final double dY = target.getEyeY() - getEyeY(); + final double dZ = target.getZ() - getZ() + getRandom().nextGaussian() * accelVariance; + + final SmallFireballEntity fireball = new SmallFireballEntity( level, this, dX, dY, dZ ); + fireball.setPos( fireball.getX(), getEyeY() - 0.1, fireball.getZ() ); + level.addFreshEntity( fireball ); + } } + /** Sets this entity as a baby. */ + @Override + public void setBaby( boolean value ) { } + + /** @return True if this entity is a baby. */ + @Override + public boolean isBaby() { return false; } + private static final ResourceLocation[] TEXTURES = { GET_TEXTURE_PATH( "fire" ) }; diff --git a/src/main/java/fathertoast/specialmobs/common/entity/witherskeleton/SpitfireWitherSkeletonEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/witherskeleton/SpitfireWitherSkeletonEntity.java index dbd0bb7..5230d0b 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/witherskeleton/SpitfireWitherSkeletonEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/witherskeleton/SpitfireWitherSkeletonEntity.java @@ -12,8 +12,10 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.ai.attributes.AttributeModifierMap; import net.minecraft.entity.ai.attributes.Attributes; +import net.minecraft.entity.projectile.SmallFireballEntity; import net.minecraft.item.Items; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import javax.annotation.ParametersAreNonnullByDefault; @@ -62,7 +64,7 @@ public class SpitfireWitherSkeletonEntity extends _SpecialWitherSkeletonEntity { public SpitfireWitherSkeletonEntity( EntityType entityType, World world ) { super( entityType, world ); - getSpecialData().setBaseScale( 1.5F ); + getSpecialData().setBaseScale( 1.8F ); getSpecialData().setDamagedByWater( true ); maxUpStep = 1.0F; xpReward += 2; @@ -72,9 +74,12 @@ public class SpitfireWitherSkeletonEntity extends _SpecialWitherSkeletonEntity { @Override protected void registerVariantGoals() { getSpecialData().rangedAttackDamage += 2.0F; - getSpecialData().rangedAttackSpread *= 0.5F; } + /** Override to change this entity's chance to spawn with a bow. */ + @Override + protected double getVariantBowChance() { return 1.0; } + /** Override to apply effects when this entity hits a target with a melee attack. */ @Override protected void onVariantAttack( Entity target ) { @@ -84,9 +89,29 @@ public class SpitfireWitherSkeletonEntity extends _SpecialWitherSkeletonEntity { /** Called to attack the target with a ranged attack. */ @Override public void performRangedAttack( LivingEntity target, float damageMulti ) { - //TODO + if( !isSilent() ) level.levelEvent( null, 1018, blockPosition(), 0 ); + + final float accelVariance = MathHelper.sqrt( distanceTo( target ) ) * 0.5F * getSpecialData().rangedAttackSpread; + + for( int i = 0; i < 4; i++ ) { + final double dX = target.getX() - getX() + getRandom().nextGaussian() * accelVariance; + final double dY = target.getEyeY() - getEyeY(); + final double dZ = target.getZ() - getZ() + getRandom().nextGaussian() * accelVariance; + + final SmallFireballEntity fireball = new SmallFireballEntity( level, this, dX, dY, dZ ); + fireball.setPos( fireball.getX(), getEyeY() - 0.1, fireball.getZ() ); + level.addFreshEntity( fireball ); + } } + /** Sets this entity as a baby. */ + @Override + public void setBaby( boolean value ) { } + + /** @return True if this entity is a baby. */ + @Override + public boolean isBaby() { return false; } + private static final ResourceLocation[] TEXTURES = { GET_TEXTURE_PATH( "fire" ) }; diff --git a/src/main/java/fathertoast/specialmobs/common/entity/zombie/FireZombieEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/zombie/FireZombieEntity.java index 4ee921b..33e6060 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/zombie/FireZombieEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/zombie/FireZombieEntity.java @@ -75,6 +75,10 @@ public class FireZombieEntity extends _SpecialZombieEntity { return arrow; } + /** @return True if this entity should appear to be on fire. */ + @Override + public boolean isOnFire() { return isAlive() && !isInWaterRainOrBubble(); } + /** @return The sound this entity makes idly. */ @Override protected SoundEvent getAmbientSound() { return SoundEvents.HUSK_AMBIENT; }