1package com.runehive.game.world.region;
3import com.google.common.base.Preconditions;
4import com.runehive.game.world.entity.mob.Mob;
5import com.runehive.game.world.entity.mob.npc.Npc;
6import com.runehive.game.world.entity.mob.player.Player;
7import com.runehive.game.world.position.Position;
8import com.runehive.util.Utility;
9import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
10import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
13import java.util.function.Consumer;
23 private final Int2ObjectMap<Region>
activeRegions =
new Int2ObjectOpenHashMap<>();
35 if (nearby ==
null)
continue;
37 if (nearby.getCurrentHealth() <= 0 || nearby.isDead())
continue;
51 position.getRegion().getSurroundingRegions().ifPresent(regions -> {
54 if (other ==
null)
continue;
56 if (other.getCurrentHealth() <= 0 || other.isDead())
continue;
70 Preconditions.checkArgument(mob !=
null,
"mob is null");
71 List<Player> localPlayers =
new LinkedList<>();
75 localPlayers.add(player);
89 List<Npc> localNpcs =
new LinkedList<>();
113 Set<Region> surrounding =
new HashSet<>();
117 for (
int y = -1; y <= 1; y++) {
118 for (
int x = -1; x <= 1; x++) {
119 int xx = (chunkX + x * 8 + 6) << 3;
120 int yy = (chunkY + y * 8 + 6) << 3;
123 if (!surrounding.contains(
region)) {
129 Region[] x = surrounding.toArray(
new Region[surrounding.size()]);
164 private static int hash(
int x,
int y) {
165 return ((x >> 6) << 8) + (y >> 6);
Represents a non-player character in the in-game world.
This class represents a character controlled by a player.
Represents a single tile on the game world.
boolean isWithinDistance(Position other, int radius)
Checks if this location is within range of another.
Represents a single region.
static final int VIEW_DISTANCE
void setSurroundingRegions(Optional< Region[]> surroundingRegions)
Optional< Region[]> getSurroundingRegions()
Manages the world regions.
static void forNearbyPlayer(Position position, int distance, Consumer< Player > action)
Sends an action to Mob instance which is within a distance.
List< Player > getLocalPlayers(Mob mob)
Gets the local players around an entity.
Region getRegion(final int x, final int y)
Gets a region by its x and y coordinates.
Region getRegion(Position position)
Gets a region by position.
static void forNearbyPlayer(Mob mob, int distance, Consumer< Player > action)
Sends an action to Mob instance which is within a distance.
final Int2ObjectMap< Region > activeRegions
The active (loaded) region map.
static int hash(int x, int y)
List< Npc > getLocalNpcs(Mob mob)
Gets the local npcs around an entity.
Region[] getSurroundingRegions(Position position)
Gets the regions surrounding a position.
Handles miscellaneous methods.
static int getDistance(Interactable source, Position target)