Jump to content

Trying to check if chunk is fully loaded (1.16.5)


InspectorCaracal

Recommended Posts

I know I said I didn't want to make a new thread, but it's still not working, so here we are.

I have an EntityJoinWorldEvent function. I'm trying to set it so that it has a check to make sure it's not while the chunk is loading. So far, everything I've tried has resulted in the game saying the chunk is loaded during the initial entering-the-game loading phase and then never getting past the 100% indicator.

This is what I currently have:

@SubscribeEvent
public static void beeSpawn(EntityJoinWorldEvent event) {
	if (event.getEntity() instanceof BeeEntity) {
		LOGGER.debug("It's a bee!");
		BeeEntity bee = (BeeEntity)event.getEntity();
		World world = event.getWorld();
		if (!world.isClientSide()) {
			LOGGER.debug("It's the server!");
			if (bee.hasHive()) {
				BlockPos hive_pos = bee.getHivePos();
				if (world.getChunkSource().getChunkNow(hive_pos.getX() >> 4, hive_pos.getY() >> 4) != null) {
					LOGGER.debug("Hive is loaded");
					Block hive_block =  world.getBlockState(hive_pos).getBlock();
					LOGGER.debug(hive_block.toString());
					if (hive_block instanceof BeehiveBlock) {
						BeehiveTileEntity hiveEntity = (BeehiveTileEntity)world.getBlockEntity(hive_pos);
						if (world.getBiome(hive_pos).getTemperature(hive_pos) < 0.95F) {
							LOGGER.debug("Bee attempted leaving the hive, but it's too cold.");
							hiveEntity.addOccupant(bee, false);
							event.setCanceled(true);
						}
					}
					
				} else {
					LOGGER.debug("Hive isn't loaded yet, ignoring");
				}
			} else {
				LOGGER.debug("Hiveless bee, ignoring");
			}
		}
	}
}

 

And this is what I get to console:

[20:10:42] [Server thread/INFO] [minecraft/MinecraftServer]: Preparing start region for dimension minecraft:overworld
[20:10:44] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 0%
[20:10:44] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 0%
[20:10:44] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 0%
[20:10:44] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 0%
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: It's a bee!
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: It's the server!
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: Hive isn't loaded yet, ignoring
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: It's a bee!
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: It's the server!
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: Hiveless bee, ignoring
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: It's a bee!
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: It's the server!
[20:10:44] [Server thread/DEBUG] [co.cl.be.ev.ModEvents/]: Hive is loaded
[20:10:47] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 83%
[20:10:47] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 83%
[20:10:47] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 83%
[20:10:47] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 83%
[20:10:47] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 83%
[20:10:47] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 95%
[20:10:48] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 95%
[20:10:48] [Render thread/INFO] [minecraft/LoggingChunkStatusListener]: Preparing spawn area: 96%

Aaaand then it just sits with the loading screen saying 100% forever. It's obviously getting stuck on "Block hive_block =  world.getBlockState(hive_pos).getBlock();" which I'm guessing is because it's trying to access block info while the chunk is loading and causing a deadlock, which means that this is still the wrong way to check if a chunk is fully loaded.

How do I fix this?

Link to comment
Share on other sites

8 hours ago, diesieben07 said:

Yes, EntityJoinWorldEvent is called during chunk loading. So if you try to access the chunk (which you do indirectly with getBlockState) then you have a deadlock, because the chunk can't be loaded until your event handler is completed, but your event handler is waiting for the chunk to be loaded.

From what I can tell the reason getChunkNow doesn't work for you here is that the chunk is already half-loaded (see ChunkStatus) and in this case getChunkNow does not bail out and return null, instead if waits for it to be fully loaded.

See ForgeInternalHandler for how Forge deals with this problem by delaying things by 1 tick.

I'll take a look, but does this mean there isn't anything that'll tell me if it's only half loaded? I was really aiming for not executing the code block during chunk loading as much as possible, but as far as I can tell, this is the event to use for bees exiting their hives so I have to account for chunk loading as well.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

I don't think so. Look at ForgeInternalHandler.

Ah, mild bummer. Yeah, I took a look at it, but I'm not at my dev machine right now so it'll be a few hours before I can try anything out.

In the meantime, though, I noticed the delayed executor uses addFreshEntity, which is the same method for bees leaving hives and has me questioning my entire event. I had assumed addFreshEntity triggers the onEntityJoinWorld event, but that makes ForgeInternalHandler look like it would just continually remove and recreate the entity every tick which is obviously not right. Does the executor not trigger events, or does addFreshEntity not count as an entity join event? If it's the latter, what does addFreshEntity trigger, because that's what I need to be using.

 

(Tangentially, I've been continually impressed by the scope of your knowledge of the code base and active presence on the forum, and I know that support work can feel incredibly thankless and exhausting so I wanted to mention that I really appreciate all the help!)

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

It only calls addFreshEntity if it cancels the event, meaning the original entity is not spawned.

Right, sorry, I wasn't clear.

What it looks like this does is, if the item has a custom entity, it cancels the spawn event and reschedules a new spawn event for the new entity. But I'd think that would then, on execution, trigger this event again, match the custom entity condition, cancel the spawn, reschedule, etc.

I know this isn't what it does and I'm probably missing something completely obvious, but I can't figure out how this doesn't just continually cancel and reschedule the entity spawn and I want to make sure I understand how it works before I try using parts of it myself.

Link to comment
Share on other sites

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I've been trying to make a mod pack for the last day or so now and I haven't been able to launch it once even with all mods disabled. It keeps showing up with Exit Code 1. I gave the modpack to a friend to try and it didn't launch on their pc either due to the same exit code, so I'm not entirely certain what the problem is or how to check it in the logs. So far I've attempted: - Changing from forge version 43.3.0 to 43.3.5 - Downloading Java - Disabling mods (both entirely and individually) I have an NVIDIA GeForce GTX 1070 driver, and I haven't tried to uninstall or reinstall it yet because I'm not certain how to and would have to mess anything up further. I have the latest .txt file of the crash report here: [16:24:34] [main/WARN]: Failed to add PDH Counter: \Paging File(_Total)\% Usage, Error code: 0xC0000BB8 [16:24:34] [main/WARN]: Failed to add counter for PDH counter: \Paging File(_Total)\% Usage [16:24:34] [main/WARN]: Disabling further attempts to query Paging File. [16:24:36] [main/WARN]: COM exception: Invalid Query: SELECT PERCENTUSAGE FROM Win32_PerfRawData_PerfOS_PagingFile [16:24:39] [Datafixer Bootstrap/INFO]: 198 Datafixer optimizations took 149 milliseconds [16:24:40] [Render thread/INFO]: Environment: Environment[sessionHost=https://sessionserver.mojang.com, servicesHost=https://api.minecraftservices.com, name=PROD] [16:24:40] [Render thread/INFO]: Setting user: CatDoodlee [16:24:41] [Render thread/INFO]: Backend library: LWJGL version 3.3.2+13 [16:24:42] [Render thread/INFO]: Reloading ResourceManager: vanilla [16:24:42] [Worker-Main-11/INFO]: Found unifont_all_no_pua-15.1.04.hex, loading [16:24:44] [Render thread/WARN]: Missing sound for event: minecraft:item.goat_horn.play [16:24:44] [Render thread/WARN]: Missing sound for event: minecraft:entity.goat.screaming.horn_break [16:24:44] [Render thread/INFO]: OpenAL initialized on device OpenAL Soft on Speakers (Atrix Wired Elite Headset) [16:24:44] [Render thread/INFO]: Sound engine started [16:24:44] [Render thread/INFO]: Created: 1024x512x4 minecraft:textures/atlas/blocks.png-atlas [16:24:44] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/signs.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/shield_patterns.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x512x4 minecraft:textures/atlas/banner_patterns.png-atlas [16:24:44] [Render thread/INFO]: Created: 1024x1024x4 minecraft:textures/atlas/armor_trims.png-atlas [16:24:44] [Render thread/INFO]: Created: 128x64x4 minecraft:textures/atlas/decorated_pot.png-atlas [16:24:44] [Render thread/INFO]: Created: 256x256x4 minecraft:textures/atlas/chest.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/shulker_boxes.png-atlas [16:24:44] [Render thread/INFO]: Created: 512x256x4 minecraft:textures/atlas/beds.png-atlas [16:24:45] [Render thread/WARN]: Shader rendertype_entity_translucent_emissive could not find sampler named Sampler2 in the specified shader program. [16:24:45] [Render thread/INFO]: Created: 512x256x0 minecraft:textures/atlas/particles.png-atlas [16:24:45] [Render thread/INFO]: Created: 256x256x0 minecraft:textures/atlas/paintings.png-atlas [16:24:45] [Render thread/INFO]: Created: 128x128x0 minecraft:textures/atlas/mob_effects.png-atlas [16:24:45] [Render thread/INFO]: Created: 1024x512x0 minecraft:textures/atlas/gui.png-atlas [16:25:41] [Render thread/INFO]: Stopping! any form of help is greatly appreciated ❤️
    • Tanks for answer, I added SleepTight and I removed Modernfix, but it still crashing: new log new crash log
    • Hi, I'm trying to hide specific vanilla effects such as levitation or slow falling from the inventory GUI, but I haven't been able to figure out how to do this. I need this because they are triggered by another effect and I don't need them all showing up. Unfortunately, I don't know of any mods that include this feature, and I couldn't find any documentation on the process. I've already looked into the IClientMobEffectExtensions interface, but I'm uncertain about how to implement it in my own effect, let alone in any existing vanilla effect. Please help I am using Forge 47.2.0. for Minecraft 1.20.1
    • Also wondering how to create these manually.  First time creating a forge server.
  • Topics

×
×
  • Create New...

Important Information

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