Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

  • Author

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

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.