From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Sun, 23 Apr 2023 07:08:26 -0700
Subject: [PATCH] Block reading in-world tile entities on worldgen threads

The returned TE may be in the world, in which case it is unsafe
for the current thread to modify or access its contents.

diff --git a/net/minecraft/world/level/chunk/ImposterProtoChunk.java b/net/minecraft/world/level/chunk/ImposterProtoChunk.java
index 41856c98d97e7eb0782f8e441b9a269a47ed1914..606b07ae06166f954b6aaa39d56f024c7ad8611f 100644
--- a/net/minecraft/world/level/chunk/ImposterProtoChunk.java
+++ b/net/minecraft/world/level/chunk/ImposterProtoChunk.java
@@ -91,6 +91,11 @@ public class ImposterProtoChunk extends ProtoChunk implements ca.spottedleaf.moo
     @Nullable
     @Override
     public BlockEntity getBlockEntity(BlockPos pos) {
+        // Folia start - block reading possibly in-world block data for worldgen threads
+        if (!this.allowWrites && !ca.spottedleaf.moonrise.common.util.TickThread.isTickThread()) {
+            return null;
+        }
+        // Folia end - block reading possibly in-world block data for worldgen threads
         return this.wrapped.getBlockEntity(pos);
     }
 
