reloading chunks is not needed when resetting, fixing entities removed.

This commit is contained in:
gnembon committed 2021-06-29 02:21:47 -03:00
1 parent b8082ba5b8
commit ca59c8f30a
6 files changed
+36 -3

No files matched your search

@@ -1,7 +1,10 @@
package carpet.fakes;
import net.minecraft.entity.Entity;
import net.minecraft.world.entity.EntityLookup;
import net.minecraft.world.level.ServerWorldProperties;
public interface ServerWorldInterface {
ServerWorldProperties getWorldPropertiesCM();
EntityLookup<Entity> getEntityLookupCMPublic();
}
@@ -0,0 +1,11 @@
package carpet.fakes;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.entity.EntityLike;
import java.util.List;
public interface SimpleEntityLookupInterface<T extends EntityLike>
{
List<T> getChunkEntities(ChunkPos chpos);
}
@@ -13,6 +13,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.world.chunk.WorldChunk;
import net.minecraft.world.entity.EntityLookup;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior;
import net.minecraft.world.level.ServerWorldProperties;
@@ -79,7 +80,14 @@ public class ServerWorld_scarpetMixin implements ServerWorldInterface
@Final
@Shadow
private ServerWorldProperties worldProperties;
@Shadow @Final private ServerEntityManager<Entity> entityManager;
public ServerWorldProperties getWorldPropertiesCM(){
return worldProperties;
}
@Override
public EntityLookup<Entity> getEntityLookupCMPublic() {
return entityManager.getLookup();
}
}
@@ -12,6 +12,10 @@ import java.util.concurrent.Future;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
import carpet.fakes.SimpleEntityLookupInterface;
import carpet.fakes.ServerWorldInterface;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTask;
import org.apache.commons.lang3.tuple.Pair;
@@ -358,11 +362,17 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem
{
final ChunkPos pos = chunk.getPos();
// remove entities
long longPos = pos.toLong();
if (this.loadedChunks.contains(longPos) && chunk instanceof WorldChunk)
((SimpleEntityLookupInterface<Entity>)((ServerWorldInterface)world).getEntityLookupCMPublic()).getChunkEntities(pos).forEach(entity -> { if (!(entity instanceof PlayerEntity)) entity.discard();});
if (chunk instanceof WorldChunk)
((WorldChunk) chunk).setLoadedToWorld(false);
if (this.loadedChunks.remove(pos.toLong()) && chunk instanceof WorldChunk)
this.world.unloadEntities((WorldChunk) chunk);
this.world.unloadEntities((WorldChunk) chunk); // block entities only
((ServerLightingProviderInterface) this.serverLightingProvider).invokeUpdateChunkStatus(pos);
((ServerLightingProviderInterface) this.serverLightingProvider).removeLightData(chunk);
@@ -1469,13 +1469,13 @@ public class WorldAccess {
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
{
Map<String, Integer> report = ((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).regenerateChunkRegion(requestedChunks);
for (ChunkPos chpos: requestedChunks)
/*for (ChunkPos chpos: requestedChunks) // needed in 1.16 only
{
if (world.getChunk(chpos.x, chpos.z, ChunkStatus.FULL, false) != null)
{
WorldTools.forceChunkUpdate(chpos.getStartPos(), world);
}
}
}*/
result[0] = MapValue.wrap(report.entrySet().stream().collect(Collectors.toMap(
e -> new StringValue((String)((Map.Entry) e).getKey()),
e -> new NumericValue((Integer)((Map.Entry) e).getValue())