Jump to content

Recommended Posts

Posted (edited)

I have an entity that uses world.isDaytime() to check whether it should despawn, however it does not seem to work since they despawn at night. 

From my entity class:

    public void onUpdate()
    {
        super.onUpdate();
        this.motionY *= 0.6000000238418579D;

        if(this.world.isDaytime())
        {
        	if(this.rand.nextInt(1000) == 0)
        	{
        		this.setDead();
        		System.out.println("despawn");
        	}
        }
    }

The console gets flooded with the test message "despawn" during night. Beds use the same boolean so it is clearly working...but not with this entity? 

 

SOLVED, solution by diesieben07:

it only works on the server side, added check for !this.world.isRemote

Edited by jt9
Posted

This is the only relevant piece of code in the entity class. Given that 

System.out.println("despawn");

is constantly being executed, it shows that the if statement isn't working correctly. I can see the mobs die as soon as I spawn them

Posted
6 minutes ago, diesieben07 said:

isDaytime only works on the server. You need to check if you are on the server before despawning anyways.

Oops! That makes sense. Fixed it, thanks :)

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.