Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into dev/threaded-worldgen

This commit is contained in:
Simon Gardling 2021-04-22 17:07:43 -04:00
commit 8e6a62ab90
18 changed files with 253 additions and 257 deletions

View File

@ -437,8 +437,6 @@ This is an overview over all patches that are currently used.
| server | dont load chunks for physics | Aikar | |
| server | fixup! Threaded WorldGen | ishland | |
| server | fixup! Threaded WorldGen | ishland | |
| server | lithium AI | JellySquid | Hugo Planque |
| server | lithium AI fixup: use vanilla method for getClosestEntity | Simon Gardling | |
| server | lithium DataTrackerMixin | JellySquid | tr7zw |
| server | lithium HashedList | JellySquid | |
| server | lithium MixinBox | JellySquid | |

View File

@ -6,21 +6,20 @@ Subject: [PATCH] lithium entity
Co-authored-by: Hugo Planque <hookwood01@gmail.com>
diff --git a/src/main/java/net/minecraft/world/entity/EntityLiving.java b/src/main/java/net/minecraft/world/entity/EntityLiving.java
index a897ad3de8c18be8bb3c320950a7421477040e8a..a182cb8d641dbf8756267901a682f8e3e2a4c67c 100644
index a057be22f488f76b926c81dc5c63e7f9c3fb54a1..45924c33b2928e25dedaae22d06f2a7a181ead25 100644
--- a/src/main/java/net/minecraft/world/entity/EntityLiving.java
+++ b/src/main/java/net/minecraft/world/entity/EntityLiving.java
@@ -286,6 +286,10 @@ public abstract class EntityLiving extends Entity {
public NearbyEntityListenerMulti getListener() {
return this.tracker;
@@ -279,6 +279,9 @@ public abstract class EntityLiving extends Entity {
this.bg = this.a(new Dynamic(dynamicopsnbt, dynamicopsnbt.createMap((Map) ImmutableMap.of(dynamicopsnbt.createString("memories"), dynamicopsnbt.emptyMap()))));
}
+
+ private IBlockData lastStateAtFeet = null;
+
+ private long lastPos = Long.MIN_VALUE;
// Yatopia end
protected void initAttributes() {} // Purpur
@@ -363,6 +367,10 @@ public abstract class EntityLiving extends Entity {
public BehaviorController<?> getBehaviorController() {
@@ -355,6 +358,10 @@ public abstract class EntityLiving extends Entity {
@Override
public void entityBaseTick() {
@ -31,7 +30,7 @@ index a897ad3de8c18be8bb3c320950a7421477040e8a..a182cb8d641dbf8756267901a682f8e3
this.ar = this.as;
if (this.justCreated) {
this.getBedPosition().ifPresent(this::a);
@@ -1783,7 +1791,24 @@ public abstract class EntityLiving extends Entity {
@@ -1775,7 +1782,24 @@ public abstract class EntityLiving extends Entity {
}
public IBlockData ds() {

View File

@ -270,10 +270,10 @@ index b95115aca72ba0cf6451096ddbd8b50a8f3bb5c6..0afb8c643cb3e5938e12183c6132797d
int j = i - 1;
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 7befe4263a2d046922438e1a9853f2d8290ee230..ab5fb00885d22126639e7459ef71c56be4b5eb9e 100644
index cd1f94e5c1c923ee9d8dd451406ac2bee360e9c3..8735735eb116382b21b6751108629acb9411d332 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2647,6 +2647,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
@@ -2646,6 +2646,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
return this.isSneaking();
}
@ -282,18 +282,18 @@ index 7befe4263a2d046922438e1a9853f2d8290ee230..ab5fb00885d22126639e7459ef71c56b
return this.isSneaking();
}
diff --git a/src/main/java/net/minecraft/world/level/block/Block.java b/src/main/java/net/minecraft/world/level/block/Block.java
index 20c2c05ab09ac3f2b2924f2b5bc938fdc5cdd32e..e0d2d2f617594674824cdff34cdcfadaa16ac291 100644
index fab55929f72c5784291b3bc87f7717ac24b7806f..024b1c8939a93e2802ea53eefc49dda182412f28 100644
--- a/src/main/java/net/minecraft/world/level/block/Block.java
+++ b/src/main/java/net/minecraft/world/level/block/Block.java
@@ -56,6 +56,7 @@ import net.minecraft.world.phys.shapes.VoxelShapes;
@@ -55,6 +55,7 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapes;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import me.jellysquid.mods.lithium.common.ai.pathing.PathNodeDefaults;
+import me.jellysquid.mods.lithium.common.util.collections.Object2BooleanCacheTable;
public class Block extends BlockBase implements IMaterial {
@@ -229,8 +230,14 @@ public class Block extends BlockBase implements IMaterial {
@@ -217,8 +218,14 @@ public class Block extends BlockBase implements IMaterial {
return a(voxelshape1);
}

View File

@ -621,13 +621,13 @@ index 0000000000000000000000000000000000000000..4e765ab19ffb300b6c810333b2dc7976
+}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/world/level/World.java b/src/main/java/net/minecraft/world/level/World.java
index db2b1863b7f46be53839fb3e86870745fb7567fd..8cecf61169d28b7ddb8e1af180ac8bc0e5fef324 100644
index f5badbe0dee5c40cf83a5d2993d27ed70ddd2c85..a23c5172857a003b546e33d2935492e3260be560 100644
--- a/src/main/java/net/minecraft/world/level/World.java
+++ b/src/main/java/net/minecraft/world/level/World.java
@@ -98,8 +98,11 @@ import org.bukkit.event.block.BlockPhysicsEvent;
@@ -97,8 +97,11 @@ import org.bukkit.event.block.BlockPhysicsEvent;
// CraftBukkit end
import net.gegy1000.tictacs.NonBlockingWorldAccess; // Yatopia
import me.jellysquid.mods.lithium.common.entity.tracker.EntityTrackerEngine; // Yatopia
+import me.jellysquid.mods.lithium.common.util.collections.MaskedTickingBlockEntityList; // Yatopia
+import me.jellysquid.mods.lithium.common.world.blockentity.BlockEntitySleepTracker; // Yatopia
+import me.jellysquid.mods.lithium.common.world.blockentity.SleepingBlockEntity; // Yatopia
@ -637,7 +637,7 @@ index db2b1863b7f46be53839fb3e86870745fb7567fd..8cecf61169d28b7ddb8e1af180ac8bc0
protected static final Logger LOGGER = LogManager.getLogger();
public static final Codec<ResourceKey<World>> f = MinecraftKey.a.xmap(ResourceKey.b(IRegistry.L), ResourceKey::a);
@@ -108,9 +111,17 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
@@ -107,9 +110,17 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
public static final ResourceKey<World> THE_END = ResourceKey.a(IRegistry.L, new MinecraftKey("the_end"));
private static final EnumDirection[] a = EnumDirection.values();
//public final List<TileEntity> tileEntityList = Lists.newArrayList(); // Paper - remove unused list
@ -656,16 +656,16 @@ index db2b1863b7f46be53839fb3e86870745fb7567fd..8cecf61169d28b7ddb8e1af180ac8bc0
public final Thread serverThread;
private final boolean debugWorld;
private int d;
@@ -371,6 +382,8 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
@@ -368,6 +379,8 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
this.keepSpawnInMemory = this.paperConfig.keepSpawnInMemory; // Paper
this.entityLimiter = new org.spigotmc.TickLimiter(spigotConfig.entityMaxTickTime);
this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime);
this.tracker = new EntityTrackerEngine(); // Yatopia - Port lithium
+ this.tileEntityListTick$lithium = new MaskedTickingBlockEntityList<>(this.tileEntityListTick, blockEntity -> ((SleepingBlockEntity) blockEntity).canTickOnSide(false)); // Yatopia
+ this.tileEntityListTick = tileEntityListTick$lithium; // Yatopia
}
// Yatopia start - Port lithium
@@ -1041,6 +1054,15 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
// Paper start
@@ -1032,6 +1045,15 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
}
@ -681,7 +681,7 @@ index db2b1863b7f46be53839fb3e86870745fb7567fd..8cecf61169d28b7ddb8e1af180ac8bc0
public void tickBlockEntities() {
GameProfilerFiller gameprofilerfiller = this.getMethodProfiler();
@@ -1063,11 +1085,19 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
@@ -1054,11 +1076,19 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
this.tickingTileEntities = true;
// Spigot start
@ -701,7 +701,7 @@ index db2b1863b7f46be53839fb3e86870745fb7567fd..8cecf61169d28b7ddb8e1af180ac8bc0
// Spigot start
if (tileentity == null) {
getServer().getLogger().severe("Spigot has detected a null entity and has removed it, preventing a crash");
@@ -1105,8 +1135,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
@@ -1096,8 +1126,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
throwable.printStackTrace();
getServer().getPluginManager().callEvent(new ServerExceptionEvent(new ServerInternalException(msg, throwable)));
// Paper end
@ -711,7 +711,7 @@ index db2b1863b7f46be53839fb3e86870745fb7567fd..8cecf61169d28b7ddb8e1af180ac8bc0
continue;
// Paper end
// Spigot start
@@ -1119,8 +1148,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
@@ -1110,8 +1139,7 @@ public abstract class World implements GeneratorAccess, AutoCloseable, NonBlocki
if (tileentity.isRemoved()) {
// Spigot start

View File

@ -174,10 +174,10 @@ index 0b9ed4042612f5242e5b2d057b716170f22c78b1..0a2edb9ac73ed71e67833f17824d3be5
return CompletableFuture.completedFuture(either);
}, this.mainInvokingExecutor);
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
index e6f85b07f731859c8b8c380afad699ccc1d6c3e8..113f3395fdf99e505750352f9b2851582731cc99 100644
index d7f95bd32842fdee0ce53fc97d31ffb3577cdc78..e2952e889ed40b5eea3971321dc11b10840166d5 100644
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
@@ -2791,14 +2791,13 @@ public class WorldServer extends World implements GeneratorAccessSeed, NonBlocki
@@ -2780,14 +2780,13 @@ public class WorldServer extends World implements GeneratorAccessSeed, NonBlocki
BlockPosition blockposition1 = blockposition.immutableCopy(); // Tuinity - oh god not for each block set
// Paper end
@ -194,7 +194,7 @@ index e6f85b07f731859c8b8c380afad699ccc1d6c3e8..113f3395fdf99e505750352f9b285158
// 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);
@@ -2806,8 +2805,9 @@ public class WorldServer extends World implements GeneratorAccessSeed, NonBlocki
@@ -2795,8 +2794,9 @@ public class WorldServer extends World implements GeneratorAccessSeed, NonBlocki
// Tuinity end - remove POIs before inserting, better version of paper's diff
this.y().a(blockposition1, villageplacetype);
PacketDebug.a(this, blockposition1);

View File

@ -261,10 +261,10 @@ index 0a2edb9ac73ed71e67833f17824d3be5909e3445..8f6feff0680a59223444141eb646410f
this.world, chunkcoordintpair.x, chunkcoordintpair.z, null, nbttagcompound,
com.destroystokyo.paper.io.PrioritizedTaskQueue.NORMAL_PRIORITY); // Tuinity - writes are async, no need for priority
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
index 7dcd055b37bb7051127e10f5d191d23e0562b29e..308bc6ea4cb2ffaa3ab2ac7ce9863320980cd242 100644
index 29cd71efe86eea2227f373c15c39dc530e9e8199..55d497f4305de50e58c7e0788724576f81128138 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
@@ -547,7 +547,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
@@ -504,7 +504,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
@javax.annotation.Nullable
@Override
public NBTTagCompound read(ChunkCoordIntPair chunkcoordintpair) throws java.io.IOException {
@ -273,7 +273,7 @@ index 7dcd055b37bb7051127e10f5d191d23e0562b29e..308bc6ea4cb2ffaa3ab2ac7ce9863320
NBTTagCompound ret = com.destroystokyo.paper.io.PaperFileIOThread.Holder.INSTANCE
.loadChunkDataAsyncFuture(this.world, chunkcoordintpair.x, chunkcoordintpair.z, com.destroystokyo.paper.io.IOUtil.getPriorityForCurrentThread(),
true, false, true).join().poiData;
@@ -562,7 +562,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
@@ -519,7 +519,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
@Override
public void write(ChunkCoordIntPair chunkcoordintpair, NBTTagCompound nbttagcompound) throws java.io.IOException {

View File

@ -0,0 +1,188 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Fri, 5 Feb 2021 23:13:42 +0800
Subject: [PATCH] fixup! Threaded WorldGen
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunk.java b/src/main/java/net/minecraft/server/level/PlayerChunk.java
index 86f156587a0939b28c5cf6f64907255c1c4f8b35..716ddfb456dbb4c84e8e9c09728e7c28b5f4cff2 100644
--- a/src/main/java/net/minecraft/server/level/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/level/PlayerChunk.java
@@ -586,6 +586,7 @@ public class PlayerChunk {
return this.ticketLevel;
}
+ public int getPriority() { return k(); } // Yatopia - OBFHELPER
public int k() {
return this.n;
}
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
index 8f6feff0680a59223444141eb646410f7effc272..8c9ac2145fa9c4e23d8723764dd361cc2440d059 100644
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
@@ -1245,9 +1245,9 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
if (!com.tuinity.tuinity.config.TuinityConfig.useNewLightEngine && chunkstatus == ChunkStatus.LIGHT) { // Tuinity - we use edge checks, so loading 1 radius neighbours isn't necessary
completablefuture1 = this.b(playerchunk, chunkstatus);
} else {
- completablefuture1 = chunkstatus.a(this.world, this.definedStructureManager, this.lightEngine, (ichunkaccess1) -> {
+ completablefuture1 = chunkstatus.runLoadTask(this.world, this.definedStructureManager, this.lightEngine, (ichunkaccess1) -> { // Yatopia
return this.c(playerchunk);
- }, ichunkaccess);
+ }, ichunkaccess, playerchunk.getPriority()); // Yatopia
}
this.worldLoadListener.a(chunkcoordintpair, chunkstatus);
@@ -1358,9 +1358,9 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
return completablefuture.thenComposeAsync((either) -> {
return either.map((list) -> { // Paper - Shut up.
try {
- CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture1 = chunkstatus.a(this.world, this.chunkGenerator, this.definedStructureManager, this.lightEngine, (ichunkaccess) -> {
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture1 = chunkstatus.runGenerationTask(this.world, this.chunkGenerator, this.definedStructureManager, this.lightEngine, (ichunkaccess) -> {
return this.c(playerchunk);
- }, list);
+ }, list, playerchunk.getPriority());
this.worldLoadListener.a(chunkcoordintpair, chunkstatus);
return completablefuture1;
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java b/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
index a01d6dfe147383242e514d2807558bf94ff8865a..b33dd2602c592f0ed5d45d0a5a1ec87f6904aaed 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
@@ -69,7 +69,7 @@ public class ChunkStatus {
private static final EnumSet<HeightMap.Type> n = EnumSet.of(HeightMap.Type.OCEAN_FLOOR_WG, HeightMap.Type.WORLD_SURFACE_WG);
private static final EnumSet<HeightMap.Type> o = EnumSet.of(HeightMap.Type.OCEAN_FLOOR, HeightMap.Type.WORLD_SURFACE, HeightMap.Type.MOTION_BLOCKING, HeightMap.Type.MOTION_BLOCKING_NO_LEAVES);
- private static final ChunkStatus.c p = (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess) -> {
+ private static final ChunkStatus.c p = (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, priority) -> { // Yatopia
if (ichunkaccess instanceof ProtoChunk && !ichunkaccess.getChunkStatus().b(chunkstatus)) {
((ProtoChunk) ichunkaccess).a(chunkstatus);
}
@@ -78,14 +78,14 @@ public class ChunkStatus {
};
public static final ChunkStatus EMPTY = a("empty", (ChunkStatus) null, -1, ChunkStatus.n, ChunkStatus.Type.PROTOCHUNK, (worldserver, chunkgenerator, list, ichunkaccess) -> {
});
- public static final ChunkStatus STRUCTURE_STARTS = a("structure_starts", ChunkStatus.EMPTY, 0, ChunkStatus.n, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
+ public static final ChunkStatus STRUCTURE_STARTS = a("structure_starts", ChunkStatus.EMPTY, 0, ChunkStatus.n, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, priority) -> { // Yatopia
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> result = CompletableFuture.completedFuture(Either.left(ichunkaccess));
if (!ichunkaccess.getChunkStatus().b(chunkstatus)) {
if (worldserver.worldDataServer.getGeneratorSettings().shouldGenerateMapFeatures()) { // CraftBukkit
result = CompletableFuture.supplyAsync(() -> {
chunkgenerator.createStructures(worldserver.r(), worldserver.getStructureManager(), ichunkaccess, definedstructuremanager, worldserver.getSeed());
return Either.left(ichunkaccess);
- }, command -> worldGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : 0, command)));
+ }, command -> worldGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : priority, command)));
}
if (ichunkaccess instanceof ProtoChunk) {
result.thenRun(() -> ((ProtoChunk) ichunkaccess).a(chunkstatus));
@@ -116,7 +116,7 @@ public class ChunkStatus {
public static final ChunkStatus LIQUID_CARVERS = a("liquid_carvers", ChunkStatus.CARVERS, 0, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (worldserver, chunkgenerator, list, ichunkaccess) -> {
chunkgenerator.doCarving(worldserver.getSeed(), worldserver.d(), ichunkaccess, WorldGenStage.Features.LIQUID);
});
- public static final ChunkStatus FEATURES = a("features", ChunkStatus.LIQUID_CARVERS, 8, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
+ public static final ChunkStatus FEATURES = a("features", ChunkStatus.LIQUID_CARVERS, 8, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, priority) -> { // Yatopia
// Yatopia start - threaded WorldGen
return chunkgenerator.featureGenLock.acquireLock().toCompletableFuture().thenComposeAsync(token -> {
try {
@@ -135,12 +135,12 @@ public class ChunkStatus {
}
return CompletableFuture.completedFuture(Either.left(ichunkaccess));
- }, command -> featureGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : 0, command)));
+ }, command -> featureGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : priority, command)));
// Yatopia end
});
- public static final ChunkStatus LIGHT = a("light", ChunkStatus.FEATURES, 1, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
+ public static final ChunkStatus LIGHT = a("light", ChunkStatus.FEATURES, 1, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, priority) -> { // Yatopia
return a(chunkstatus, lightenginethreaded, ichunkaccess);
- }, (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess) -> {
+ }, (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, priority) -> { // Yatopia
return a(chunkstatus, lightenginethreaded, ichunkaccess);
});
public static final ChunkStatus SPAWN = a("spawn", ChunkStatus.LIGHT, 0, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (worldserver, chunkgenerator, list, ichunkaccess) -> {
@@ -148,9 +148,9 @@ public class ChunkStatus {
});
public static final ChunkStatus HEIGHTMAPS = a("heightmaps", ChunkStatus.SPAWN, 0, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (worldserver, chunkgenerator, list, ichunkaccess) -> {
});
- public static final ChunkStatus FULL = a("full", ChunkStatus.HEIGHTMAPS, 0, ChunkStatus.o, ChunkStatus.Type.LEVELCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
+ public static final ChunkStatus FULL = a("full", ChunkStatus.HEIGHTMAPS, 0, ChunkStatus.o, ChunkStatus.Type.LEVELCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, priority) -> { // Yatopia
return (CompletableFuture) function.apply(ichunkaccess);
- }, (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess) -> {
+ }, (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, priority) -> { // Yatopia
return (CompletableFuture) function.apply(ichunkaccess);
});
private static final List<ChunkStatus> q = ImmutableList.of(ChunkStatus.FULL, ChunkStatus.FEATURES, ChunkStatus.LIQUID_CARVERS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS);
@@ -254,11 +254,23 @@ public class ChunkStatus {
}
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> a(WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list) {
- return this.v.doWork(this, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, (IChunkAccess) list.get(list.size() / 2));
+ // Yatopia start - add priority param
+ return runGenerationTask(worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, Integer.MAX_VALUE);
+ }
+
+ public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> runGenerationTask(WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, int priority) {
+ return this.v.doWork(this, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, (IChunkAccess) list.get(list.size() / 2), priority);
+ // Yatopia end
}
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> a(WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess) {
- return this.w.doWork(this, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess);
+ // Yatopia start - add priority param
+ return runLoadTask(worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, Integer.MAX_VALUE);
+ }
+
+ public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> runLoadTask(WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess, int priority) {
+ return this.w.doWork(this, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, priority);
+ // Yatopia end
}
public final int getNeighborRadius() { return this.f(); } // Paper - OBFHELPER
@@ -309,6 +321,13 @@ public class ChunkStatus {
@Override
default CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess) {
+ // Yatopia start - add priority param
+ return doWork(chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, Integer.MAX_VALUE);
+ }
+
+ @Override
+ default CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess, int priority) {
+ // Yatopia end
// Yatopia start - threaded worldGen
return CompletableFuture.supplyAsync(() -> {
if (!ichunkaccess.getChunkStatus().b(chunkstatus)) {
@@ -318,7 +337,7 @@ public class ChunkStatus {
}
}
return Either.left(ichunkaccess);
- }, command -> worldGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : 0, command)));
+ }, command -> worldGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : priority, command)));
// Yatopia end
}
@@ -328,11 +347,23 @@ public class ChunkStatus {
interface c {
- CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess);
+ // Yatopia start - add priority param
+ default CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess) {
+ return this.doWork(chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, Integer.MAX_VALUE);
+ }
+
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess, int priority);
+ // Yatopia end
}
interface b {
- CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess);
+ // Yatopia start - add priority param
+ default CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess) {
+ return doWork(chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, Integer.MAX_VALUE);
+ }
+
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess, int priority);
+ // Yatopia end
}
}

View File

@ -5,10 +5,10 @@ Subject: [PATCH] Force world save
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
index 308bc6ea4cb2ffaa3ab2ac7ce9863320980cd242..43670af9a44253fac1596471933c06a04849750c 100644
index 55d497f4305de50e58c7e0788724576f81128138..edb45dd2933b985efb29d61b2a844615f5f1cc9f 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/VillagePlace.java
@@ -404,6 +404,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
@@ -366,6 +366,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
}).orElse(false);
}
@ -16,7 +16,7 @@ index 308bc6ea4cb2ffaa3ab2ac7ce9863320980cd242..43670af9a44253fac1596471933c06a0
@Override
public void a(BooleanSupplier booleansupplier) {
// Paper start - async chunk io
@@ -411,7 +412,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
@@ -373,7 +374,7 @@ public class VillagePlace extends RegionFileSection<VillagePlaceSection> {
super.a(booleansupplier);
} else {
//super.a(booleansupplier); // re-implement below
@ -26,14 +26,13 @@ index 308bc6ea4cb2ffaa3ab2ac7ce9863320980cd242..43670af9a44253fac1596471933c06a0
NBTTagCompound data;
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileSection.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileSection.java
index 5968712468ad1bea4894d31d0d08b213735743e5..e2cbeecf2646ffc174366eefe83241b8816f2641 100644
index f70c14385c95763b5f270a6e2ce372cf047ba7bb..4454489153f7932deaaebe8aa32ecb603764f42b 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileSection.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileSection.java
@@ -143,9 +143,9 @@ public class RegionFileSection<R> extends RegionFileCache implements AutoCloseab
return set;
@@ -50,8 +50,9 @@ public class RegionFileSection<R> extends RegionFileCache implements AutoCloseab
//this.b = new IOWorker(file, flag, file.getName()); // Paper - nuke IOWorker
}
// Yatopia end
-
+ private final java.util.concurrent.atomic.AtomicBoolean hasWorked = new java.util.concurrent.atomic.AtomicBoolean(false); // Yatopia - enforce one chunk unload per tick
protected void a(BooleanSupplier booleansupplier) {
- while (!this.d.isEmpty() && booleansupplier.getAsBoolean()) {

View File

@ -1,188 +1,37 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Fri, 5 Feb 2021 23:13:42 +0800
Date: Sat, 20 Feb 2021 22:39:16 +0800
Subject: [PATCH] fixup! Threaded WorldGen
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunk.java b/src/main/java/net/minecraft/server/level/PlayerChunk.java
index 86f156587a0939b28c5cf6f64907255c1c4f8b35..716ddfb456dbb4c84e8e9c09728e7c28b5f4cff2 100644
--- a/src/main/java/net/minecraft/server/level/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/level/PlayerChunk.java
@@ -586,6 +586,7 @@ public class PlayerChunk {
return this.ticketLevel;
}
diff --git a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
index 194321b7183d3aaa8031608a979dde71006e2fab..f5690544c1fec4b5e2e4535c2692c809074dca66 100644
--- a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
@@ -841,16 +841,18 @@ public class ChunkProviderServer extends IChunkProvider {
+ public int getPriority() { return k(); } // Yatopia - OBFHELPER
public int k() {
return this.n;
}
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
index 8f6feff0680a59223444141eb646410f7effc272..8c9ac2145fa9c4e23d8723764dd361cc2440d059 100644
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
@@ -1245,9 +1245,9 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
if (!com.tuinity.tuinity.config.TuinityConfig.useNewLightEngine && chunkstatus == ChunkStatus.LIGHT) { // Tuinity - we use edge checks, so loading 1 radius neighbours isn't necessary
completablefuture1 = this.b(playerchunk, chunkstatus);
} else {
- completablefuture1 = chunkstatus.a(this.world, this.definedStructureManager, this.lightEngine, (ichunkaccess1) -> {
+ completablefuture1 = chunkstatus.runLoadTask(this.world, this.definedStructureManager, this.lightEngine, (ichunkaccess1) -> { // Yatopia
return this.c(playerchunk);
- }, ichunkaccess);
+ }, ichunkaccess, playerchunk.getPriority()); // Yatopia
}
this.worldLoadListener.a(chunkcoordintpair, chunkstatus);
@@ -1358,9 +1358,9 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
return completablefuture.thenComposeAsync((either) -> {
return either.map((list) -> { // Paper - Shut up.
try {
- CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture1 = chunkstatus.a(this.world, this.chunkGenerator, this.definedStructureManager, this.lightEngine, (ichunkaccess) -> {
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture1 = chunkstatus.runGenerationTask(this.world, this.chunkGenerator, this.definedStructureManager, this.lightEngine, (ichunkaccess) -> {
return this.c(playerchunk);
- }, list);
+ }, list, playerchunk.getPriority());
this.worldLoadListener.a(chunkcoordintpair, chunkstatus);
return completablefuture1;
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java b/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
index a01d6dfe147383242e514d2807558bf94ff8865a..b33dd2602c592f0ed5d45d0a5a1ec87f6904aaed 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkStatus.java
@@ -69,7 +69,7 @@ public class ChunkStatus {
private static final EnumSet<HeightMap.Type> n = EnumSet.of(HeightMap.Type.OCEAN_FLOOR_WG, HeightMap.Type.WORLD_SURFACE_WG);
private static final EnumSet<HeightMap.Type> o = EnumSet.of(HeightMap.Type.OCEAN_FLOOR, HeightMap.Type.WORLD_SURFACE, HeightMap.Type.MOTION_BLOCKING, HeightMap.Type.MOTION_BLOCKING_NO_LEAVES);
- private static final ChunkStatus.c p = (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess) -> {
+ private static final ChunkStatus.c p = (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, priority) -> { // Yatopia
if (ichunkaccess instanceof ProtoChunk && !ichunkaccess.getChunkStatus().b(chunkstatus)) {
((ProtoChunk) ichunkaccess).a(chunkstatus);
// Yatopia start - reduce scheduling overhead
final ConcurrentLinkedQueue<Runnable> poiQueue = new ConcurrentLinkedQueue<>();
- private boolean runPoiQueueNext() { // TODO flush poi queue?
- try {
- final Runnable runnable = poiQueue.poll();
- if (runnable != null)
+ private boolean runPoiQueueNext() {
+ boolean hasWork = false;
+ Runnable runnable;
+ while ((runnable = poiQueue.poll()) != null) {
+ hasWork = true;
+ try {
runnable.run();
- return runnable != null;
- } catch (Throwable t) {
- t.printStackTrace();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
}
@@ -78,14 +78,14 @@ public class ChunkStatus {
};
public static final ChunkStatus EMPTY = a("empty", (ChunkStatus) null, -1, ChunkStatus.n, ChunkStatus.Type.PROTOCHUNK, (worldserver, chunkgenerator, list, ichunkaccess) -> {
});
- public static final ChunkStatus STRUCTURE_STARTS = a("structure_starts", ChunkStatus.EMPTY, 0, ChunkStatus.n, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
+ public static final ChunkStatus STRUCTURE_STARTS = a("structure_starts", ChunkStatus.EMPTY, 0, ChunkStatus.n, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, priority) -> { // Yatopia
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> result = CompletableFuture.completedFuture(Either.left(ichunkaccess));
if (!ichunkaccess.getChunkStatus().b(chunkstatus)) {
if (worldserver.worldDataServer.getGeneratorSettings().shouldGenerateMapFeatures()) { // CraftBukkit
result = CompletableFuture.supplyAsync(() -> {
chunkgenerator.createStructures(worldserver.r(), worldserver.getStructureManager(), ichunkaccess, definedstructuremanager, worldserver.getSeed());
return Either.left(ichunkaccess);
- }, command -> worldGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : 0, command)));
+ }, command -> worldGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : priority, command)));
}
if (ichunkaccess instanceof ProtoChunk) {
result.thenRun(() -> ((ProtoChunk) ichunkaccess).a(chunkstatus));
@@ -116,7 +116,7 @@ public class ChunkStatus {
public static final ChunkStatus LIQUID_CARVERS = a("liquid_carvers", ChunkStatus.CARVERS, 0, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (worldserver, chunkgenerator, list, ichunkaccess) -> {
chunkgenerator.doCarving(worldserver.getSeed(), worldserver.d(), ichunkaccess, WorldGenStage.Features.LIQUID);
});
- public static final ChunkStatus FEATURES = a("features", ChunkStatus.LIQUID_CARVERS, 8, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
+ public static final ChunkStatus FEATURES = a("features", ChunkStatus.LIQUID_CARVERS, 8, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, priority) -> { // Yatopia
// Yatopia start - threaded WorldGen
return chunkgenerator.featureGenLock.acquireLock().toCompletableFuture().thenComposeAsync(token -> {
try {
@@ -135,12 +135,12 @@ public class ChunkStatus {
}
return CompletableFuture.completedFuture(Either.left(ichunkaccess));
- }, command -> featureGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : 0, command)));
+ }, command -> featureGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : priority, command)));
// Yatopia end
});
- public static final ChunkStatus LIGHT = a("light", ChunkStatus.FEATURES, 1, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
+ public static final ChunkStatus LIGHT = a("light", ChunkStatus.FEATURES, 1, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, priority) -> { // Yatopia
return a(chunkstatus, lightenginethreaded, ichunkaccess);
- }, (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess) -> {
+ }, (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, priority) -> { // Yatopia
return a(chunkstatus, lightenginethreaded, ichunkaccess);
});
public static final ChunkStatus SPAWN = a("spawn", ChunkStatus.LIGHT, 0, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (worldserver, chunkgenerator, list, ichunkaccess) -> {
@@ -148,9 +148,9 @@ public class ChunkStatus {
});
public static final ChunkStatus HEIGHTMAPS = a("heightmaps", ChunkStatus.SPAWN, 0, ChunkStatus.o, ChunkStatus.Type.PROTOCHUNK, (worldserver, chunkgenerator, list, ichunkaccess) -> {
});
- public static final ChunkStatus FULL = a("full", ChunkStatus.HEIGHTMAPS, 0, ChunkStatus.o, ChunkStatus.Type.LEVELCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess) -> {
+ public static final ChunkStatus FULL = a("full", ChunkStatus.HEIGHTMAPS, 0, ChunkStatus.o, ChunkStatus.Type.LEVELCHUNK, (chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, priority) -> { // Yatopia
return (CompletableFuture) function.apply(ichunkaccess);
- }, (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess) -> {
+ }, (chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, priority) -> { // Yatopia
return (CompletableFuture) function.apply(ichunkaccess);
});
private static final List<ChunkStatus> q = ImmutableList.of(ChunkStatus.FULL, ChunkStatus.FEATURES, ChunkStatus.LIQUID_CARVERS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS, ChunkStatus.STRUCTURE_STARTS);
@@ -254,11 +254,23 @@ public class ChunkStatus {
- return false;
+ return hasWork;
}
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> a(WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list) {
- return this.v.doWork(this, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, (IChunkAccess) list.get(list.size() / 2));
+ // Yatopia start - add priority param
+ return runGenerationTask(worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, Integer.MAX_VALUE);
+ }
+
+ public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> runGenerationTask(WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, int priority) {
+ return this.v.doWork(this, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, (IChunkAccess) list.get(list.size() / 2), priority);
+ // Yatopia end
}
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> a(WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess) {
- return this.w.doWork(this, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess);
+ // Yatopia start - add priority param
+ return runLoadTask(worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, Integer.MAX_VALUE);
+ }
+
+ public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> runLoadTask(WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess, int priority) {
+ return this.w.doWork(this, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, priority);
+ // Yatopia end
}
public final int getNeighborRadius() { return this.f(); } // Paper - OBFHELPER
@@ -309,6 +321,13 @@ public class ChunkStatus {
@Override
default CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess) {
+ // Yatopia start - add priority param
+ return doWork(chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, Integer.MAX_VALUE);
+ }
+
+ @Override
+ default CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess, int priority) {
+ // Yatopia end
// Yatopia start - threaded worldGen
return CompletableFuture.supplyAsync(() -> {
if (!ichunkaccess.getChunkStatus().b(chunkstatus)) {
@@ -318,7 +337,7 @@ public class ChunkStatus {
}
}
return Either.left(ichunkaccess);
- }, command -> worldGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : 0, command)));
+ }, command -> worldGenExecutor.execute(new org.yatopiamc.yatopia.server.executors.PrioritizedRunnable(() -> com.destroystokyo.paper.io.chunk.ChunkTaskManager.hasChunkWait(worldserver, ichunkaccess.getPos().x, ichunkaccess.getPos().z) ? Integer.MIN_VALUE : priority, command)));
// Yatopia end
}
@@ -328,11 +347,23 @@ public class ChunkStatus {
interface c {
- CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess);
+ // Yatopia start - add priority param
+ default CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess) {
+ return this.doWork(chunkstatus, worldserver, definedstructuremanager, lightenginethreaded, function, ichunkaccess, Integer.MAX_VALUE);
+ }
+
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, IChunkAccess ichunkaccess, int priority);
+ // Yatopia end
}
interface b {
- CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess);
+ // Yatopia start - add priority param
+ default CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess) {
+ return doWork(chunkstatus, worldserver, chunkgenerator, definedstructuremanager, lightenginethreaded, function, list, ichunkaccess, Integer.MAX_VALUE);
+ }
+
+ CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> doWork(ChunkStatus chunkstatus, WorldServer worldserver, ChunkGenerator chunkgenerator, DefinedStructureManager definedstructuremanager, LightEngineThreaded lightenginethreaded, Function<IChunkAccess, CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> function, List<IChunkAccess> list, IChunkAccess ichunkaccess, int priority);
+ // Yatopia end
}
}
public boolean runTasks() {

View File

@ -1,37 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <ishlandmc@yeah.net>
Date: Sat, 20 Feb 2021 22:39:16 +0800
Subject: [PATCH] fixup! Threaded WorldGen
diff --git a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
index 194321b7183d3aaa8031608a979dde71006e2fab..f5690544c1fec4b5e2e4535c2692c809074dca66 100644
--- a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
@@ -841,16 +841,18 @@ public class ChunkProviderServer extends IChunkProvider {
// Yatopia start - reduce scheduling overhead
final ConcurrentLinkedQueue<Runnable> poiQueue = new ConcurrentLinkedQueue<>();
- private boolean runPoiQueueNext() { // TODO flush poi queue?
- try {
- final Runnable runnable = poiQueue.poll();
- if (runnable != null)
+ private boolean runPoiQueueNext() {
+ boolean hasWork = false;
+ Runnable runnable;
+ while ((runnable = poiQueue.poll()) != null) {
+ hasWork = true;
+ try {
runnable.run();
- return runnable != null;
- } catch (Throwable t) {
- t.printStackTrace();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
}
- return false;
+ return hasWork;
}
public boolean runTasks() {