JayZX535 Posted June 4, 2020 Posted June 4, 2020 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. Quote
TheGreyGhost Posted June 4, 2020 Posted June 4, 2020 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 1 Quote
Novârch Posted June 4, 2020 Posted June 4, 2020 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. 1 Quote 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".
JayZX535 Posted June 5, 2020 Author Posted June 5, 2020 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! Quote
Recommended Posts
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.