Skip to content

Commit 182b2f8

Browse files
authored
Add Point Of Interest API (#12117)
1 parent a8c05a3 commit 182b2f8

17 files changed

Lines changed: 620 additions & 1 deletion

File tree

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package io.papermc.paper.registry.keys;
2+
3+
import static net.kyori.adventure.key.Key.key;
4+
5+
import io.papermc.paper.annotation.GeneratedClass;
6+
import io.papermc.paper.entity.poi.PoiType;
7+
import io.papermc.paper.registry.RegistryKey;
8+
import io.papermc.paper.registry.TypedKey;
9+
import net.kyori.adventure.key.Key;
10+
import org.jspecify.annotations.NullMarked;
11+
12+
/**
13+
* Vanilla keys for {@link RegistryKey#POINT_OF_INTEREST_TYPE}.
14+
*
15+
* @apiNote The fields provided here are a direct representation of
16+
* what is available from the vanilla game source. They may be
17+
* changed (including removals) on any Minecraft version
18+
* bump, so cross-version compatibility is not provided on the
19+
* same level as it is on most of the other API.
20+
*/
21+
@SuppressWarnings({
22+
"unused",
23+
"SpellCheckingInspection"
24+
})
25+
@NullMarked
26+
@GeneratedClass
27+
public final class PoiTypeKeys {
28+
/**
29+
* {@code minecraft:armorer}
30+
*
31+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
32+
*/
33+
public static final TypedKey<PoiType> ARMORER = create(key("armorer"));
34+
35+
/**
36+
* {@code minecraft:bee_nest}
37+
*
38+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
39+
*/
40+
public static final TypedKey<PoiType> BEE_NEST = create(key("bee_nest"));
41+
42+
/**
43+
* {@code minecraft:beehive}
44+
*
45+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
46+
*/
47+
public static final TypedKey<PoiType> BEEHIVE = create(key("beehive"));
48+
49+
/**
50+
* {@code minecraft:butcher}
51+
*
52+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
53+
*/
54+
public static final TypedKey<PoiType> BUTCHER = create(key("butcher"));
55+
56+
/**
57+
* {@code minecraft:cartographer}
58+
*
59+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
60+
*/
61+
public static final TypedKey<PoiType> CARTOGRAPHER = create(key("cartographer"));
62+
63+
/**
64+
* {@code minecraft:cleric}
65+
*
66+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
67+
*/
68+
public static final TypedKey<PoiType> CLERIC = create(key("cleric"));
69+
70+
/**
71+
* {@code minecraft:farmer}
72+
*
73+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
74+
*/
75+
public static final TypedKey<PoiType> FARMER = create(key("farmer"));
76+
77+
/**
78+
* {@code minecraft:fisherman}
79+
*
80+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
81+
*/
82+
public static final TypedKey<PoiType> FISHERMAN = create(key("fisherman"));
83+
84+
/**
85+
* {@code minecraft:fletcher}
86+
*
87+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
88+
*/
89+
public static final TypedKey<PoiType> FLETCHER = create(key("fletcher"));
90+
91+
/**
92+
* {@code minecraft:home}
93+
*
94+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
95+
*/
96+
public static final TypedKey<PoiType> HOME = create(key("home"));
97+
98+
/**
99+
* {@code minecraft:leatherworker}
100+
*
101+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
102+
*/
103+
public static final TypedKey<PoiType> LEATHERWORKER = create(key("leatherworker"));
104+
105+
/**
106+
* {@code minecraft:librarian}
107+
*
108+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
109+
*/
110+
public static final TypedKey<PoiType> LIBRARIAN = create(key("librarian"));
111+
112+
/**
113+
* {@code minecraft:lightning_rod}
114+
*
115+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
116+
*/
117+
public static final TypedKey<PoiType> LIGHTNING_ROD = create(key("lightning_rod"));
118+
119+
/**
120+
* {@code minecraft:lodestone}
121+
*
122+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
123+
*/
124+
public static final TypedKey<PoiType> LODESTONE = create(key("lodestone"));
125+
126+
/**
127+
* {@code minecraft:mason}
128+
*
129+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
130+
*/
131+
public static final TypedKey<PoiType> MASON = create(key("mason"));
132+
133+
/**
134+
* {@code minecraft:meeting}
135+
*
136+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
137+
*/
138+
public static final TypedKey<PoiType> MEETING = create(key("meeting"));
139+
140+
/**
141+
* {@code minecraft:nether_portal}
142+
*
143+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
144+
*/
145+
public static final TypedKey<PoiType> NETHER_PORTAL = create(key("nether_portal"));
146+
147+
/**
148+
* {@code minecraft:shepherd}
149+
*
150+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
151+
*/
152+
public static final TypedKey<PoiType> SHEPHERD = create(key("shepherd"));
153+
154+
/**
155+
* {@code minecraft:test_instance}
156+
*
157+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
158+
*/
159+
public static final TypedKey<PoiType> TEST_INSTANCE = create(key("test_instance"));
160+
161+
/**
162+
* {@code minecraft:toolsmith}
163+
*
164+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
165+
*/
166+
public static final TypedKey<PoiType> TOOLSMITH = create(key("toolsmith"));
167+
168+
/**
169+
* {@code minecraft:weaponsmith}
170+
*
171+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
172+
*/
173+
public static final TypedKey<PoiType> WEAPONSMITH = create(key("weaponsmith"));
174+
175+
private PoiTypeKeys() {
176+
}
177+
178+
private static TypedKey<PoiType> create(final Key key) {
179+
return TypedKey.create(RegistryKey.POINT_OF_INTEREST_TYPE, key);
180+
}
181+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package io.papermc.paper.registry.keys.tags;
2+
3+
import static net.kyori.adventure.key.Key.key;
4+
5+
import io.papermc.paper.annotation.GeneratedClass;
6+
import io.papermc.paper.entity.poi.PoiType;
7+
import io.papermc.paper.registry.RegistryKey;
8+
import io.papermc.paper.registry.tag.TagKey;
9+
import net.kyori.adventure.key.Key;
10+
import org.jspecify.annotations.NullMarked;
11+
12+
/**
13+
* Vanilla tag keys for {@link RegistryKey#POINT_OF_INTEREST_TYPE}.
14+
*
15+
* @apiNote The fields provided here are a direct representation of
16+
* what is available from the vanilla game source. They may be
17+
* changed (including removals) on any Minecraft version
18+
* bump, so cross-version compatibility is not provided on the
19+
* same level as it is on most of the other API.
20+
*/
21+
@SuppressWarnings({
22+
"unused",
23+
"SpellCheckingInspection"
24+
})
25+
@NullMarked
26+
@GeneratedClass
27+
public final class PoiTypeTagKeys {
28+
/**
29+
* {@code #minecraft:acquirable_job_site}
30+
*
31+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
32+
*/
33+
public static final TagKey<PoiType> ACQUIRABLE_JOB_SITE = create(key("acquirable_job_site"));
34+
35+
/**
36+
* {@code #minecraft:bee_home}
37+
*
38+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
39+
*/
40+
public static final TagKey<PoiType> BEE_HOME = create(key("bee_home"));
41+
42+
/**
43+
* {@code #minecraft:village}
44+
*
45+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
46+
*/
47+
public static final TagKey<PoiType> VILLAGE = create(key("village"));
48+
49+
private PoiTypeTagKeys() {
50+
}
51+
52+
/**
53+
* Creates a tag key for {@link PoiType} in the registry {@code minecraft:point_of_interest_type}.
54+
*
55+
* @param key the tag key's key
56+
* @return a new tag key
57+
*/
58+
public static TagKey<PoiType> create(final Key key) {
59+
return TagKey.create(RegistryKey.POINT_OF_INTEREST_TYPE, key);
60+
}
61+
}

paper-api/src/main/java/io/papermc/paper/InternalAPIBridge.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.destroystokyo.paper.SkinParts;
44
import io.papermc.paper.command.brigadier.CommandSourceStack;
55
import io.papermc.paper.datacomponent.item.ResolvableProfile;
6+
import io.papermc.paper.entity.poi.PoiType;
67
import io.papermc.paper.world.damagesource.CombatEntry;
78
import io.papermc.paper.world.damagesource.FallLocationType;
89
import java.util.Set;
@@ -52,6 +53,14 @@ class Holder {
5253
*/
5354
DamageEffect getDamageEffect(String key);
5455

56+
/**
57+
* Creates an occupancy instance for the passed enum entry name.
58+
*
59+
* @param enumNameEntry the enum entry
60+
* @return the occupancy
61+
*/
62+
PoiType.Occupancy createOccupancy(String enumNameEntry);
63+
5564
/**
5665
* Constructs the legacy custom biome instance for the biome enum.
5766
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.papermc.paper.entity.poi;
2+
3+
import java.util.function.Predicate;
4+
import org.bukkit.Location;
5+
import org.bukkit.World;
6+
import org.jspecify.annotations.NullMarked;
7+
8+
/**
9+
* Holds the result of searching for a point of interest.
10+
*
11+
* @see World#locateAllPoiInRange(Location, Predicate, int)
12+
* @see World#locateAllPoiInRange(Location, Predicate, int, PoiType.Occupancy)
13+
*/
14+
@NullMarked
15+
public interface PoiSearchResult {
16+
17+
/**
18+
* Returns the {@link PoiType}.
19+
*
20+
* @return the {@link PoiType}
21+
*/
22+
PoiType poiType();
23+
24+
/**
25+
* Return the location of the {@link PoiType}.
26+
*
27+
* @return the location the {@link PoiType} was found at
28+
*/
29+
Location location();
30+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package io.papermc.paper.entity.poi;
2+
3+
import io.papermc.paper.InternalAPIBridge;
4+
import org.bukkit.Keyed;
5+
import org.bukkit.block.data.BlockData;
6+
import org.jspecify.annotations.NullMarked;
7+
8+
/**
9+
* Represents a point of interest (POI).
10+
* <p>
11+
* Many PoiTypes act as a marker vs storing occupants examples of this are most
12+
* explicitly {@link PoiTypes#NETHER_PORTAL}. This state can be checked using the method
13+
* {@link #hasOccupants()} which will return {@code true} if the PoiType can have occupants.
14+
*
15+
* @see PoiTypes
16+
*/
17+
@NullMarked
18+
public interface PoiType extends Keyed {
19+
20+
/**
21+
* Determines whether the provided BlockState is relevant to this
22+
* point of interest.
23+
*
24+
* @param data the BlockData to check
25+
* @return {@code true} if the BlockState is relevant, otherwise {@code false}
26+
*/
27+
boolean is(BlockData data);
28+
29+
/**
30+
* Determines whether this PoiType can actually hold occupants.
31+
*
32+
* @return {@code true} if this PoiType can hold occupants
33+
*/
34+
boolean hasOccupants();
35+
36+
/**
37+
* Determines the type of occupancy the point of interest has.
38+
* <p>
39+
* A PoiType occupancy is defined by how much "space" a point of interest
40+
* has.
41+
* <p>
42+
* With context to a Villager workstation if a villager is currently using
43+
* a workstation as a source of its profession the occupancy would be
44+
* {@link Occupancy#IS_OCCUPIED}, however, if no villager was attached to
45+
* a workstation its occupancy would be {@link Occupancy#HAS_SPACE}.
46+
*/
47+
interface Occupancy {
48+
49+
/**
50+
* The poi has space.
51+
*/
52+
Occupancy HAS_SPACE = occupancy("HAS_SPACE");
53+
/**
54+
* The poi is occupied.
55+
*/
56+
Occupancy IS_OCCUPIED = occupancy("IS_OCCUPIED");
57+
/**
58+
* The poi is either occupied or has space.
59+
*/
60+
Occupancy ANY = occupancy("ANY");
61+
62+
private static Occupancy occupancy(final String enumEntryName) {
63+
return InternalAPIBridge.get().createOccupancy(enumEntryName);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)