From 631b9b6c60ee9ef10c2728b59499b274cc3e9e08 Mon Sep 17 00:00:00 2001 From: FatherToast Date: Thu, 23 Jun 2022 22:34:24 -0500 Subject: [PATCH] Goldn't fish --- .../specialmobs/client/ClientRegister.java | 2 + .../entity/SpecialSilverfishRenderer.java | 44 +++ .../entity/SpecialSpiderRenderer.java | 5 - .../common/bestiary/MobFamily.java | 13 +- .../cavespider/MotherCaveSpiderEntity.java | 2 +- .../silverfish/BlindingSilverfishEntity.java | 80 ++++++ .../silverfish/FlyingSilverfishEntity.java | 76 ++++++ .../silverfish/PoisonSilverfishEntity.java | 79 ++++++ .../silverfish/ToughSilverfishEntity.java | 72 +++++ .../silverfish/_SpecialSilverfishEntity.java | 252 ++++++++++++++++++ .../entity/spider/MotherSpiderEntity.java | 2 +- 11 files changed, 612 insertions(+), 15 deletions(-) create mode 100644 src/main/java/fathertoast/specialmobs/client/renderer/entity/SpecialSilverfishRenderer.java create mode 100644 src/main/java/fathertoast/specialmobs/common/entity/silverfish/BlindingSilverfishEntity.java create mode 100644 src/main/java/fathertoast/specialmobs/common/entity/silverfish/FlyingSilverfishEntity.java create mode 100644 src/main/java/fathertoast/specialmobs/common/entity/silverfish/PoisonSilverfishEntity.java create mode 100644 src/main/java/fathertoast/specialmobs/common/entity/silverfish/ToughSilverfishEntity.java create mode 100644 src/main/java/fathertoast/specialmobs/common/entity/silverfish/_SpecialSilverfishEntity.java diff --git a/src/main/java/fathertoast/specialmobs/client/ClientRegister.java b/src/main/java/fathertoast/specialmobs/client/ClientRegister.java index 383f64d..7701854 100644 --- a/src/main/java/fathertoast/specialmobs/client/ClientRegister.java +++ b/src/main/java/fathertoast/specialmobs/client/ClientRegister.java @@ -1,6 +1,7 @@ package fathertoast.specialmobs.client; import fathertoast.specialmobs.client.renderer.entity.SpecialCreeperRenderer; +import fathertoast.specialmobs.client.renderer.entity.SpecialSilverfishRenderer; import fathertoast.specialmobs.client.renderer.entity.SpecialSkeletonRenderer; import fathertoast.specialmobs.client.renderer.entity.SpecialSpiderRenderer; import fathertoast.specialmobs.common.bestiary.MobFamily; @@ -32,6 +33,7 @@ public class ClientRegister { //registerFamilyRenderers( MobFamily.SKELETON, SpecialSkeletonRenderer::new ); registerFamilyRenderers( MobFamily.SPIDER, SpecialSpiderRenderer::new ); registerFamilyRenderers( MobFamily.CAVE_SPIDER, SpecialSpiderRenderer::new ); + registerFamilyRenderers( MobFamily.SILVERFISH, SpecialSilverfishRenderer::new ); } private static void registerFamilyRenderers( MobFamily family, IRenderFactory renderFactory ) { diff --git a/src/main/java/fathertoast/specialmobs/client/renderer/entity/SpecialSilverfishRenderer.java b/src/main/java/fathertoast/specialmobs/client/renderer/entity/SpecialSilverfishRenderer.java new file mode 100644 index 0000000..0b7ea34 --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/client/renderer/entity/SpecialSilverfishRenderer.java @@ -0,0 +1,44 @@ +package fathertoast.specialmobs.client.renderer.entity; + +import com.mojang.blaze3d.matrix.MatrixStack; +import fathertoast.specialmobs.client.renderer.entity.layers.SpecialMobEyesLayer; +import fathertoast.specialmobs.common.entity.ISpecialMob; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.client.renderer.entity.EntityRendererManager; +import net.minecraft.client.renderer.entity.SilverfishRenderer; +import net.minecraft.entity.monster.SilverfishEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +@OnlyIn( Dist.CLIENT ) +public class SpecialSilverfishRenderer extends SilverfishRenderer { + + private final float baseShadowRadius; + + public SpecialSilverfishRenderer( EntityRendererManager rendererManager ) { + super( rendererManager ); + baseShadowRadius = shadowRadius; + addLayer( new SpecialMobEyesLayer<>( this ) ); + // Model doesn't support size parameter + //addLayer( new SpecialMobOverlayLayer<>( this, new SilverfishModel<>( 0.25F ) ) ); + } + + @Override + public ResourceLocation getTextureLocation( SilverfishEntity entity ) { + return ((ISpecialMob) entity).getSpecialData().getTexture(); + } + + @Override + protected void scale( SilverfishEntity entity, MatrixStack matrixStack, float partialTick ) { + super.scale( entity, matrixStack, partialTick ); + + final float scale = ((ISpecialMob) entity).getSpecialData().getRenderScale(); + shadowRadius = baseShadowRadius * scale; + matrixStack.scale( scale, scale, scale ); + } +} \ No newline at end of file diff --git a/src/main/java/fathertoast/specialmobs/client/renderer/entity/SpecialSpiderRenderer.java b/src/main/java/fathertoast/specialmobs/client/renderer/entity/SpecialSpiderRenderer.java index 070762f..9b86e05 100644 --- a/src/main/java/fathertoast/specialmobs/client/renderer/entity/SpecialSpiderRenderer.java +++ b/src/main/java/fathertoast/specialmobs/client/renderer/entity/SpecialSpiderRenderer.java @@ -2,15 +2,10 @@ package fathertoast.specialmobs.client.renderer.entity; import com.mojang.blaze3d.matrix.MatrixStack; import fathertoast.specialmobs.client.renderer.entity.layers.SpecialMobEyesLayer; -import fathertoast.specialmobs.client.renderer.entity.layers.SpecialMobOverlayLayer; import fathertoast.specialmobs.common.entity.ISpecialMob; import mcp.MethodsReturnNonnullByDefault; -import net.minecraft.client.renderer.entity.CreeperRenderer; import net.minecraft.client.renderer.entity.EntityRendererManager; import net.minecraft.client.renderer.entity.SpiderRenderer; -import net.minecraft.client.renderer.entity.model.CreeperModel; -import net.minecraft.client.renderer.entity.model.SpiderModel; -import net.minecraft.entity.monster.CreeperEntity; import net.minecraft.entity.monster.SpiderEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/fathertoast/specialmobs/common/bestiary/MobFamily.java b/src/main/java/fathertoast/specialmobs/common/bestiary/MobFamily.java index 8870568..389f96c 100644 --- a/src/main/java/fathertoast/specialmobs/common/bestiary/MobFamily.java +++ b/src/main/java/fathertoast/specialmobs/common/bestiary/MobFamily.java @@ -8,10 +8,7 @@ import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.Block; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.monster.AbstractSkeletonEntity; -import net.minecraft.entity.monster.CaveSpiderEntity; -import net.minecraft.entity.monster.CreeperEntity; -import net.minecraft.entity.monster.SpiderEntity; +import net.minecraft.entity.monster.*; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.ForgeSpawnEggItem; @@ -82,10 +79,10 @@ public class MobFamily { "Baby", "Flying", "Mother", "Web", "Witch" ); - // public static final MobFamily SILVERFISH = new MobFamily<>( - // "Silverfish", "silverfish", 0x6E6E6E, new EntityType[] { EntityType.SILVERFISH }, - // "Blinding", "Fishing", "Flying", "Poison", "Tough" - // ); + public static final MobFamily SILVERFISH = new MobFamily<>( + "Silverfish", "silverfish", 0x6E6E6E, new EntityType[] { EntityType.SILVERFISH }, + "Blinding", /*"Fishing",*/ "Flying", "Poison", /*"Puffer",*/ "Tough" + ); // public static final MobFamily ENDERMAN = new MobFamily<>( // "Enderman", "endermen", 0x161616, new EntityType[] { EntityType.ENDERMAN }, diff --git a/src/main/java/fathertoast/specialmobs/common/entity/cavespider/MotherCaveSpiderEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/cavespider/MotherCaveSpiderEntity.java index 30b2a94..33f55ee 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/cavespider/MotherCaveSpiderEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/cavespider/MotherCaveSpiderEntity.java @@ -39,8 +39,8 @@ public class MotherCaveSpiderEntity extends _SpecialCaveSpiderEntity { public static AttributeModifierMap.MutableAttribute createAttributes() { return AttributeHelper.of( _SpecialCaveSpiderEntity.createAttributes() ) .addAttribute( Attributes.MAX_HEALTH, 16.0 ) - .addAttribute( Attributes.ATTACK_DAMAGE, 3.0 ) .addAttribute( Attributes.ARMOR, 6.0 ) + .addAttribute( Attributes.ATTACK_DAMAGE, 3.0 ) .build(); } diff --git a/src/main/java/fathertoast/specialmobs/common/entity/silverfish/BlindingSilverfishEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/BlindingSilverfishEntity.java new file mode 100644 index 0000000..045cf85 --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/BlindingSilverfishEntity.java @@ -0,0 +1,80 @@ +package fathertoast.specialmobs.common.entity.silverfish; + +import fathertoast.specialmobs.common.bestiary.BestiaryInfo; +import fathertoast.specialmobs.common.bestiary.SpecialMob; +import fathertoast.specialmobs.common.entity.MobHelper; +import fathertoast.specialmobs.common.util.References; +import fathertoast.specialmobs.datagen.loot.LootTableBuilder; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.attributes.AttributeModifierMap; +import net.minecraft.item.Items; +import net.minecraft.potion.EffectInstance; +import net.minecraft.potion.Effects; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +@SpecialMob +public class BlindingSilverfishEntity extends _SpecialSilverfishEntity { + + //--------------- Static Special Mob Hooks ---------------- + + @SpecialMob.BestiaryInfoSupplier + public static BestiaryInfo bestiaryInfo( EntityType.Builder entityType ) { + return new BestiaryInfo( 0x000000 ); + //TODO theme - forest + } + + @SpecialMob.AttributeCreator + public static AttributeModifierMap.MutableAttribute createAttributes() { + return _SpecialSilverfishEntity.createAttributes(); + } + + @SpecialMob.LanguageProvider + public static String[] getTranslations( String langKey ) { + return References.translations( langKey, "Blinding Silverfish", + "", "", "", "", "", "" );//TODO + } + + @SpecialMob.LootTableProvider + public static void buildLootTable( LootTableBuilder loot ) { + addBaseLoot( loot ); + loot.addCommonDrop( "common", Items.INK_SAC ); + } + + @SpecialMob.Constructor + public BlindingSilverfishEntity( EntityType entityType, World world ) { + super( entityType, world ); + getSpecialData().addPotionImmunity( Effects.BLINDNESS ); + xpReward += 1; + } + + + //--------------- Variant-Specific Implementations ---------------- + + /** Override to apply effects when this entity hits a target with a melee attack. */ + @Override + protected void onVariantAttack( Entity target ) { + if( target instanceof LivingEntity ) { + final LivingEntity livingTarget = (LivingEntity) target; + final int duration = MobHelper.getDebuffDuration( level.getDifficulty() ); + + livingTarget.addEffect( new EffectInstance( Effects.BLINDNESS, duration ) ); + livingTarget.removeEffect( Effects.NIGHT_VISION ); // Prevent blind + night vision combo (black screen) + } + } + + private static final ResourceLocation[] TEXTURES = { + GET_TEXTURE_PATH( "blinding" ) + }; + + /** @return All default textures for this entity. */ + @Override + public ResourceLocation[] getDefaultTextures() { return TEXTURES; } +} \ No newline at end of file diff --git a/src/main/java/fathertoast/specialmobs/common/entity/silverfish/FlyingSilverfishEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/FlyingSilverfishEntity.java new file mode 100644 index 0000000..a0ad8c1 --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/FlyingSilverfishEntity.java @@ -0,0 +1,76 @@ +package fathertoast.specialmobs.common.entity.silverfish; + +import fathertoast.specialmobs.common.bestiary.BestiaryInfo; +import fathertoast.specialmobs.common.bestiary.SpecialMob; +import fathertoast.specialmobs.common.entity.ai.SpecialLeapAtTargetGoal; +import fathertoast.specialmobs.common.util.AttributeHelper; +import fathertoast.specialmobs.common.util.References; +import fathertoast.specialmobs.datagen.loot.LootTableBuilder; +import mcp.MethodsReturnNonnullByDefault; +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.item.Items; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +@SpecialMob +public class FlyingSilverfishEntity extends _SpecialSilverfishEntity { + + //--------------- Static Special Mob Hooks ---------------- + + @SpecialMob.BestiaryInfoSupplier + public static BestiaryInfo bestiaryInfo( EntityType.Builder entityType ) { + return new BestiaryInfo( 0x6388B2 ); + //TODO theme - mountain + } + + @SpecialMob.AttributeCreator + public static AttributeModifierMap.MutableAttribute createAttributes() { + return AttributeHelper.of( _SpecialSilverfishEntity.createAttributes() ) + .multAttribute( Attributes.MOVEMENT_SPEED, 1.2 ) + .build(); + } + + @SpecialMob.LanguageProvider + public static String[] getTranslations( String langKey ) { + return References.translations( langKey, "Flying Silverfish", + "", "", "", "", "", "" );//TODO + } + + @SpecialMob.LootTableProvider + public static void buildLootTable( LootTableBuilder loot ) { + addBaseLoot( loot ); + loot.addCommonDrop( "common", Items.FEATHER, 1 ); + } + + @SpecialMob.Constructor + public FlyingSilverfishEntity( EntityType entityType, World world ) { + super( entityType, world ); + getSpecialData().setFallDamageMultiplier( 0.0F ); + xpReward += 2; + } + + + //--------------- Variant-Specific Implementations ---------------- + + /** Override to change this entity's AI goals. */ + @Override + protected void registerVariantGoals() { + goalSelector.addGoal( 3, new SpecialLeapAtTargetGoal( + this, 10, 6.0F, 12.0F, 2.0F, 2.0F ) ); + } + + private static final ResourceLocation[] TEXTURES = { + GET_TEXTURE_PATH( "flying" ) + }; + + /** @return All default textures for this entity. */ + @Override + public ResourceLocation[] getDefaultTextures() { return TEXTURES; } +} \ No newline at end of file diff --git a/src/main/java/fathertoast/specialmobs/common/entity/silverfish/PoisonSilverfishEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/PoisonSilverfishEntity.java new file mode 100644 index 0000000..79a22dd --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/PoisonSilverfishEntity.java @@ -0,0 +1,79 @@ +package fathertoast.specialmobs.common.entity.silverfish; + +import fathertoast.specialmobs.common.bestiary.BestiaryInfo; +import fathertoast.specialmobs.common.bestiary.SpecialMob; +import fathertoast.specialmobs.common.entity.MobHelper; +import fathertoast.specialmobs.common.util.References; +import fathertoast.specialmobs.datagen.loot.LootTableBuilder; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.attributes.AttributeModifierMap; +import net.minecraft.item.Items; +import net.minecraft.potion.EffectInstance; +import net.minecraft.potion.Effects; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +@SpecialMob +public class PoisonSilverfishEntity extends _SpecialSilverfishEntity { + + //--------------- Static Special Mob Hooks ---------------- + + @SpecialMob.BestiaryInfoSupplier + public static BestiaryInfo bestiaryInfo( EntityType.Builder entityType ) { + return new BestiaryInfo( 0x779C68 ); + //TODO theme - forest + } + + @SpecialMob.AttributeCreator + public static AttributeModifierMap.MutableAttribute createAttributes() { + return _SpecialSilverfishEntity.createAttributes(); + } + + @SpecialMob.LanguageProvider + public static String[] getTranslations( String langKey ) { + return References.translations( langKey, "Venomous Silverfish", + "", "", "", "", "", "" );//TODO + } + + @SpecialMob.LootTableProvider + public static void buildLootTable( LootTableBuilder loot ) { + addBaseLoot( loot ); + loot.addUncommonDrop( "uncommon", Items.SPIDER_EYE ); + } + + @SpecialMob.Constructor + public PoisonSilverfishEntity( EntityType entityType, World world ) { + super( entityType, world ); + getSpecialData().addPotionImmunity( Effects.POISON ); + xpReward += 1; + } + + + //--------------- Variant-Specific Implementations ---------------- + + /** Override to apply effects when this entity hits a target with a melee attack. */ + @Override + protected void onVariantAttack( Entity target ) { + if( target instanceof LivingEntity ) { + final LivingEntity livingTarget = (LivingEntity) target; + final int duration = MobHelper.getDebuffDuration( level.getDifficulty() ); + + livingTarget.addEffect( new EffectInstance( Effects.POISON, duration ) ); + } + } + + private static final ResourceLocation[] TEXTURES = { + GET_TEXTURE_PATH( "poison" ) + }; + + /** @return All default textures for this entity. */ + @Override + public ResourceLocation[] getDefaultTextures() { return TEXTURES; } +} \ No newline at end of file diff --git a/src/main/java/fathertoast/specialmobs/common/entity/silverfish/ToughSilverfishEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/ToughSilverfishEntity.java new file mode 100644 index 0000000..7d091e7 --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/ToughSilverfishEntity.java @@ -0,0 +1,72 @@ +package fathertoast.specialmobs.common.entity.silverfish; + +import fathertoast.specialmobs.common.bestiary.BestiaryInfo; +import fathertoast.specialmobs.common.bestiary.SpecialMob; +import fathertoast.specialmobs.common.util.AttributeHelper; +import fathertoast.specialmobs.common.util.References; +import fathertoast.specialmobs.datagen.loot.LootTableBuilder; +import mcp.MethodsReturnNonnullByDefault; +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.item.Items; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +@SpecialMob +public class ToughSilverfishEntity extends _SpecialSilverfishEntity { + + //--------------- Static Special Mob Hooks ---------------- + + @SpecialMob.BestiaryInfoSupplier + public static BestiaryInfo bestiaryInfo( EntityType.Builder entityType ) { + entityType.sized( 0.6F, 0.9F ); + return new BestiaryInfo( 0xDD0E0E, BestiaryInfo.BaseWeight.LOW ); + } + + @SpecialMob.AttributeCreator + public static AttributeModifierMap.MutableAttribute createAttributes() { + return AttributeHelper.of( _SpecialSilverfishEntity.createAttributes() ) + .addAttribute( Attributes.MAX_HEALTH, 16.0 ) + .addAttribute( Attributes.ARMOR, 15.0 ) + .addAttribute( Attributes.ATTACK_DAMAGE, 2.0 ) + .multAttribute( Attributes.MOVEMENT_SPEED, 0.7 ) + .build(); + } + + @SpecialMob.LanguageProvider + public static String[] getTranslations( String langKey ) { + return References.translations( langKey, "Tough Silverfish", + "", "", "", "", "", "" );//TODO + } + + @SpecialMob.LootTableProvider + public static void buildLootTable( LootTableBuilder loot ) { + addBaseLoot( loot ); + loot.addCommonDrop( "common", Items.FLINT, 1 ); + loot.addRareDrop( "rare", Items.IRON_INGOT ); + } + + @SpecialMob.Constructor + public ToughSilverfishEntity( EntityType entityType, World world ) { + super( entityType, world ); + getSpecialData().setBaseScale( 1.5F ); + xpReward += 2; + } + + + //--------------- Variant-Specific Implementations ---------------- + + private static final ResourceLocation[] TEXTURES = { + GET_TEXTURE_PATH( "tough" ) + }; + + /** @return All default textures for this entity. */ + @Override + public ResourceLocation[] getDefaultTextures() { return TEXTURES; } +} \ No newline at end of file diff --git a/src/main/java/fathertoast/specialmobs/common/entity/silverfish/_SpecialSilverfishEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/_SpecialSilverfishEntity.java new file mode 100644 index 0000000..a467e35 --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/entity/silverfish/_SpecialSilverfishEntity.java @@ -0,0 +1,252 @@ +package fathertoast.specialmobs.common.entity.silverfish; + +import fathertoast.specialmobs.common.bestiary.BestiaryInfo; +import fathertoast.specialmobs.common.bestiary.SpecialMob; +import fathertoast.specialmobs.common.core.SpecialMobs; +import fathertoast.specialmobs.common.entity.ISpecialMob; +import fathertoast.specialmobs.common.entity.SpecialMobData; +import fathertoast.specialmobs.common.util.References; +import fathertoast.specialmobs.datagen.loot.LootTableBuilder; +import mcp.MethodsReturnNonnullByDefault; +import net.minecraft.block.BlockState; +import net.minecraft.entity.*; +import net.minecraft.entity.ai.attributes.AttributeModifierMap; +import net.minecraft.entity.ai.attributes.Attributes; +import net.minecraft.entity.monster.SilverfishEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.network.datasync.DataParameter; +import net.minecraft.network.datasync.DataSerializers; +import net.minecraft.network.datasync.EntityDataManager; +import net.minecraft.potion.EffectInstance; +import net.minecraft.util.DamageSource; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.world.DifficultyInstance; +import net.minecraft.world.IServerWorld; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; + +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +@SpecialMob +public class _SpecialSilverfishEntity extends SilverfishEntity implements ISpecialMob<_SpecialSilverfishEntity> { + + //--------------- Static Special Mob Hooks ---------------- + + @SpecialMob.BestiaryInfoSupplier + public static BestiaryInfo bestiaryInfo( EntityType.Builder entityType ) { + return new BestiaryInfo( 0x303030 ); + } + + @SpecialMob.AttributeCreator + public static AttributeModifierMap.MutableAttribute createAttributes() { + return SilverfishEntity.createAttributes(); + } + + @SpecialMob.LanguageProvider + public static String[] getTranslations( String langKey ) { + return References.translations( langKey, "Silverfish", + "", "", "", "", "", "" );//TODO + } + + @SpecialMob.LootTableProvider + public static void addBaseLoot( LootTableBuilder loot ) { + loot.addLootTable( "main", EntityType.SILVERFISH.getDefaultLootTable() ); + } + + @SpecialMob.Constructor + public _SpecialSilverfishEntity( EntityType entityType, World world ) { + super( entityType, world ); + specialData.initialize(); + } + + + //--------------- Variant-Specific Breakouts ---------------- + + /** Called in the MobEntity.class constructor to initialize AI goals. */ + @Override + protected void registerGoals() { + super.registerGoals(); + registerVariantGoals(); + } + + /** Override to change this entity's AI goals. */ + protected void registerVariantGoals() { } + + /** Called to melee attack the target. */ + @Override + public boolean doHurtTarget( Entity target ) { + if( super.doHurtTarget( target ) ) { + onVariantAttack( target ); + return true; + } + return false; + } + + /** Override to apply effects when this entity hits a target with a melee attack. */ + protected void onVariantAttack( Entity target ) { } + + /** Override to save data to this entity's NBT data. */ + public void addVariantSaveData( CompoundNBT saveTag ) { } + + /** Override to load data from this entity's NBT data. */ + public void readVariantSaveData( CompoundNBT saveTag ) { } + + + //--------------- Family-Specific Implementations ---------------- + + /** The parameter for special mob render scale. */ + private static final DataParameter SCALE = EntityDataManager.defineId( _SpecialSilverfishEntity.class, DataSerializers.FLOAT ); + + /** Called from the Entity.class constructor to define data watcher variables. */ + @Override + protected void defineSynchedData() { + super.defineSynchedData(); + specialData = new SpecialMobData<>( this, SCALE, 1.0F ); + } + + /** Called on spawn to initialize properties based on the world, difficulty, and the group it spawns with. */ + @Nullable + public ILivingEntityData finalizeSpawn( IServerWorld world, DifficultyInstance difficulty, SpawnReason spawnReason, + @Nullable ILivingEntityData groupData, @Nullable CompoundNBT eggTag ) { + groupData = super.finalizeSpawn( world, difficulty, spawnReason, groupData, eggTag ); + + // TODO ranged attack + + if( random.nextFloat() < 0.05 ) { //TODO config + // Immediately start calling for reinforcements if it can find a player + if( getTarget() == null ) { + final double followRange = getAttributeValue( Attributes.FOLLOW_RANGE ); + final List nearbyPlayers = world.getNearbyPlayers( new EntityPredicate().range( followRange ), + this, getBoundingBox().inflate( followRange, followRange, followRange ) ); + for( PlayerEntity player : nearbyPlayers ) { + if( player != null && canSee( player ) ) { + setTarget( player ); + break; + } + } + } + if( getTarget() != null ) { + // Triggers silverfish call for reinforcements + hurt( DamageSource.MAGIC, 0.0F ); + } + } + + return groupData; + } + + + //--------------- ISpecialMob Implementation ---------------- + + private SpecialMobData<_SpecialSilverfishEntity> specialData; + + /** @return This mob's special data. */ + @Override + public SpecialMobData<_SpecialSilverfishEntity> getSpecialData() { return specialData; } + + /** @return The experience that should be dropped by this entity. */ + @Override + public final int getExperience() { return xpReward; } + + /** Sets the experience that should be dropped by this entity. */ + @Override + public final void setExperience( int xp ) { xpReward = xp; } + + static ResourceLocation GET_TEXTURE_PATH( String type ) { + return SpecialMobs.resourceLoc( SpecialMobs.TEXTURE_PATH + "silverfish/" + type + ".png" ); + } + + private static final ResourceLocation[] TEXTURES = { new ResourceLocation( "textures/entity/silverfish.png" ) }; + + /** @return All default textures for this entity. */ + @Override + public ResourceLocation[] getDefaultTextures() { return TEXTURES; } + + + //--------------- SpecialMobData Hooks ---------------- + + /** Called each tick to update this entity's movement. */ + @Override + public void aiStep() { + super.aiStep(); + getSpecialData().tick(); + } + + /** @return The eye height of this entity when standing. */ + @Override + protected float getStandingEyeHeight( Pose pose, EntitySize size ) { + return super.getStandingEyeHeight( pose, size ) * getSpecialData().getBaseScale() * (isBaby() ? 0.53448F : 1.0F); + } + + /** @return Whether this entity is immune to fire damage. */ + @Override + public boolean fireImmune() { return specialData.isImmuneToFire(); } + + /** Sets this entity on fire for a specific duration. */ + @Override + public void setRemainingFireTicks( int ticks ) { + if( !getSpecialData().isImmuneToBurning() ) super.setRemainingFireTicks( ticks ); + } + + /** @return True if this entity can be leashed. */ + @Override + public boolean canBeLeashed( PlayerEntity player ) { return !isLeashed() && getSpecialData().allowLeashing(); } + + /** Sets this entity 'stuck' inside a block, such as a cobweb or sweet berry bush. Mod blocks could use this as a speed boost. */ + @Override + public void makeStuckInBlock( BlockState block, Vector3d speedMulti ) { + if( specialData.canBeStuckIn( block ) ) super.makeStuckInBlock( block, speedMulti ); + } + + /** @return Called when this mob falls. Calculates and applies fall damage. Returns false if canceled. */ + @Override + public boolean causeFallDamage( float distance, float damageMultiplier ) { + return super.causeFallDamage( distance, damageMultiplier * getSpecialData().getFallDamageMultiplier() ); + } + + /** @return True if this entity should NOT trigger pressure plates or tripwires. */ + @Override + public boolean isIgnoringBlockTriggers() { return getSpecialData().ignorePressurePlates(); } + + /** @return True if this entity can breathe underwater. */ + @Override + public boolean canBreatheUnderwater() { return getSpecialData().canBreatheInWater(); } + + /** @return True if this entity can be pushed by (flowing) fluids. */ + @Override + public boolean isPushedByFluid() { return !getSpecialData().ignoreWaterPush(); } + + /** @return True if this entity takes damage while wet. */ + @Override + public boolean isSensitiveToWater() { return getSpecialData().isDamagedByWater(); } + + /** @return True if the effect can be applied to this entity. */ + @Override + public boolean canBeAffected( EffectInstance effect ) { return getSpecialData().isPotionApplicable( effect ); } + + /** Saves data to this entity's base NBT compound that is specific to its subclass. */ + @Override + public void addAdditionalSaveData( CompoundNBT tag ) { + super.addAdditionalSaveData( tag ); + + final CompoundNBT saveTag = SpecialMobData.getSaveLocation( tag ); + + getSpecialData().writeToNBT( saveTag ); + addVariantSaveData( saveTag ); + } + + /** Loads data from this entity's base NBT compound that is specific to its subclass. */ + @Override + public void readAdditionalSaveData( CompoundNBT tag ) { + super.readAdditionalSaveData( tag ); + + final CompoundNBT saveTag = SpecialMobData.getSaveLocation( tag ); + + getSpecialData().readFromNBT( saveTag ); + readVariantSaveData( saveTag ); + } +} \ No newline at end of file diff --git a/src/main/java/fathertoast/specialmobs/common/entity/spider/MotherSpiderEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/spider/MotherSpiderEntity.java index 01939be..c095ed7 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/spider/MotherSpiderEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/spider/MotherSpiderEntity.java @@ -40,8 +40,8 @@ public class MotherSpiderEntity extends _SpecialSpiderEntity { public static AttributeModifierMap.MutableAttribute createAttributes() { return AttributeHelper.of( _SpecialSpiderEntity.createAttributes() ) .addAttribute( Attributes.MAX_HEALTH, 16.0 ) - .addAttribute( Attributes.ATTACK_DAMAGE, 3.0 ) .addAttribute( Attributes.ARMOR, 6.0 ) + .addAttribute( Attributes.ATTACK_DAMAGE, 3.0 ) .build(); }