Jump to content

[1.8]Mob only spawns near player spawn


TheFakeMarkTwain

Recommended Posts

Hey, I've got this weird issue where my mob won't spawn outside in the world, and only near the player's entry point to the world.

 

Spawn/Entity code (located in init method)

EntityRegistry.registerModEntity(EntityMimic.class, "rpgMimic", ENTITY_MIMIC_ID, BrightRPG.instance, 80, 1, true);
	EntityRegistry.addSpawn(EntityMimic.class, 85, 3, 7, EnumCreatureType.CREATURE,
			BiomeGenBase.desert,  BiomeGenBase.beach, BiomeGenBase.birchForest, BiomeGenBase.birchForestHills, BiomeGenBase.desertHills, BiomeGenBase.extremeHills,
			BiomeGenBase.extremeHillsEdge, BiomeGenBase.extremeHillsPlus, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.jungle, BiomeGenBase.jungleEdge,
			BiomeGenBase.jungleHills, BiomeGenBase.mesa, BiomeGenBase.mesaPlateau, BiomeGenBase.mesaPlateau_F, BiomeGenBase.plains,
			BiomeGenBase.river, BiomeGenBase.roofedForest, BiomeGenBase.savanna, BiomeGenBase.savannaPlateau);
	EntityList.addMapping(EntityMimic.class, "rpgMimic", 205, 113213, 3523523);

 

Link to comment
Share on other sites

Here it is:

@Override
public boolean getCanSpawnHere()
{
	return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL;
}

 

I changed the frequency to 3 and they still would only spawn near the world entrance. Also, why is 205 taken? When I changed it to a final int, I set it at 400, nothing spawned at all.

Link to comment
Share on other sites

Vanilla global entity IDs only go up to 255, which is why it is HIGHLY recommended NOT to use them, and use only the registerModEntity. In 1.8, you don't need to manually add mappings like that anymore to get a spawn egg, you can use instead EntityRegister#registerEgg.

 

The frequency I mentioned is not related to spawn rate, just something I see all the time that is probably not very good to do.

 

Put some println statements in your mob's onInitialSpawn method and see if that is getting called. Also, you probably want to call super.getCanSpawnHere() - the super methods generally have useful checks, depending on what class your mob extends.

 

 

Link to comment
Share on other sites

So I changed the registry to this:

int id = 600;

	EntityRegistry.registerModEntity(EntityMimic.class, "rpgMimic", BrightRPG.ENTITY_MIMIC_ID, BrightRPG.instance, 80, 3, true);
	EntityRegistry.addSpawn(EntityMimic.class, 85, 3, 7, EnumCreatureType.CREATURE,
			BiomeGenBase.desert,  BiomeGenBase.beach, BiomeGenBase.birchForest, BiomeGenBase.birchForestHills, BiomeGenBase.desertHills, BiomeGenBase.extremeHills,
			BiomeGenBase.extremeHillsEdge, BiomeGenBase.extremeHillsPlus, BiomeGenBase.forest, BiomeGenBase.forestHills, BiomeGenBase.jungle, BiomeGenBase.jungleEdge,
			BiomeGenBase.jungleHills, BiomeGenBase.mesa, BiomeGenBase.mesaPlateau, BiomeGenBase.mesaPlateau_F, BiomeGenBase.plains,
			BiomeGenBase.river, BiomeGenBase.roofedForest, BiomeGenBase.savanna, BiomeGenBase.savannaPlateau);

	EntityList.idToClassMapping.put(id, EntityMimic.class);
	EntityList.entityEggs.put(id, new EntityEggInfo(id, 113213, 3523523));

	id++;

 

I did some more experimenting and it seems that they'll just despawn as soon as I look away. I also can't find the onInitialSpawn method in EntityMob, EntityCreature, EntityLiving or EntityLivingBase.

Link to comment
Share on other sites

I'll update MCP in a sec, here's the entity code. It's pretty barebones right now:

package twain.brightRPG.entity;

import java.util.UUID;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
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.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import twain.brightRPG.BrightRPG;

public class EntityMimic extends EntityMob
{
private UUID field_175459_bn;

public EntityMimic(World par1World)
{
	super(par1World);
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(1, new EntityAIAttackOnCollide(this, EntityPlayer.class, 0.6D, false));
	this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityVillager.class, 0.6D, true));
	this.tasks.addTask(3, new EntityAIMoveTowardsRestriction(this, 1.0D));
	this.tasks.addTask(4, new EntityAIMoveThroughVillage(this, 0.6D, true));
	this.tasks.addTask(5, new EntityAIWander(this, 0.6D));
	this.tasks.addTask(6, new EntityAIWatchClosest(this, EntityPlayer.class, 7.0F));
	this.tasks.addTask(7, new EntityAILookIdle(this));
	this.targetTasks.addTask(0, new EntityAIHurtByTarget(this, true));

	this.setSize(0.6F, 1.8F);
}

@Override
protected void applyEntityAttributes()
{
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);;
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.6D);
	this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D);
}

@Override
protected String getLivingSound()
{
	return null;
}

@Override
protected String getHurtSound()
{
	return "brightRPG:mimicHurt";
}

@Override
protected String getDeathSound()
{
	return "brightRPG:mimicDeath";
}

@Override
protected float getSoundVolume()
{
	return 0.4F;
}

@Override
public void setRevengeTarget(EntityLivingBase livingBase)
{
	super.setRevengeTarget(livingBase);

	if (livingBase != null)
	{
		this.field_175459_bn = livingBase.getUniqueID();
	}
}

@Override
public boolean getCanSpawnHere()
{
	return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL && super.getCanSpawnHere();
}
}

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.