From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
Date: Tue, 20 Apr 2021 18:04:54 -0700
Subject: [PATCH] Do not schedule poi task for each block write on chunk gen

Most of the time optional == optional1, so we shouldn't
schedule a task for each write.

diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
index fcf9af44702f34d75185eee0b3259fe0e57001b1..e3481eb71972c82edd892a99d1136c8248fb0f8c 100644
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
@@ -2707,14 +2707,9 @@ public class WorldServer extends World implements GeneratorAccessSeed {
         Optional<VillagePlaceType> optional1 = VillagePlaceType.b(iblockdata1);
 
         // Paper start
-        BlockPosition blockposition1 = blockposition.immutableCopy();
-        this.getMinecraftServer().execute(() -> {
-                if (!optional.isPresent() && this.getPoiStorage().test(blockposition1, com.google.common.base.Predicates.alwaysTrue())) {
-                    this.getPoiStorage().remove(blockposition1);
-                }
-        });
+        // Tuinity - oh god not for each block set
         if (!Objects.equals(optional, optional1)) {
-            //BlockPosition blockposition1 = blockposition.immutableCopy();
+            BlockPosition blockposition1 = blockposition.immutableCopy(); // Tuinity - oh god not for each block set
             // Paper end
 
             optional.ifPresent((villageplacetype) -> {
@@ -2725,6 +2720,11 @@ public class WorldServer extends World implements GeneratorAccessSeed {
             });
             optional1.ifPresent((villageplacetype) -> {
                 this.getMinecraftServer().execute(() -> {
+                    // Tuinity start - remove POIs before inserting, better version of paper's diff
+                    if (!optional.isPresent() && this.getPoiStorage().test(blockposition1, com.google.common.base.Predicates.alwaysTrue())) {
+                        this.getPoiStorage().remove(blockposition1);
+                    }
+                    // Tuinity end - remove POIs before inserting, better version of paper's diff
                     this.y().a(blockposition1, villageplacetype);
                     PacketDebug.a(this, blockposition1);
                 });
