regenerate WIP
This commit is contained in:
1 parent
5c9774f1d2
commit
9601ab9973
3 files changed
+76
-1
No files matched your search
@@ -0,0 +1,10 @@
|
|||||||
|
package carpet.fakes;
|
||||||
|
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
|
||||||
|
public interface ThreadedAnvilChunkStorageInterface
|
||||||
|
{
|
||||||
|
//boolean isChunkLoaded(ChunkPos chpos);
|
||||||
|
//void forceUnloadChunk(ChunkPos chpos);
|
||||||
|
void regenerateChunk(ChunkPos chpos);
|
||||||
|
}
|
||||||
+53
-1
@@ -1,8 +1,15 @@
|
|||||||
package carpet.mixins;
|
package carpet.mixins;
|
||||||
|
|
||||||
|
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||||
|
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
|
||||||
|
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||||
import net.minecraft.server.world.ChunkHolder;
|
import net.minecraft.server.world.ChunkHolder;
|
||||||
|
import net.minecraft.server.world.ChunkTaskPrioritySystem;
|
||||||
|
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.world.chunk.Chunk;
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
@@ -11,15 +18,34 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static carpet.script.CarpetEventServer.Event.CHUNK_GENERATED;
|
import static carpet.script.CarpetEventServer.Event.CHUNK_GENERATED;
|
||||||
|
|
||||||
@Mixin(ThreadedAnvilChunkStorage.class)
|
@Mixin(ThreadedAnvilChunkStorage.class)
|
||||||
public class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin
|
public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implements ThreadedAnvilChunkStorageInterface
|
||||||
{
|
{
|
||||||
@Shadow @Final private ServerWorld world;
|
@Shadow @Final private ServerWorld world;
|
||||||
|
|
||||||
|
@Shadow @Final private LongSet loadedChunks;
|
||||||
|
|
||||||
|
@Shadow @Final private LongSet unloadedChunks;
|
||||||
|
|
||||||
|
@Shadow @Final private Long2ObjectLinkedOpenHashMap<ChunkHolder> currentChunkHolders;
|
||||||
|
|
||||||
|
@Shadow @Final private Long2ObjectLinkedOpenHashMap<ChunkHolder> field_18807;
|
||||||
|
|
||||||
|
@Shadow private boolean chunkHolderListDirty;
|
||||||
|
|
||||||
|
@Shadow protected abstract void method_20458(long l, ChunkHolder chunkHolder);
|
||||||
|
|
||||||
|
@Shadow @Final private Queue<Runnable> field_19343;
|
||||||
|
|
||||||
|
@Shadow @Final private ServerLightingProvider serverLightingProvider;
|
||||||
|
|
||||||
|
@Shadow @Final private ChunkTaskPrioritySystem chunkTaskPrioritySystem;
|
||||||
|
|
||||||
//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(
|
||||||
@@ -32,4 +58,30 @@ public class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin
|
|||||||
if (CHUNK_GENERATED.isNeeded())
|
if (CHUNK_GENERATED.isNeeded())
|
||||||
world.getServer().execute( () -> CHUNK_GENERATED.onChunkGenerated(world, chunk) );
|
world.getServer().execute( () -> CHUNK_GENERATED.onChunkGenerated(world, chunk) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void regenerateChunk(ChunkPos chpos)
|
||||||
|
{
|
||||||
|
Long id = chpos.toLong();
|
||||||
|
if (loadedChunks.contains(id))
|
||||||
|
{
|
||||||
|
//unload chunk first
|
||||||
|
unloadedChunks.remove(id);
|
||||||
|
ChunkHolder chunkHolder = (ChunkHolder)currentChunkHolders.remove(id);
|
||||||
|
if (chunkHolder != null) {
|
||||||
|
field_18807.put(id, chunkHolder);
|
||||||
|
chunkHolderListDirty = true;
|
||||||
|
method_20458(id, chunkHolder);
|
||||||
|
}
|
||||||
|
Runnable runnable;
|
||||||
|
while((runnable = (Runnable) field_19343.poll()) != null) {
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ChunkHolder newHolder = new ChunkHolder(chpos, 0,serverLightingProvider, chunkTaskPrioritySystem, (ChunkHolder.PlayersWatchingChunkProvider) this);
|
||||||
|
this.currentChunkHolders.put(id, newHolder);
|
||||||
|
this.chunkHolderListDirty = true;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -78,6 +78,7 @@ import net.minecraft.server.command.ServerCommandSource;
|
|||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ChunkTicket;
|
import net.minecraft.server.world.ChunkTicket;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
||||||
import net.minecraft.sound.BlockSoundGroup;
|
import net.minecraft.sound.BlockSoundGroup;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.stat.Stat;
|
import net.minecraft.stat.Stat;
|
||||||
@@ -1672,6 +1673,18 @@ public class CarpetExpression
|
|||||||
Value ret = result[0]; // preventing from lazy evaluating of the result in case a future completes later
|
Value ret = result[0]; // preventing from lazy evaluating of the result in case a future completes later
|
||||||
return (_c, _t) -> ret;
|
return (_c, _t) -> ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*this.expr.addLazyFunction("reset_chunk", -1, (c, t, lv) ->
|
||||||
|
{
|
||||||
|
CarpetContext cc = (CarpetContext)c;
|
||||||
|
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
|
||||||
|
|
||||||
|
ServerWorld world = cc.s.getWorld();
|
||||||
|
BlockPos pos = locator.block.getPos();
|
||||||
|
ThreadedAnvilChunkStorage
|
||||||
|
|
||||||
|
});*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user