Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlayerTag.view_distance tag & mech #2694

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ public static void register() {
return map;
});

// <--[tag]
// @attribute <PlayerTag.view_distance>
// @returns ElementTag(Number)
// @mechanism PlayerTag.view_distance
// @group paper
// @Plugin Paper
// @description
// Returns this player's view distance, or the view distance of the world they're in if unset.
// -->
PlayerTag.registerOnlineOnlyTag(ElementTag.class, "view_distance", (attribute, object) -> {
return new ElementTag(object.getPlayerEntity().getViewDistance());
});

// <--[mechanism]
// @object PlayerTag
// @name affects_monster_spawning
Expand Down Expand Up @@ -136,6 +149,32 @@ public static void register() {
}
});

// <--[mechanism]
// @object PlayerTag
// @name view_distance
// @input ElementTag(Number)
// @Plugin Paper
// @group paper
// @description
// Sets this player's view distance. Input must be a number between 2 and 32.
// This will be reset when a player rejoins. Provide no input to unset.
// @tags
// <PlayerTag.view_distance>
// -->
PlayerTag.registerOnlineOnlyMechanism("view_distance", (object, mechanism) -> {
if (!mechanism.hasValue()) {
object.getPlayerEntity().setViewDistance(-1);
}
else if (mechanism.requireInteger()) {
int distance = mechanism.getValue().asInt();
if (distance < 2 || distance > 32) {
mechanism.echoError("Invalid view distance '" + distance + "': must be between 2 and 32.");
return;
}
object.getPlayerEntity().setViewDistance(distance);
}
});

if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {

// <--[tag]
Expand Down