Jump to content

[Solved] Prevent entities de-spawning client-side


Recommended Posts

Posted

I have an entity that must be able to move away from a player without de-spawning (or stop ticking) client-side. Even though chucks are loaded, server-side and client-side, around that entity it still de-spawns around 150-200 block away from the player. 

 

It appears that the trackingRange in forge's entity tracker might be doing this. If I reduce it to 10 blocks, the entity will de-spawn 10 blocks away. I can't seem to go beyond 150-200 blocks regardless of what I set the tracking range to.

 

Is there a way to force an entity to stay loaded client-side? Any help will be appreciated.

Thanks

Posted

You are probably hitting on about 3-4 different issues simultaneously here.

 

One of them is render distance.  This can be set in the entity, through an overrided method.

 

A second is chunk-loading.  You will need to setup chunkloading for your entity if you want it to stay loaded past about ~140 blocks range.

 

The third is the update range--position/velocity update packets won't be sent to players beyond this range.

 

 

So, in order to make an entity persistent (and visible) you will need to set your render distance in the entity, setup chunkloading for your mod and register the entity to a chunk-ticket, and set the updateRange where you registered your entity up to the range you want it to update.

 

 

I had some missiles in my mod that I had to do this to, in order to make them continue flying at long range/explode on impact at any range > 140 blocks.  Works great now though.

Posted

One of them is render distance.  This can be set in the entity, through an overrided method.

 

A second is chunk-loading.  You will need to setup chunkloading for your entity if you want it to stay loaded past about ~140 blocks range.

 

The first two issues you have mentioned have been solved. I initially thought the problem was caused by chunks not loading on the client-side, but its not the case (Unless I'm doing it wrong).

 

The third is probably causing the problem, but even if I set the update range more than 150 the entity still de-spawns around 150.

Posted

try this:

 

in the onUpdate for your entity, have it output the distance to the closest player if it is on server side

if(!worldObj.isRemote)

{

//get closest player from world

if(player!=null)

{

//output distance from this.getDistanceToEntity(player)

}

 

}

 

if it stops outputting at a distance of 150'ish blocks, it is a chunkloading issue  (meaning you will need to use Forge's forced-chunk loading system)

 

if it continues outputting past 150'ish blocks, it is a render-distance or update distance issue.  (also render distance is given as a sqRt, so in order to render out to 250 blocks, needs to be set as 250*250)

 

Also, I dont' think chunks 'load client side' as you are thinking, or at least that has nothing to do with your entity being spawned/visible.  Most of the entity stuff is handled server side (entity updates)--pretty much only positioning and rendering is done client side.  So if the chunk is unloaded client-side, but still loaded server side, the entity will still update.  If a chunk is somehow loaded on client but not on server, it doesn't matter because the server won't be doing any updating to that chunk.

 

Anyhow..hope this helps..I know it took me a few days to sort over my chunkloading issues.

Posted

I'm using this to keep chunks loaded server-side. It might not be the best way to do it.

    	if(!worldObj.isRemote)
    	{
            
            for(int x = -2; x <= 2; x++)
            {
                for(int z = -2; z <= 2; z++)
                {             
                    worldObj.getChunkFromChunkCoords(this.chunkCoordX+ x, this.chunkCoordZ+ z);
                }
            }
        }

 

The onUpdate() will keep ticking server-side (or !worldObj.isremote) regardless of how far it is away from any player.

 

Posted

I do the same on the client-side to see if chunks are loader. Under worldObj.isremote.

 

worldObj.getChunkFromChunkCoords(this.chunkCoordX+ x, this.chunkCoordZ+ z).isChunkLoaded

 

If that returns false, the client will then send a custom packet to the server to send it a chunk.

Once the server has sent that chunk it becomes visible to the player. This chunk will appear on the client even if its more than 150 blocks away from the player.

 

I use a camera entity that spawns in client-side only that can allow a player to view any other entity away form the actual player.

 

So for instance if I have a plane that needs to fly way from the player, the camera entity will follow that plane. As you fly away chunks will load and appear around the plane. But once I get to ~150 blocks away from the player the plane disappears and stops ticking client-side (worldObj.isremote). It will still keep ticking on the server-side(!worldObj.isremote)

Posted

I've been able to track down the problem. The problem was in the EntityTracker class.

 

        if (par2 > this.entityViewDistance)
        {
            par2 = this.entityViewDistance;
        }

 

par2 is the tracking range you register your entity with. If the entityViewDistance is less than you tracking range your actual tracking range will be limited to the view distance.

 

By deleting this or change the entityViewDistance to more than 150, the entity will stay loaded on the client-side up to what ever distance you set it to.

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.