reset multiple chunks WvmIP
This commit is contained in:
1 parent
d8e554f182
commit
b2e5053c6b
3 files changed
+47
-20
No files matched your search
@@ -4,5 +4,5 @@ import net.minecraft.util.math.ChunkPos;
|
||||
|
||||
public interface ThreadedAnvilChunkStorageInterface
|
||||
{
|
||||
void regenerateChunk(ChunkPos chpos);
|
||||
void regenerateChunkRegion(ChunkPos from, ChunkPos to);
|
||||
}
|
||||
+37
-17
@@ -1,5 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.fakes.ChunkHolderInterface;
|
||||
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
@@ -24,6 +25,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -79,9 +82,17 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public void regenerateChunk(ChunkPos chpos)
|
||||
public void regenerateChunkRegion(ChunkPos from, ChunkPos to)
|
||||
{
|
||||
Long id = chpos.toLong();
|
||||
List<ChunkPos> chunksToConvert = new ArrayList<>();
|
||||
int xmax = Math.max(from.x, to.x);
|
||||
int zmax = Math.max(from.z, to.z);
|
||||
for (int x = Math.min(from.x, to.x); x <= xmax; x++) for (int z = Math.min(from.z, to.z); z <= zmax; z++)
|
||||
{
|
||||
chunksToConvert.add(new ChunkPos(x,z));
|
||||
}
|
||||
CarpetSettings.LOG.error("Converting "+chunksToConvert.size()+" chunks");
|
||||
|
||||
//flushning all tasks on the thread executor so all futures are ready - we don't want any deadlocks
|
||||
mainThreadExecutor.runTasks(() -> mainThreadExecutor.getTaskCount() == 0);
|
||||
// save all pending chunks
|
||||
@@ -91,9 +102,14 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
List<ChunkHolder> createdChunks = new ArrayList<>();
|
||||
for (ChunkPos chpos : chunksToConvert)
|
||||
{
|
||||
Long id = chpos.toLong();
|
||||
//chunk is currently in memory in some shape or form / loaded / unloaded / queued / cached
|
||||
ChunkHolder chunkHolder = currentChunkHolders.remove(id);
|
||||
if (chunkHolder != null) {
|
||||
if (chunkHolder != null)
|
||||
{
|
||||
//method_20458(id, chunkHolder); // saving chunk // skipping entities etc
|
||||
Chunk chunk = null;
|
||||
try
|
||||
@@ -102,36 +118,40 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem
|
||||
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);
|
||||
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;
|
||||
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());
|
||||
//this.serverLightingProvider.updateChunkStatus(chunk.getPos()); // we might need that as some point
|
||||
serverLightingProvider.tick();
|
||||
worldGenerationProgressListener.setChunkStatus(chunk.getPos(), (ChunkStatus)null);
|
||||
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);
|
||||
createdChunks.add(newHolder);
|
||||
}
|
||||
//getting rid of all signs
|
||||
this.chunkHolderListDirty = true;
|
||||
// not needed right now
|
||||
//for (ChunkHolder newHolder: createdChunks) convertToFullChunk(newHolder);
|
||||
// running all pending tasks
|
||||
mainThreadExecutor.runTasks(() -> mainThreadExecutor.getTaskCount() == 0);
|
||||
// save all pending chunks / potentially only one max - ours
|
||||
|
||||
@@ -79,7 +79,6 @@ import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ChunkTicket;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.stat.Stat;
|
||||
@@ -1680,11 +1679,19 @@ public class CarpetExpression
|
||||
CarpetContext cc = (CarpetContext)c;
|
||||
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
|
||||
|
||||
|
||||
ServerWorld world = cc.s.getWorld();
|
||||
BlockPos pos = locator.block.getPos();
|
||||
BlockPos temp = pos;
|
||||
if (lv.size() > locator.offset )
|
||||
{
|
||||
BlockValue.LocatorResult locator2 = BlockValue.fromParams(cc, lv, locator.offset);
|
||||
temp = locator2.block.getPos();
|
||||
}
|
||||
BlockPos toPos = temp;
|
||||
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
|
||||
{
|
||||
((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).regenerateChunk(new ChunkPos(pos));
|
||||
((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).regenerateChunkRegion(new ChunkPos(pos), new ChunkPos(toPos));
|
||||
world.getChunk(pos);
|
||||
this.forceChunkUpdate(pos, world);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user