Skip to content

Commit

Permalink
Fixes some behavior issues in MixinSpawnDensityCapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Dec 21, 2022
1 parent f4fda8d commit 706232e
Showing 1 changed file with 15 additions and 6 deletions.
Expand Up @@ -2,7 +2,6 @@

import com.ishland.vmp.common.chunkwatching.AreaPlayerChunkWatchingManager;
import com.ishland.vmp.mixins.access.IThreadedAnvilChunkStorage;
import it.unimi.dsi.fastutil.objects.Object2ReferenceOpenHashMap;
import it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -41,7 +40,13 @@ private void onInit(CallbackInfo info) {
@Unique
private Object[] getMobSpawnablePlayersArray(ChunkPos chunkPos) {
final AreaPlayerChunkWatchingManager manager = (AreaPlayerChunkWatchingManager) ((IThreadedAnvilChunkStorage) this.threadedAnvilChunkStorage).getPlayerChunkWatchingManager();
return manager.getPlayersWatchingChunkArray(chunkPos.toLong());
return manager.getPlayersInGeneralAreaMap(chunkPos.toLong());
}

private static double sqrDistance(double x1, double y1, double x2, double y2) {
final double dx = x1 - x2;
final double dy = y1 - y2;
return dx * dx + dy * dy;
}

/**
Expand All @@ -50,9 +55,11 @@ private Object[] getMobSpawnablePlayersArray(ChunkPos chunkPos) {
*/
@Overwrite
public void increaseDensity(ChunkPos chunkPos, SpawnGroup spawnGroup) {
final double centerX = chunkPos.getCenterX();
final double centerZ = chunkPos.getCenterZ();
for(Object _player : this.getMobSpawnablePlayersArray(chunkPos)) {
if (_player instanceof ServerPlayerEntity serverPlayerEntity) {
this.playersToDensityCap.computeIfAbsent(serverPlayerEntity, newDensityCap).increaseDensity(spawnGroup);
if (_player instanceof ServerPlayerEntity player && !player.isSpectator() && sqrDistance(centerX, centerZ, player.getX(), player.getZ()) <= 16384.0D) {
this.playersToDensityCap.computeIfAbsent(player, newDensityCap).increaseDensity(spawnGroup);
}
}
}
Expand All @@ -63,9 +70,11 @@ public void increaseDensity(ChunkPos chunkPos, SpawnGroup spawnGroup) {
*/
@Overwrite
public boolean canSpawn(SpawnGroup spawnGroup, ChunkPos chunkPos) {
final double centerX = chunkPos.getCenterX();
final double centerZ = chunkPos.getCenterZ();
for(Object _player : this.getMobSpawnablePlayersArray(chunkPos)) {
if (_player instanceof ServerPlayerEntity serverPlayerEntity) {
SpawnDensityCapper.DensityCap densityCap = this.playersToDensityCap.get(serverPlayerEntity);
if (_player instanceof ServerPlayerEntity player && !player.isSpectator() && sqrDistance(centerX, centerZ, player.getX(), player.getZ()) <= 16384.0D) {
SpawnDensityCapper.DensityCap densityCap = this.playersToDensityCap.get(player);
if (densityCap == null || densityCap.canSpawn(spawnGroup)) {
return true;
}
Expand Down

0 comments on commit 706232e

Please sign in to comment.