reset_chunk
This commit is contained in:
1 parent
786ae4ae7f
commit
7af08306e4
6 files changed
+137
-24
No files matched your search
@@ -0,0 +1,14 @@
|
|||||||
|
package carpet.fakes;
|
||||||
|
|
||||||
|
import com.mojang.datafixers.util.Either;
|
||||||
|
import net.minecraft.server.world.ChunkHolder;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.util.thread.ThreadExecutor;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public interface ChunkHolderInterface
|
||||||
|
{
|
||||||
|
CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> setDefaultProtoChunk(ChunkPos chpos, ThreadExecutor<Runnable> executor);
|
||||||
|
}
|
||||||
@@ -4,7 +4,5 @@ import net.minecraft.util.math.ChunkPos;
|
|||||||
|
|
||||||
public interface ThreadedAnvilChunkStorageInterface
|
public interface ThreadedAnvilChunkStorageInterface
|
||||||
{
|
{
|
||||||
//boolean isChunkLoaded(ChunkPos chpos);
|
|
||||||
//void forceUnloadChunk(ChunkPos chpos);
|
|
||||||
void regenerateChunk(ChunkPos chpos);
|
void regenerateChunk(ChunkPos chpos);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package carpet.mixins;
|
||||||
|
|
||||||
|
import carpet.fakes.ChunkHolderInterface;
|
||||||
|
import com.mojang.datafixers.util.Either;
|
||||||
|
import net.minecraft.server.world.ChunkHolder;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.util.thread.ThreadExecutor;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.ChunkStatus;
|
||||||
|
import net.minecraft.world.chunk.ProtoChunk;
|
||||||
|
import net.minecraft.world.chunk.UpgradeData;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||||
|
|
||||||
|
@Mixin(ChunkHolder.class)
|
||||||
|
public abstract class ChunkHolder_scarpetChunkCreationMixin implements ChunkHolderInterface
|
||||||
|
{
|
||||||
|
@Shadow protected abstract void updateFuture(CompletableFuture<? extends Either<? extends Chunk, ChunkHolder.Unloaded>> newChunkFuture);
|
||||||
|
|
||||||
|
@Shadow @Final private AtomicReferenceArray<CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>>> futuresByStatus;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> setDefaultProtoChunk(ChunkPos chpos, ThreadExecutor<Runnable> executor)
|
||||||
|
{
|
||||||
|
int i = ChunkStatus.EMPTY.getIndex();
|
||||||
|
CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> completableFuture2 = CompletableFuture.supplyAsync(
|
||||||
|
() -> Either.left(new ProtoChunk(chpos, UpgradeData.NO_UPGRADE_DATA)),
|
||||||
|
executor
|
||||||
|
);
|
||||||
|
updateFuture(completableFuture2);
|
||||||
|
futuresByStatus.set(i, completableFuture2);
|
||||||
|
return completableFuture2;
|
||||||
|
}
|
||||||
|
}
|
||||||
+74
-18
@@ -1,16 +1,22 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
|
import carpet.fakes.ChunkHolderInterface;
|
||||||
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||||
|
import com.mojang.datafixers.util.Either;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
|
||||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
|
import net.minecraft.server.WorldGenerationProgressListener;
|
||||||
import net.minecraft.server.world.ChunkHolder;
|
import net.minecraft.server.world.ChunkHolder;
|
||||||
import net.minecraft.server.world.ChunkTaskPrioritySystem;
|
import net.minecraft.server.world.ChunkTaskPrioritySystem;
|
||||||
import net.minecraft.server.world.ServerLightingProvider;
|
import net.minecraft.server.world.ServerLightingProvider;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
||||||
import net.minecraft.util.math.ChunkPos;
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.util.thread.MessageListener;
|
||||||
|
import net.minecraft.util.thread.ThreadExecutor;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import net.minecraft.world.chunk.ChunkStatus;
|
||||||
|
import net.minecraft.world.chunk.WorldChunk;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
@@ -20,6 +26,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
import static carpet.script.CarpetEventServer.Event.CHUNK_GENERATED;
|
import static carpet.script.CarpetEventServer.Event.CHUNK_GENERATED;
|
||||||
|
|
||||||
@@ -46,6 +53,18 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem
|
|||||||
|
|
||||||
@Shadow @Final private ChunkTaskPrioritySystem chunkTaskPrioritySystem;
|
@Shadow @Final private ChunkTaskPrioritySystem chunkTaskPrioritySystem;
|
||||||
|
|
||||||
|
@Shadow protected abstract CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> convertToFullChunk(ChunkHolder chunkHolder);
|
||||||
|
|
||||||
|
@Shadow public abstract CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> createChunkFuture(ChunkHolder chunkHolder, ChunkStatus chunkStatus);
|
||||||
|
|
||||||
|
@Shadow @Final private ThreadExecutor<Runnable> mainThreadExecutor;
|
||||||
|
|
||||||
|
@Shadow protected abstract boolean save(Chunk chunk);
|
||||||
|
|
||||||
|
@Shadow @Final private WorldGenerationProgressListener worldGenerationProgressListener;
|
||||||
|
|
||||||
|
@Shadow @Final private MessageListener<ChunkTaskPrioritySystem.Task<Runnable>> worldgenExecutor;
|
||||||
|
|
||||||
//in method_20617
|
//in method_20617
|
||||||
//method_19534(Lnet/minecraft/server/world/ChunkHolder;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;
|
//method_19534(Lnet/minecraft/server/world/ChunkHolder;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;
|
||||||
@Inject(method = "method_19534", at = @At(
|
@Inject(method = "method_19534", at = @At(
|
||||||
@@ -63,25 +82,62 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem
|
|||||||
public void regenerateChunk(ChunkPos chpos)
|
public void regenerateChunk(ChunkPos chpos)
|
||||||
{
|
{
|
||||||
Long id = chpos.toLong();
|
Long id = chpos.toLong();
|
||||||
if (loadedChunks.contains(id))
|
//flushning all tasks on the thread executor so all futures are ready - we don't want any deadlocks
|
||||||
{
|
mainThreadExecutor.runTasks(() -> mainThreadExecutor.getTaskCount() == 0);
|
||||||
//unload chunk first
|
// save all pending chunks
|
||||||
unloadedChunks.remove(id);
|
// hopefully that would flush all chunk writes, including current chunk, if exists
|
||||||
ChunkHolder chunkHolder = (ChunkHolder)currentChunkHolders.remove(id);
|
|
||||||
if (chunkHolder != null) {
|
|
||||||
field_18807.put(id, chunkHolder);
|
|
||||||
chunkHolderListDirty = true;
|
|
||||||
method_20458(id, chunkHolder);
|
|
||||||
}
|
|
||||||
Runnable runnable;
|
Runnable runnable;
|
||||||
while((runnable = (Runnable) field_19343.poll()) != null) {
|
while((runnable = field_19343.poll()) != null) {
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
//chunk is currently in memory in some shape or form / loaded / unloaded / queued / cached
|
||||||
|
ChunkHolder chunkHolder = currentChunkHolders.remove(id);
|
||||||
|
if (chunkHolder != null) {
|
||||||
|
//method_20458(id, chunkHolder); // saving chunk // skipping entities etc
|
||||||
|
Chunk chunk = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// fingers crossed
|
||||||
|
chunk = chunkHolder.getFuture().get();
|
||||||
|
}
|
||||||
|
catch (InterruptedException | ExecutionException e)
|
||||||
|
{ }
|
||||||
|
// if (field_18807.remove(id, chunkHolder) && chunk != null) {
|
||||||
|
if (chunk != null) {
|
||||||
|
if (chunk instanceof WorldChunk) {
|
||||||
|
((WorldChunk)chunk).setLoadedToWorld(false);
|
||||||
|
}
|
||||||
|
save(chunk);
|
||||||
|
if (this.loadedChunks.remove(id) && chunk instanceof WorldChunk) {
|
||||||
|
WorldChunk worldChunk = (WorldChunk)chunk;
|
||||||
|
//apparently that doesn't remove them for the client
|
||||||
|
this.world.unloadEntities(worldChunk);
|
||||||
|
}
|
||||||
|
//this.serverLightingProvider.updateChunkStatus(chunk.getPos());
|
||||||
|
serverLightingProvider.tick();
|
||||||
|
worldGenerationProgressListener.setChunkStatus(chunk.getPos(), (ChunkStatus)null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//getting rid of all signs
|
||||||
|
this.chunkHolderListDirty = true;
|
||||||
|
currentChunkHolders.remove(id);
|
||||||
|
unloadedChunks.remove(id);
|
||||||
|
loadedChunks.remove(id);
|
||||||
|
field_18807.remove(id);
|
||||||
|
|
||||||
|
ChunkHolder newHolder = new ChunkHolder(chpos, 0,serverLightingProvider, chunkTaskPrioritySystem, (ChunkHolder.PlayersWatchingChunkProvider) this);
|
||||||
|
this.currentChunkHolders.put(id, newHolder);
|
||||||
|
loadedChunks.add(id);
|
||||||
|
|
||||||
|
((ChunkHolderInterface)newHolder).setDefaultProtoChunk(chpos, mainThreadExecutor);
|
||||||
|
convertToFullChunk(newHolder);
|
||||||
|
// running all pending tasks
|
||||||
|
mainThreadExecutor.runTasks(() -> mainThreadExecutor.getTaskCount() == 0);
|
||||||
|
// save all pending chunks / potentially only one max - ours
|
||||||
|
// hopefully that would flush all chunk writes, including current chink
|
||||||
|
while((runnable = field_19343.poll()) != null) {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ChunkHolder newHolder = new ChunkHolder(chpos, 0,serverLightingProvider, chunkTaskPrioritySystem, (ChunkHolder.PlayersWatchingChunkProvider) this);
|
|
||||||
this.currentChunkHolders.put(id, newHolder);
|
|
||||||
this.chunkHolderListDirty = true;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import carpet.CarpetServer;
|
|||||||
import carpet.fakes.MinecraftServerInterface;
|
import carpet.fakes.MinecraftServerInterface;
|
||||||
import carpet.fakes.BiomeArrayInterface;
|
import carpet.fakes.BiomeArrayInterface;
|
||||||
import carpet.fakes.StatTypeInterface;
|
import carpet.fakes.StatTypeInterface;
|
||||||
|
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||||
import carpet.helpers.FeatureGenerator;
|
import carpet.helpers.FeatureGenerator;
|
||||||
import carpet.mixins.ChunkTicketManager_scarpetMixin;
|
import carpet.mixins.ChunkTicketManager_scarpetMixin;
|
||||||
import carpet.mixins.PointOfInterest_scarpetMixin;
|
import carpet.mixins.PointOfInterest_scarpetMixin;
|
||||||
@@ -1674,16 +1675,21 @@ public class CarpetExpression
|
|||||||
return (_c, _t) -> ret;
|
return (_c, _t) -> ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
/*this.expr.addLazyFunction("reset_chunk", -1, (c, t, lv) ->
|
this.expr.addLazyFunction("reset_chunk", -1, (c, t, lv) ->
|
||||||
{
|
{
|
||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
|
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
|
||||||
|
|
||||||
ServerWorld world = cc.s.getWorld();
|
ServerWorld world = cc.s.getWorld();
|
||||||
BlockPos pos = locator.block.getPos();
|
BlockPos pos = locator.block.getPos();
|
||||||
ThreadedAnvilChunkStorage
|
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
|
||||||
|
{
|
||||||
});*/
|
((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).regenerateChunk(new ChunkPos(pos));
|
||||||
|
world.getChunk(pos);
|
||||||
|
this.forceChunkUpdate(pos, world);
|
||||||
|
});
|
||||||
|
return LazyValue.NULL;
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
"ThreadedAnvilChunkStorage_tickMixin",
|
"ThreadedAnvilChunkStorage_tickMixin",
|
||||||
|
|
||||||
"ThreadedAnvilChunkStorage_scarpetChunkCreationMixin",
|
"ThreadedAnvilChunkStorage_scarpetChunkCreationMixin",
|
||||||
|
"ChunkHolder_scarpetChunkCreationMixin",
|
||||||
|
|
||||||
"MobEntityMixin",
|
"MobEntityMixin",
|
||||||
"ServerWorld_unloadedEntityMixin",
|
"ServerWorld_unloadedEntityMixin",
|
||||||
|
|||||||
Reference in new issue
Block a user