Jump to content

[1.15.2] Why my custom monsters spawn in villagers' house?


NGYF

Recommended Posts

I try to make my custom entity spawn in world. But when I test in Superflat world, my custom entities only spawn in villagers house.

Can anybody tell me why, and how to spawn it correctly?

Here is the code:

OriginiumSlugEntity.java

Spoiler

public class OriginiumSlugEntity extends MonsterEntity {
   private OriginiumSlugEntity.SummonOriginiumSlugGoal summonOriginiumSlug;
   public EntitySize size;

   public OriginiumSlugEntity(EntityType<? extends OriginiumSlugEntity> typeIn, World worldIn) {
      super(typeIn, worldIn);
   }

   public static boolean spawnCondition (EntityType<? extends OriginiumSlugEntity> entityType, IWorld world, SpawnReason spawnReason, BlockPos pos, Random random) {
      //return world.getBlockState(pos.down()).getBlock() == Blocks.GRASS_BLOCK;
      return true;
   }

   protected void registerGoals() {
      this.summonOriginiumSlug = new OriginiumSlugEntity.SummonOriginiumSlugGoal(this);
      this.goalSelector.addGoal(10, new LookAtGoal(this, AnimalEntity.class, 8.0F));
      this.goalSelector.addGoal(10, new LookRandomlyGoal(this));
      this.goalSelector.addGoal(10, new LookAtGoal(this, PlayerEntity.class, 8.0F));
      this.goalSelector.addGoal(10, new LookAtGoal(this, AbstractVillagerEntity.class, 8.0F));
      this.goalSelector.addGoal(10, new RandomWalkingGoal(this, 1.0F));
      this.goalSelector.addGoal(1, new SwimGoal(this));
      this.goalSelector.addGoal(10, new RandomSwimmingGoal(this, 1.0F, 120));
      this.goalSelector.addGoal(3, this.summonOriginiumSlug);
      this.goalSelector.addGoal(4, new MeleeAttackGoal(this, 1.0D, false));
      this.targetSelector.addGoal(1, (new HurtByTargetGoal(this)).setCallsForHelp());
      this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, AnimalEntity.class, true));
      this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true));
      this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, AbstractVillagerEntity.class, true));
   }

   /**
    * Returns the Y Offset of this entity.
    */

   public double getYOffset() {
      return 0.1D;
   }

   protected float getStandingEyeHeight(Pose poseIn, EntitySize sizeIn) {
      return 0.1F;
   }

   protected void registerAttributes() {
      super.registerAttributes();
      this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(8.0D);
      this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.25D);
      this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(1.0D);
   }

   protected boolean func_225502_at_() {
      return false;
   }


   /**
    * Called when the entity is attacked.
    */
   public boolean attackEntityFrom(DamageSource source, float amount) {
      if (this.isInvulnerableTo(source)) {
         return false;
      } else {
         if ((source instanceof EntityDamageSource || source == DamageSource.MAGIC) && this.summonOriginiumSlug != null) {
            this.summonOriginiumSlug.notifyHurt();
         }

         return super.attackEntityFrom(source, amount);
      }
   }


   public static boolean func_223331_b(EntityType<OriginiumSlugEntity> p_223331_0_, IWorld p_223331_1_, SpawnReason p_223331_2_, BlockPos p_223331_3_, Random p_223331_4_) {
      if (func_223324_d(p_223331_0_, p_223331_1_, p_223331_2_, p_223331_3_, p_223331_4_)) {
         PlayerEntity playerentity = p_223331_1_.getClosestPlayer((double) p_223331_3_.getX() + 0.5D, (double) p_223331_3_.getY() + 0.5D, (double) p_223331_3_.getZ() + 0.5D, 5.0D, true);
         return playerentity == null;
      } else {
         return false;
      }
   }


   static class SummonOriginiumSlugGoal extends Goal {
      private final OriginiumSlugEntity originiumslug;
      private int lookForFriends;

      public SummonOriginiumSlugGoal(OriginiumSlugEntity originiumslugIn) {
         this.originiumslug = originiumslugIn;
      }

      public void notifyHurt() {
         if (this.lookForFriends == 0) {
            this.lookForFriends = 20;
         }

      }

      public boolean shouldExecute() {
         return this.lookForFriends > 0;
      }

      @Nullable
      public AxisAlignedBB getCollisionBox(Entity entityIn) {
         return new AxisAlignedBB(-4.0, -3.0, -5.0, 4.0, 3.0, 5.0);
      }
   }
}

 

EntitySpawnHandler.java

Spoiler

public class EntitySpawnHandler {
    public static void register(){
        EntitySpawnPlacementRegistry.register(EntityHandler.ORIGINIUMSLUG, EntitySpawnPlacementRegistry.PlacementType.ON_GROUND, Heightmap.Type.MOTION_BLOCKING_NO_LEAVES, OriginiumSlugEntity::spawnCondition);
        PLAINS.getSpawns(EntityClassification.MONSTER).clear();//only for test

        registerEntityWorldSpawn(EntityHandler.ORIGINIUMSLUG, 100, PLAINS, DESERT, MOUNTAINS, FOREST, TAIGA, SWAMP, NETHER, BEACH, DESERT_HILLS, WOODED_HILLS,
                TAIGA_HILLS, MOUNTAIN_EDGE, JUNGLE, JUNGLE_HILLS, JUNGLE_EDGE, STONE_SHORE, BIRCH_FOREST,
                BIRCH_FOREST_HILLS, DARK_FOREST, GIANT_TREE_TAIGA, GIANT_TREE_TAIGA_HILLS, WOODED_MOUNTAINS, SAVANNA, SAVANNA_PLATEAU, BADLANDS, WOODED_BADLANDS_PLATEAU, BADLANDS_PLATEAU, GRAVELLY_MOUNTAINS,
                TAIGA_MOUNTAINS, SWAMP_HILLS, MODIFIED_JUNGLE, MODIFIED_JUNGLE_EDGE, TALL_BIRCH_FOREST, TALL_BIRCH_HILLS,
                DARK_FOREST_HILLS, GIANT_SPRUCE_TAIGA, GIANT_TREE_TAIGA_HILLS, MODIFIED_GRAVELLY_MOUNTAINS, SHATTERED_SAVANNA, SHATTERED_SAVANNA_PLATEAU,
                ERODED_BADLANDS, MODIFIED_WOODED_BADLANDS_PLATEAU, MODIFIED_BADLANDS_PLATEAU);
    }

    public static void registerEntityWorldSpawn(EntityType<?> entity, int weight, Biome... biomes) {
        for (Biome biome : biomes) {
            if (biome != null) {
                biome.getSpawns(entity.getClassification()).add(new Biome.SpawnListEntry(entity, weight, 1, 10));
            }
        }
    }
}

 

Thank you for your help.

 

By the way, now I need to generate some ore, but I don't know how to start. Could you please tell me how?

Edited by NGYF
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.