Jump to content

[Solved][1.10] Chunk rendering problems


wesserboy

Recommended Posts

Hey everyone,

 

I am currently working on a block that, if the player stands on it, changes the POV to a remote location, which is determined by the block. To achieve this, i made a renderTick handler. Here i check if the player is on top of one of these blocks. if this is the case i change the position of the renderViewEntity in the phase.START, and set it back to the original values in the phase.END.

 

For locations that are close to the original location this works perfectly, however, when the location is further away i run into two problems:

 

1. The chunks at the remote location are partially/not rendered. I figured this was because the chunks weren't loaded on the client. I tried to check if they were loaded, and it turned out this was indeed not the case. However i can't seem to be able to force the client to load these chunks. So my first question is: How do i force the client to load (and render) these remote chunks?

 

2. When i step off of the block, the POV is restored. However depending on how far away the POV was replaced, the chunks at the original position are partially/not loaded. I thought these chunks maybe got unloaded because the player was located far away, but this wasn't the case. When i place/break a block (cause a block update) in one of these chunks, it re-renders. I tried to mark all chunks within the render distance dirty, but this didn't work. My second question is: What is causing this and/or how would i go about fixing this?

 

You can find my RenderTickHandler class here:

https://gist.github.com/wesserboy/71a7bc547ee8e1e58e8f76c15cdbb3c6

All relevant code should be in there. However if you feel like you need to see more/other code, be sure to let me know, and i will post it.

 

Any answers, clues, ideas, etc... is very much appreciated!  :)

 

Thank you!

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

You may be interested in Looking Glass

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I had stumbled upon looking glass before, but it seems this is only intended for locations in different dimensions. My block is limited to only the dimension the block is located in. He wrote a custom way to retrieve chunk data from the server (since vanilla doesn't support this for multiple dimensions), but i was kinda hoping to be able to use the vanilla way (Since i stick to the world the client is in already anyway).

 

I don't think he does any marking for re-rendering, since he doesn't move the vision of the actual client side player. I could be wrong though. I will browse through the code once more, to see if it might still be able to give me some clues :)

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

I don't think he does any marking for re-rendering, since he doesn't move the vision of the actual client side player. I could be wrong though.

 

Turns out I was wrong, he updates them when the client receives the chunk data. I looked which method he used to force a render update: markBlockRangeForRenderUpdate  (:o How did i miss that method... My brain must have been dead last night).

For people that are curious, i found it here:

https://github.com/XCompWiz/LookingGlass/blob/946429fc5e7c82393b23e43f1820104b75febbf9/src/main/java/com/xcompwiz/lookingglass/network/packet/PacketChunkInfo.java

 

Problem #2 is fixed now, the chunks re-render when the player steps off the block and it look fine.

 

The only problem that remains is problem #1: How do i force the client to load (and render) a chunk far away from the player?

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

LookingGlass had to be custom built to handle other dimensions, but it works just fine in a single dimension.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

LookingGlass had to be custom built to handle other dimensions, but it works just fine in a single dimension.

You have a valid point here  ;)

 

However, i couldn't find my answer in the LookingGlass source. I did find a (currently) half working solution:

I created a custom packet that the client can use to request a chunk from the server. I reply to this packet by sending a vanilla chunk packet back to the client. Here is the code i use for this packet:

@Override
public void handleServerSide(MessageChunkRequest message, EntityPlayer player) {
	if(player instanceof EntityPlayerMP){
		EntityPlayerMP playerMP = (EntityPlayerMP) player;
		if(playerMP.worldObj instanceof WorldServer){
			WorldServer world = (WorldServer) playerMP.worldObj;
			Chunk chunk = world.getChunkProvider().provideChunk(message.chunkX, message.chunkZ);
			Packet<?> packet = new SPacketChunkData(chunk, 65535);
			playerMP.connection.sendPacket(packet);
		}
	}

}

 

On flat worlds this works, however on non-flat worlds this causes a crash:

 

 

[22:54:22] [server thread/ERROR]: Encountered an unexpected exception

net.minecraft.util.ReportedException: Exception ticking world

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:778) ~[MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687) ~[MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?]

at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]

Caused by: java.lang.IllegalStateException: TickNextTick list out of synch

at net.minecraft.world.WorldServer.tickUpdates(WorldServer.java:728) ~[WorldServer.class:?]

at net.minecraft.world.WorldServer.tick(WorldServer.java:225) ~[WorldServer.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:772) ~[MinecraftServer.class:?]

... 4 more

[22:54:22] [server thread/ERROR]: This crash report has been saved to: /Users/**************/Dropbox/Minecraft Modding/In World Storage/run/./crash-reports/crash-2016-06-29_22.54.22-server.txt

[22:54:22] [server thread/INFO]: Stopping server

[22:54:22] [server thread/INFO]: Saving players

[22:54:22] [server thread/INFO]: Saving worlds

[22:54:22] [server thread/INFO]: Saving chunks for level 'Non flat'/Overworld

[22:54:22] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:649]: ---- Minecraft Crash Report ----

// There are four lights!

 

Time: 29-6-16 22:54

Description: Exception ticking world

 

java.lang.IllegalStateException: TickNextTick list out of synch

at net.minecraft.world.WorldServer.tickUpdates(WorldServer.java:728)

at net.minecraft.world.WorldServer.tick(WorldServer.java:225)

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:772)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536)

at java.lang.Thread.run(Thread.java:745)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Thread: Client thread

Stacktrace:

at net.minecraft.world.WorldServer.tickUpdates(WorldServer.java:728)

at net.minecraft.world.WorldServer.tick(WorldServer.java:225)

 

-- Affected level --

Details:

Level name: Non flat

All players: 1 total; [EntityPlayerMP['Player797'/103153, l='Non flat', x=-91,49, y=70,00, z=176,52]]

Chunk stats: ServerChunkCache: 1022 Drop: 0

Level seed: -1483418972719784436

Level generator: ID 00 - default, ver 1. Features enabled: true

Level generator options:

Level spawn location: World: (-68,64,210), Chunk: (at 12,4,2 in -5,13; contains blocks -80,0,208 to -65,255,223), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 1730 game time, 1730 day time

Level dimension: 0

Level storage version: 0x04ABD - Anvil

Level weather: Rain time: 35059 (now: false), thunder time: 117888 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true

Stacktrace:

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:772)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536)

at java.lang.Thread.run(Thread.java:745)

 

-- System Details --

Details:

Minecraft Version: 1.10

Operating System: Mac OS X (x86_64) version 10.11.4

Java Version: 1.8.0_91, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 545225648 bytes (519 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95

FML: MCP 9.32 Powered by Forge 12.18.0.1986 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAAAAAAAAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAAAAAAAAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.10-12.18.0.1986-1.10.0.jar)

UCHIJAAAAAAAAA Forge{12.18.0.1986} [Minecraft Forge] (forgeSrc-1.10-12.18.0.1986-1.10.0.jar)

UCHIJAAAAAAAAA inWorldStorage{1.0.0} [in World Storage] (bin)

Loaded coremods (and transformers):

Profiler Position: N/A (disabled)

Player Count: 1 / 8; [EntityPlayerMP['Player797'/103153, l='Non flat', x=-91,49, y=70,00, z=176,52]]

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge'

[22:54:22] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:649]: #@!@# Game crashed! Crash report saved to: #@!@# ./crash-reports/crash-2016-06-29_22.54.22-server.txt

[22:54:22] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.

[22:54:23] [server thread/INFO]: Saving chunks for level 'Non flat'/Nether

[22:54:23] [server thread/INFO]: Saving chunks for level 'Non flat'/The End

[22:54:24] [server thread/INFO] [FML]: Unloading dimension 0

[22:54:24] [server thread/INFO] [FML]: Unloading dimension -1

[22:54:24] [server thread/INFO] [FML]: Unloading dimension 1

[22:54:24] [server thread/INFO] [FML]: Applying holder lookups

[22:54:24] [server thread/INFO] [FML]: Holder lookups applied

[22:54:24] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.

[22:54:24] [Client thread/INFO] [FML]: Server terminated.

 

 

 

I have never encountered such a crash, but my guess is that the server is overloaded because of all the chunks i request. (most of which have not been generated yet). But if someone could confirm that this is indeed the case that would be nice. :)

 

I tried only requesting the next chunk when the previously requested one has arrived, but this doesn't help, which makes me think there might be another problem causing the crash...

 

Any help/tips are greatly appreciated.

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

While looking through the minecraft code i found there is one place where such an exception is thrown:

net.minecraft.server.MinecraftServer: line 776

It gets thrown when the WorldServer.tick() method fails.

 

This confirms my suspicion that I am indeed overloading the server (which causes a tick to fail).

 

I am confused however why balancing out the requests doesn't work. I think load balancing should fix problems regarding too heavy loads...

 

Anyone that can explain why balancing doesn't work, or point me in the right direction as to how i could fix this?

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

I wasn't able to solve the problems of the previous approach, so I am currently working on a new approach: (still to problem #1)

 

I am now creating a fake EntityPlayerMP, and put that one on the location the player should be looking. The packets sent to this fake version, i forward to the client of the original player.

 

The game crashes when i add my fake version to the PlayerChunkMap. It complains about a ConcurrentModificationException. This must be thread related (i think), I can't however seem to figure out which thread is (constantly?) reading the array of PlayerChunkMapEntries.

 

This is the crash log:

 

 

[18:16:57] [server thread/ERROR]: Encountered an unexpected exception

net.minecraft.util.ReportedException: Exception ticking world

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:778) ~[MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687) ~[MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) ~[integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536) [MinecraftServer.class:?]

at java.lang.Thread.run(Thread.java:745) [?:1.8.0_91]

Caused by: java.util.ConcurrentModificationException

at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966) ~[?:1.8.0_91]

at java.util.LinkedList$ListItr.remove(LinkedList.java:921) ~[?:1.8.0_91]

at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:180) ~[PlayerChunkMap.class:?]

at net.minecraft.world.WorldServer.tick(WorldServer.java:229) ~[WorldServer.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:772) ~[MinecraftServer.class:?]

... 4 more

[18:16:57] [server thread/ERROR]: This crash report has been saved to: /Users/**************/Dropbox/Minecraft Modding/In World Storage/run/./crash-reports/crash-2016-06-30_18.16.57-server.txt

[18:16:57] [server thread/INFO]: Stopping server

[18:16:57] [server thread/INFO]: Saving players

[18:16:57] [server thread/INFO]: Saving worlds

[18:16:57] [server thread/INFO]: Saving chunks for level 'New World flat 2.0'/Overworld

[18:16:57] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:649]: ---- Minecraft Crash Report ----

// Don't be sad, have a hug! <3

 

Time: 30-6-16 18:16

Description: Exception ticking world

 

java.util.ConcurrentModificationException

at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966)

at java.util.LinkedList$ListItr.remove(LinkedList.java:921)

at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:180)

at net.minecraft.world.WorldServer.tick(WorldServer.java:229)

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:772)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536)

at java.lang.Thread.run(Thread.java:745)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Thread: Client thread

Stacktrace:

at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966)

at java.util.LinkedList$ListItr.remove(LinkedList.java:921)

at net.minecraft.server.management.PlayerChunkMap.tick(PlayerChunkMap.java:180)

at net.minecraft.world.WorldServer.tick(WorldServer.java:229)

 

-- Affected level --

Details:

Level name: New World flat 2.0

All players: 1 total; [EntityPlayerMP['Player785'/0, l='New World flat 2.0', x=1287,51, y=56,00, z=-401,02]]

Chunk stats: ServerChunkCache: 1211 Drop: 0

Level seed: 4472399697343842144

Level generator: ID 01 - flat, ver 0. Features enabled: true

Level generator options: 3;minecraft:bedrock,3*minecraft:stone,52*minecraft:sandstone;2;

Level spawn location: World: (1295,4,-395), Chunk: (at 15,0,5 in 80,-25; contains blocks 1280,0,-400 to 1295,255,-385), Region: (2,-1; contains chunks 64,-32 to 95,-1, blocks 1024,0,-512 to 1535,255,-1)

Level time: 611 game time, 611 day time

Level dimension: 0

Level storage version: 0x04ABD - Anvil

Level weather: Rain time: 145357 (now: false), thunder time: 77069 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true

Stacktrace:

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:772)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:687)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:536)

at java.lang.Thread.run(Thread.java:745)

 

-- System Details --

Details:

Minecraft Version: 1.10

Operating System: Mac OS X (x86_64) version 10.11.4

Java Version: 1.8.0_91, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 692271472 bytes (660 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0

FML: MCP 9.32 Powered by Forge 12.18.0.1986 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAAAA mcp{9.19} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAAAA FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.10-12.18.0.1986-1.10.0.jar)

UCHIJAAAA Forge{12.18.0.1986} [Minecraft Forge] (forgeSrc-1.10-12.18.0.1986-1.10.0.jar)

UCHIJAAAA inWorldStorage{1.0.0} [in World Storage] (bin)

Loaded coremods (and transformers):

Profiler Position: N/A (disabled)

Player Count: 1 / 8; [EntityPlayerMP['Player785'/0, l='New World flat 2.0', x=1287,51, y=56,00, z=-401,02]]

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge'

[18:16:57] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:649]: #@!@# Game crashed! Crash report saved to: #@!@# ./crash-reports/crash-2016-06-30_18.16.57-server.txt

[18:16:57] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.

[18:16:59] [server thread/INFO]: Saving chunks for level 'New World flat 2.0'/Nether

[18:16:59] [server thread/INFO]: Saving chunks for level 'New World flat 2.0'/The End

[18:17:00] [server thread/INFO] [FML]: Unloading dimension 0

[18:17:00] [server thread/INFO] [FML]: Unloading dimension -1

[18:17:00] [server thread/INFO] [FML]: Unloading dimension 1

[18:17:00] [server thread/INFO] [FML]: Applying holder lookups

[18:17:00] [server thread/INFO] [FML]: Holder lookups applied

[18:17:00] [server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.

[18:17:00] [Client thread/INFO] [FML]: Server terminated.

 

 

 

If additional code is required i will provide it.

Any information regarding the crash, or this problem in general would be nice, since I am really stuck on this one  :-\

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

I figured out the problem and it works now. I do however feel like there must be a better way to solve this.

I will explain what was causing the crash, and what i did to fix it.

I would like to hear any recommendations/ideas on how to improve it, if you have any.  ;)

 

The cause:

The crash was a ConcurrentModificationException. There were two threads modifying the same List simultaneously:

* The thread handling my packet was adding the fake player to the list.

* The server thread was checking the chunks around the players in this list in order to tick them, send updates to clients etc...

When these two operations happend at the same time --> ConcurrentModificationException.

 

The fix:

When the message is received (On the server), I subscribe it to the TickEvent.ServerTickEvent. I use the different phases of this event to monitor the tick progress, and i schedule the insertion of the fake player in between two ticks. (After Phase.END and before the next Phase.START)

 

Fields of improvement:

1. I feel like there should be a better way of loading distant chunks altogether. Inserting fake players and rerouting vanilla packets feel really hacky, and i can't imagine this being the first situation where distant chunks are needed on the client.

 

2. I think there must be a better way to schedule tasks in between ticks. Vanilla minecraft also has to insert the player into this list when it spawns a new player. This (obviously) doesn't cause a crash, so a mechanism to handle this must already be in place. (at least, I would think) EDIT: Has been improved, now uses a mechanic that is already present in vanilla

 

3. Possibly other things I haven't thought of yet  :)

 

 

As mentioned before, any feedback is greatly appreciated, since I am not yet fully convinced of the effectiveness of my current approach.

thank you for your interest  ;)

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

Link to comment
Share on other sites

Your packet handlers should use the existing

IThreadListener

API to schedule a task that runs on the main thread and does whatever the packet is supposed to do. The Simple Network Implementation documentation explains how to do this.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Your packet handlers should use the existing

IThreadListener

API to schedule a task that runs on the main thread and does whatever the packet is supposed to do. The Simple Network Implementation documentation explains how to do this.

 

Thank you! I implemented it, and it works like a charm.

It is probably also way more reliable than my tick-handler magic  ;)

I made the Mob Particles mod, you can check it out here: http://www.minecraftforum.net/topic/2709242-172-forge-mob-particles/

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.

Announcements



×
×
  • Create New...

Important Information

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