Improve performance of persistent chunk checks (#5706)

This commit is contained in:
Ben Staddon authored and LexManos committed 2019-08-28 18:21:38 -07:00
1 parent 20efd7150a
commit 3b99c80636
2 files changed
+9 -4

No files matched your search

@@ -576,7 +576,7 @@
- int l2 = 32;
- if (p_72866_2_ && !this.func_175663_a(j2 - 32, 0, k2 - 32, j2 + 32, 0, k2 + 32, true))
+ boolean isForced = getPersistentChunks().containsKey(new net.minecraft.util.math.ChunkPos(j2 >> 4, k2 >> 4));
+ boolean isForced = !this.field_72995_K && getPersistentChunks().containsKey(new net.minecraft.util.math.ChunkPos(j2 >> 4, k2 >> 4));
+ int range = isForced ? 0 : 32;
+ boolean canUpdate = !p_72866_2_ || this.func_175663_a(j2 - range, 0, k2 - range, j2 + range, 0, k2 + range, true);
+ if (!canUpdate) canUpdate = net.minecraftforge.event.ForgeEventFactory.canEntityUpdate(p_72866_1_);
@@ -22,6 +22,7 @@ package net.minecraftforge.common;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
@@ -29,6 +30,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.WeakHashMap;
import javax.annotation.Nullable;
@@ -104,7 +106,7 @@ public class ForgeChunkManager
private static Map<String, LoadingCallback> callbacks = Maps.newHashMap();
private static Map<World, ImmutableSetMultimap<ChunkPos,Ticket>> forcedChunks = new MapMaker().weakKeys().makeMap();
private static Map<World, ImmutableSetMultimap<ChunkPos,Ticket>> forcedChunks = Collections.synchronizedMap(new WeakHashMap<>());
private static BiMap<UUID,Ticket> pendingEntities = HashBiMap.create();
private static Map<World,Cache<Long, ChunkEntry>> dormantChunkCache = new MapMaker().weakKeys().makeMap();
@@ -613,13 +615,14 @@ public class ForgeChunkManager
static void unloadWorld(World world)
{
forcedChunks.remove(world);
// World save fires before this event so the chunk loading info will be done
if (!(world instanceof WorldServer))
{
return;
}
forcedChunks.remove(world);
if (dormantChunkCacheSize != 0) // only if in use
{
dormantChunkCache.remove(world);
@@ -888,7 +891,9 @@ public class ForgeChunkManager
*/
public static ImmutableSetMultimap<ChunkPos, Ticket> getPersistentChunksFor(World world)
{
return forcedChunks.containsKey(world) ? forcedChunks.get(world) : ImmutableSetMultimap.of();
if (world.isRemote) return ImmutableSetMultimap.of();
ImmutableSetMultimap<ChunkPos, Ticket> persistentChunks = forcedChunks.get(world);
return persistentChunks != null ? persistentChunks : ImmutableSetMultimap.of();
}
static void saveWorld(World world)