I am working on a simple mod to add a single mob to the game, but it is spawning far more than it should, and far more than any other mod. I haven't counted, but it's enough to lag down my generally beefy PC, and is definitely over twenty in a chunk. What am I doing wrong here? I'll admit, I have no idea how the weighted probability works. I've tested setting it to zero, and this results in none spawning, but setting it to one leads to the same aforementioned problem. Any insight?
(And while I'm here, I also want it so spawn in the daytime and in Peaceful, but no overrides I've tried so far have worked. However, that's a different problem and far less important than this one.)
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
// Here we set various attributes for our mob. Like maximum health, armor, speed, ...
this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(50.0D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.5D);
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(0.0D);
this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(0.0D);
}
@Override
protected void initEntityAI() {
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(2, new EntityAILutinAttack(this, 1.0D, false));
this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
this.tasks.addTask(8, new EntityAILookIdle(this));
this.applyEntityAI();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void applyEntityAI() {
this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
}
public static void init() {
// Every entity in our mod has an ID (local to this mod)
int id = 1;
EntityRegistry.registerModEntity(EntityLutin.LOOT, EntityLutin.class, "Lutin", id++, Main.instance, 64, 3, true, 0x996600, 0x00ff00);
// We want our mob to spawn in Plains and ice plains biomes. If you don't add this then it will not spawn automatically
// but you can of course still make it spawn manually
EntityRegistry.addSpawn(EntityLutin.class, 1, 0, 1, EnumCreatureType.AMBIENT, Biomes.BIRCH_FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.COLD_TAIGA, Biomes.COLD_TAIGA_HILLS, Biomes.DESERT, Biomes.DESERT_HILLS, Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_WITH_TREES, Biomes.FOREST, Biomes.FOREST_HILLS, Biomes.HELL, Biomes.ICE_MOUNTAINS, Biomes.ICE_PLAINS, Biomes.JUNGLE, Biomes.JUNGLE_HILLS, Biomes.MESA, Biomes.MESA_ROCK, Biomes.MUSHROOM_ISLAND, Biomes.PLAINS, Biomes.REDWOOD_TAIGA, Biomes.REDWOOD_TAIGA_HILLS, Biomes.ROOFED_FOREST, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.SWAMPLAND, Biomes.TAIGA, Biomes.TAIGA_HILLS);
// This is the loot table for our mob
LootTableList.register(EntityLutin.LOOT);
}
@SideOnly(Side.CLIENT)
public static void initModels() {
RenderingRegistry.registerEntityRenderingHandler(EntityLutin.class, new IRenderFactory<EntityLutin>()
{
@Override
public Render<? super EntityLutin> createRenderFor(RenderManager manager)
{
return new RenderLutin(manager);
}
});
}
}
The problem is that your entity is of type "EntityMob" (generally hostile mobs) but it is added to the "ambient" mob spawn list - which means that the ambient mob cap is not affected by your mob (which counts toward the hostile mob cap) so it will keep spawning as long as the cap is not reached (normally only bats occupy the ambient mob cap, and since they gradually despawn you mob will have opportunities to spawn even if it is otherwise full. Your mob appears to despawn as well since you don't override the default canDespawn() method but this does not happen that fast. A similar situation occurs with ocelots in vanilla, which spawn under the hostile mob cap but are passive so they do not count towards it, but ocelots have a very low probability of spawning relative to other hostile mobs, I've still seen the entity count in F3 exceed 300 in jungles where I lit up all the caves so they are the only mob that can spawn).
You'll either want to change the class of mob (to "EntityAmbientCreature") or the spawn list; mobs of type EntityMob also automatically despawn on Peaceful so you'll probably want to do the former if you want it to spawn on Peaceful (note that the type of mob does not determine its behavior, which is set by its AI; e.g. rabbits are based on EntityAnimal (generally passive and harmless) but killer rabbits have an attack AI function added to the default rabbit AI list; wolves are also "passive" but attack when provoked, and so on).
I am working on a simple mod to add a single mob to the game, but it is spawning far more than it should, and far more than any other mod. I haven't counted, but it's enough to lag down my generally beefy PC, and is definitely over twenty in a chunk. What am I doing wrong here? I'll admit, I have no idea how the weighted probability works. I've tested setting it to zero, and this results in none spawning, but setting it to one leads to the same aforementioned problem. Any insight?
(And while I'm here, I also want it so spawn in the daytime and in Peaceful, but no overrides I've tried so far have worked. However, that's a different problem and far less important than this one.)
EntityLutin.class
package com.volbot.kone.mobs;
import javax.annotation.Nullable;
import javax.swing.text.html.parser.Entity;
import com.volbot.kone.ref.Ref;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
public class EntityLutin extends EntityMob{
public static final ResourceLocation LOOT = new ResourceLocation(Ref.modId, "entities/lutin");
public EntityLutin(World worldIn) {
super(worldIn);
setSize(1F, 2F);
// TODO Auto-generated constructor stub
}
@Override
protected void entityInit() {
super.entityInit();
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
// Here we set various attributes for our mob. Like maximum health, armor, speed, ...
this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(50.0D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.5D);
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(0.0D);
this.getEntityAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(0.0D);
}
@Override
protected void initEntityAI() {
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(2, new EntityAILutinAttack(this, 1.0D, false));
this.tasks.addTask(5, new EntityAIMoveTowardsRestriction(this, 1.0D));
this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
this.tasks.addTask(8, new EntityAILookIdle(this));
this.applyEntityAI();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private void applyEntityAI() {
this.tasks.addTask(6, new EntityAIMoveThroughVillage(this, 1.0D, false));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
}
@Override
@Nullable
protected ResourceLocation getLootTable() {
return LOOT;
}
@Override
protected boolean isValidLightLevel() {
return true;
}
@Override
public int getMaxSpawnedInChunk() {
return 2;
}
}
ModEntites.class
package com.volbot.kone.ref;
import com.volbot.kone.Main;
import com.volbot.kone.mobs.EntityLutin;
import com.volbot.kone.mobs.RenderLutin;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Biomes;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.fml.client.registry.IRenderFactory;
import net.minecraftforge.fml.client.registry.RenderingRegistry;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ModEntities {
public static void init() {
// Every entity in our mod has an ID (local to this mod)
int id = 1;
EntityRegistry.registerModEntity(EntityLutin.LOOT, EntityLutin.class, "Lutin", id++, Main.instance, 64, 3, true, 0x996600, 0x00ff00);
// We want our mob to spawn in Plains and ice plains biomes. If you don't add this then it will not spawn automatically
// but you can of course still make it spawn manually
EntityRegistry.addSpawn(EntityLutin.class, 1, 0, 1, EnumCreatureType.AMBIENT, Biomes.BIRCH_FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.COLD_TAIGA, Biomes.COLD_TAIGA_HILLS, Biomes.DESERT, Biomes.DESERT_HILLS, Biomes.EXTREME_HILLS, Biomes.EXTREME_HILLS_WITH_TREES, Biomes.FOREST, Biomes.FOREST_HILLS, Biomes.HELL, Biomes.ICE_MOUNTAINS, Biomes.ICE_PLAINS, Biomes.JUNGLE, Biomes.JUNGLE_HILLS, Biomes.MESA, Biomes.MESA_ROCK, Biomes.MUSHROOM_ISLAND, Biomes.PLAINS, Biomes.REDWOOD_TAIGA, Biomes.REDWOOD_TAIGA_HILLS, Biomes.ROOFED_FOREST, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.SWAMPLAND, Biomes.TAIGA, Biomes.TAIGA_HILLS);
// This is the loot table for our mob
LootTableList.register(EntityLutin.LOOT);
}
@SideOnly(Side.CLIENT)
public static void initModels() {
RenderingRegistry.registerEntityRenderingHandler(EntityLutin.class, new IRenderFactory<EntityLutin>()
{
@Override
public Render<? super EntityLutin> createRenderFor(RenderManager manager)
{
return new RenderLutin(manager);
}
});
}
}
how do i make this text bold
The problem is that your entity is of type "EntityMob" (generally hostile mobs) but it is added to the "ambient" mob spawn list - which means that the ambient mob cap is not affected by your mob (which counts toward the hostile mob cap) so it will keep spawning as long as the cap is not reached (normally only bats occupy the ambient mob cap, and since they gradually despawn you mob will have opportunities to spawn even if it is otherwise full. Your mob appears to despawn as well since you don't override the default canDespawn() method but this does not happen that fast. A similar situation occurs with ocelots in vanilla, which spawn under the hostile mob cap but are passive so they do not count towards it, but ocelots have a very low probability of spawning relative to other hostile mobs, I've still seen the entity count in F3 exceed 300 in jungles where I lit up all the caves so they are the only mob that can spawn).
You'll either want to change the class of mob (to "EntityAmbientCreature") or the spawn list; mobs of type EntityMob also automatically despawn on Peaceful so you'll probably want to do the former if you want it to spawn on Peaceful (note that the type of mob does not determine its behavior, which is set by its AI; e.g. rabbits are based on EntityAnimal (generally passive and harmless) but killer rabbits have an attack AI function added to the default rabbit AI list; wolves are also "passive" but attack when provoked, and so on).
TheMasterCaver's First World - possibly the most caved-out world in Minecraft history - includes world download.
TheMasterCaver's World - my own version of Minecraft largely based on my views of how the game should have evolved since 1.6.4.
Why do I still play in 1.6.4?
Thank you, this worked!
how do i make this text bold