Jump to content

[1.14/1.15] Entities With Home Block and Unloading Chunks (the bee problem)


Recommended Posts

Posted

Hey all,

 

So I'm theorycrafting some of my mod mechanics and I think I want my entities to have a "home block"-- similar to how bees will try and return to their nest.  However, this brings up an interesting situation.  When I've played in 1.15, I've noticed my bees tend to wander off and disappear if not enclosed.  If I have a full hive, eventually some of the bees will just disappear-- and if I venture to chunks outside my usual travel range, all of a sudden there are a bunch of homeless bees.  I'm guessing this is because the bees fly off when I'm in the area, but then get stranded in unloaded chunks if I walk away.  I'd like to avoid this problem if at all possible, so I'm trying to figure out ways to do it.

 

My current idea is to catch the chunk unload event, scan for my entities, and, if found, warp them back to/closer to their home block.  This runs the risk of being a little janky, but if the player is far enough away from them to be unloading those chunks in the first place, I'm guessing it wouldn't be super noticeable?  Better yet, I could catch the unload event for the entities themselves, and use that as the warp trigger.

 

I don't know of any mods that do something like this off the top of my head, though, so I was curious as to its plausibility.  Is there anyone who's tried something like this before?  What events would I need to intercept?  Is there a good way to force a chunk to load temporarily (i.e. if the home chunk is already unloaded, make it load back in, warp the entities, and then let it unload once more)?  Is there anything else I should be aware of when considering this?

 

Thank you for your time, and have a great day.

Posted

Howdy

 

I'd suggest your entity unloading is the way to go - perhaps Entity.remove() or Entity.onRemovedFromWorld() override, perhaps you can mark the Entity in some way to kill it permanently, and respawn a new one to emerge from the hive.  Or after the entity unloads your hive block could track a virtual bee for a while and then respawn it with some logic to make it head towards the hive for a while.

 

I'm not sure that there is an "unload event", but perhaps PlayerEvent.StopTracking will work how you need.

 

I think the only way to make it truly seamless is to have a central bee controller instance which comes into existence whenever a hive or one of its bees loads.  Every few server ticks, the bee controller reviews its list of virtual bees, calculates their movement and location, and spawns or despawns them as necessary within a given radius of the player (eg the render distance).

Might not be worth the effort from a gameplay point of view.

 

-TGG

 

 

 

 

  • Like 1
Posted
On 5/20/2020 at 9:23 AM, diesieben07 said:

You should be able to abuse a fact of the capability system here.

Subscribe to AttachCapabilitiesEvent<Entity>. If the entity is one you want to track (presumably it's a living entity) then use AttachCapabilitiesEvent#addLIstener. The listener will be called when the entity is completely removed from the world. You'll also have to check if the entity actually died by some logic (this also fires when the entity despawns), so you might want to check it's health.

This method is probably not perfect, you can do some experimentation.

Maybe this'll help, thought of it immediately after seeing this.

  • Like 1

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Posted
On 6/4/2020 at 6:42 AM, TheGreyGhost said:

Howdy

 

I'd suggest your entity unloading is the way to go - perhaps Entity.remove() or Entity.onRemovedFromWorld() override, perhaps you can mark the Entity in some way to kill it permanently, and respawn a new one to emerge from the hive.  Or after the entity unloads your hive block could track a virtual bee for a while and then respawn it with some logic to make it head towards the hive for a while.

 

I'm not sure that there is an "unload event", but perhaps PlayerEvent.StopTracking will work how you need.

 

I think the only way to make it truly seamless is to have a central bee controller instance which comes into existence whenever a hive or one of its bees loads.  Every few server ticks, the bee controller reviews its list of virtual bees, calculates their movement and location, and spawns or despawns them as necessary within a given radius of the player (eg the render distance).

Might not be worth the effort from a gameplay point of view.

 

-TGG

Oooh, those first ideas seem pretty feasible.  There's code in the game that allows for "unnatural spawns" (i.e. interdimensional teleportation), so I might be able to utilize that to recall them.  Possibly implement a delay before respawning them, so they don't instantly warp... hmmm...

 

Though, I suppose that'd hinge on the hive itself being loaded.  Hmm.  Is there a way to load a certain chunk based off a block even when no players are near?  I know some mods have managed to make chunk loaders but I'm not sure of a good example offhand...

 

On 6/4/2020 at 7:23 AM, Novârch said:

Maybe this'll help, thought of it immediately after seeing this.

That's another good option!  I've definitely got some more direction now, so thank y'all for your help!

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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