Jump to content

Recommended Posts

Posted

hi,  i have created an entity and now i want it to spawn only at night...

this is the code i use to spawn it:

 

ModLoader.addSpawn(EntityGlacialTurtle.class, 20, 2, 2, EnumCreatureType.monster, new BiomeGenBase[] {Glacia});

 

and this is my EntityGlacialTurtle.java

 

package net.minecraft.src;

import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIBreakDoor;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveThroughVillage;
import net.minecraft.entity.ai.EntityAIMoveTwardsRestriction;
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.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.entity.Entity;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLiving;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.item.ItemFood;

public class EntityGlacialTurtle extends EntityMob{

    public EntityGlacialTurtle(World var1)
    {
        super(var1);
        this.health = 10;
        
        this.texture = "/mob/Glacia/GlacialTurtle.png";
        this.moveSpeed = 1.0F;
        this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(4, new EntityAIMoveTwardsRestriction(this, this.moveSpeed));
        this.tasks.addTask(5, new EntityAIMoveThroughVillage(this, this.moveSpeed, false));
        this.tasks.addTask(6, new EntityAIWander(this, this.moveSpeed));
        this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(7, new EntityAILookIdle(this));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));
	this.setSize(0.9F, 1.3F);
    }

    public int getMaxHealth()
    {
        return 10;
    }

public boolean canBreatheUnderwater()
    {
        return true;
    }

    /**
     * Drop 0-2 items of this living's type
     */
    protected void dropFewItems(boolean var1, int var2)
    {
        this.entityDropItem(new ItemStack(mod_Glacia.SaberToothedCatMeat.itemID, 1, 0), 0.0F);
    }
    
    protected void dropRareDrop(int par1)
    {
        this.dropItem(mod_Glacia.SaberToothedCatMeat.itemID, 1);
    }
   
    /**
     * Returns the sound this mob makes while it's alive.
     */
    public String getLivingSound()
    {
        return "";
    }

    /**
     * Returns the sound this mob makes when it is hurt.
     */
    public String getHurtSound()
    {
        return "";
    }

    /**
     * Returns the sound this mob makes on death.
     */
    public String getDeathSound()
    {
        return "";
    }

    /**
     * Determines if an entity can be despawned, used on idle far away entities
     */
    protected boolean canDespawn()
    {
        return false;
    }
}

 

It works well, but i want to make it spawn only on night, how can i do?

Actually i don't know what to write in this signature soooo.... anyway

Posted

There is a method called something like isValidSpawn() in Entity. Use that (override it) and use the world to check the time of day.

 

thanx

Actually i don't know what to write in this signature soooo.... anyway

Posted

for all people want to know how to do it:

 

public boolean getCanSpawnHere()
{
         return !this.worldObj.isDaytime() && !this.worldObj.isRemote;
}

Actually i don't know what to write in this signature soooo.... anyway

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.