Skip to content

Commit

Permalink
Merge branch 'ver/1.20.2' into ver/1.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Nov 9, 2023
2 parents 7c7ecfa + 0544aa1 commit 7fc159a
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void movePlayer(long currentPos, ServerPlayerEntity player) {
}

private int getViewDistance(ServerPlayerEntity player) {
return MathHelper.clamp(player.getViewDistance(), 2, this.watchDistance);
return MathHelper.clamp(player.getViewDistance(), 2, this.watchDistance) + 1; // edge chunks are required for rendering
}

public interface Listener {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/ishland/vmp/common/maps/AreaMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AreaMap<T> {
ReferenceLinkedOpenHashSet::clear,
ts -> {
ts.clear();
ts.trim(4);
ts.trim(256);
},
8192
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ public static void init() {
8192
);

private final AreaMap<ThreadedAnvilChunkStorage.EntityTracker> areaMap = new AreaMap<>(
(object, x, z) -> {
},
(object, x, z) -> {
},
false
);
private final AreaMap<ThreadedAnvilChunkStorage.EntityTracker> areaMap = new AreaMap<>();

private final Reference2ReferenceLinkedOpenHashMap<ServerPlayerEntity, ReferenceLinkedOpenHashSet<ThreadedAnvilChunkStorage.EntityTracker>> playerTrackers = new Reference2ReferenceLinkedOpenHashMap<>();
private final Reference2LongOpenHashMap<ThreadedAnvilChunkStorage.EntityTracker> tracker2ChunkPos = new Reference2LongOpenHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface MixinChunkFilter {
*/
@Overwrite
static boolean isWithinDistance(int centerX, int centerZ, int viewDistance, int x, int z, boolean includeEdge) {
int actualViewDistance = viewDistance + (includeEdge ? 0 : -1);
int actualViewDistance = viewDistance + (includeEdge ? 1 : 0);
int xDistance = Math.abs(centerX - x);
int zDistance = Math.abs(centerZ - z);
return xDistance <= actualViewDistance && zDistance <= actualViewDistance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public List<ServerPlayerEntity> getPlayersWatchingChunk(ChunkPos pos) {
} else {
ImmutableList.Builder<ServerPlayerEntity> builder = ImmutableList.builder();

for (Object __player : this.areaPlayerChunkWatchingManager.getPlayersWatchingChunkArray(l)) {
for (Object __player : this.areaPlayerChunkWatchingManager.getPlayersInGeneralAreaMap(l)) {
if (__player instanceof ServerPlayerEntity serverPlayerEntity) {
if (this.canTickChunk(serverPlayerEntity, pos)) {
builder.add(serverPlayerEntity);
Expand All @@ -145,7 +145,7 @@ public boolean shouldTick(ChunkPos pos) {
if (!this.ticketManager.shouldTick(l)) {
return false;
} else {
for (Object __player : this.areaPlayerChunkWatchingManager.getPlayersWatchingChunkArray(l)) {
for (Object __player : this.areaPlayerChunkWatchingManager.getPlayersInGeneralAreaMap(l)) {
if (__player instanceof ServerPlayerEntity serverPlayerEntity) {
if (this.canTickChunk(serverPlayerEntity, pos)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,11 @@ protected void rehash(int newN) {
this.pendingChunkHolderUpdates = new ObjectArrayFIFOQueue<>();
}

@Redirect(method = {"purge", "addTicket(JLnet/minecraft/server/world/ChunkTicket;)V", "removeTicket(JLnet/minecraft/server/world/ChunkTicket;)V", "removePersistentTickets"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ChunkTicketManager$TicketDistanceLevelPropagator;updateLevel(JIZ)V"), require = 3, expect = 3)
@Redirect(method = {"purge", "addTicket(JLnet/minecraft/server/world/ChunkTicket;)V", "removeTicket(JLnet/minecraft/server/world/ChunkTicket;)V", "removePersistentTickets"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ChunkTicketManager$TicketDistanceLevelPropagator;updateLevel(JIZ)V"), require = 4, expect = 4)
private void redirectUpdate(ChunkTicketManager.TicketDistanceLevelPropagator instance, long l, int i, boolean b) {
this.updateTicketLevel(l, i);
}

/**
* @author ishland
* @reason workaround for lithium compat
*/
@Overwrite
public void purge() {
++this.age;

final Predicate<ChunkTicket<?>> predicate = chunkTicket -> ((IChunkTicket) chunkTicket).invokeIsExpired1(this.age);
ObjectIterator<Long2ObjectMap.Entry<SortedArraySet<ChunkTicket<?>>>> objectIterator = this.ticketsByPosition.long2ObjectEntrySet().fastIterator();

while(objectIterator.hasNext()) {
Long2ObjectMap.Entry<SortedArraySet<ChunkTicket<?>>> entry = objectIterator.next();
if (entry.getValue().removeIf(predicate)) {
this.updateTicketLevel(entry.getLongKey(), getLevel(entry.getValue())); // modified
}

if (entry.getValue().isEmpty()) {
objectIterator.remove();
}
}

}

@Redirect(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ChunkTicketManager$TicketDistanceLevelPropagator;update(I)I"))
public int tickTickets(ChunkTicketManager.TicketDistanceLevelPropagator __, int distance, ThreadedAnvilChunkStorage threadedAnvilChunkStorage) {
if (!((IThreadedAnvilChunkStorage) threadedAnvilChunkStorage).getMainThreadExecutor().isOnThread()) {
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
},

"custom": {
"_lithium_toggle_comment": "We disable the player_chunk_tick mixin as we handle chunk sending on our own",
"lithium:options": {
"mixin.world.player_chunk_tick": false
}
}
}

0 comments on commit 7fc159a

Please sign in to comment.