Skip to content

Commit

Permalink
Lectern page tag/mech fix (#2598)
Browse files Browse the repository at this point in the history
* Guess who's back (:

* Updated deprecation stuff

* Update LocationTag.java

* Update LocationTag.java

* Update LocationTag.java
  • Loading branch information
heypr committed Mar 14, 2024
1 parent d88b22f commit 62e96a3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3681,13 +3681,30 @@ else if (PolygonTag.matches(attribute.getParam())) {
// @returns ElementTag(Number)
// @mechanism LocationTag.lectern_page
// @group world
// @deprecated Use 'LocationTag.page'
// @description
// Returns the current page on display in the book on this Lectern block.
// Deprecated in favor of <@link tag LocationTag.page>.
// -->
tagProcessor.registerTag(ElementTag.class, "lectern_page", (attribute, object) -> {
BukkitImplDeprecations.lecternPage.warn(attribute.context);
BlockState state = object.getBlockStateForTag(attribute);
if (state instanceof Lectern) {
return new ElementTag(((Lectern) state).getPage());
if (state instanceof Lectern lectern) {
return new ElementTag(lectern.getPage());
}
return null;
});

// <--[tag]
// @attribute <LocationTag.page>
// @returns ElementTag(Number)
// @mechanism LocationTag.page
// @group world
// @description
// Returns the current page on display in the book on this Lectern block.
// -->
tagProcessor.registerTag(ElementTag.class, "page", (attribute, object) -> {
if (object.getBlockState() instanceof Lectern lectern) {
return new ElementTag(lectern.getPage() + 1);
}
return null;
});
Expand Down Expand Up @@ -4524,6 +4541,28 @@ else if (mechanism.requireObject(EntityTag.class)) {
chiseledBookshelf.setLastInteractedSlot(input.asInt() - 1);
}
});

// <--[mechanism]
// @object LocationTag
// @name page
// @input ElementTag(Number)
// @description
// Sets the page currently displayed on the book in a lectern block.
// @tags
// <LocationTag.page>
// -->
tagProcessor.registerMechanism("page", false, ElementTag.class, (object, mechanism, input) -> {
if (!mechanism.requireInteger()) {
return;
}
if (object.getBlockState() instanceof Lectern lectern) {
lectern.setPage(input.asInt() - 1);
lectern.update();
}
else {
mechanism.echoError("The 'LocationTag.page' mechanism can only be called on a lectern block.");
}
});
}

public static final ObjectTagProcessor<LocationTag> tagProcessor = new ObjectTagProcessor<>();
Expand Down Expand Up @@ -5123,15 +5162,17 @@ else if (state instanceof Dropper) {
// @object LocationTag
// @name lectern_page
// @input ElementTag(Number)
// @deprecated Use LocationTag.page
// @description
// Changes the page currently displayed on the book in a lectern block.
// Deprecated in favor of <@link tag LocationTag.page>.
// @tags
// <LocationTag.lectern_page>
// -->
if (mechanism.matches("lectern_page") && mechanism.requireInteger()) {
BukkitImplDeprecations.lecternPage.warn(mechanism.context);
BlockState state = getBlockState();
if (state instanceof Lectern) {
((Lectern) state).setPage(mechanism.getValue().asInt());
if (state instanceof Lectern lectern) {
lectern.setPage(mechanism.getValue().asInt());
state.update();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ public class BukkitImplDeprecations {
// Added 2023/11/16, deprecate officially by 2027
public static Warning takeExperience = new FutureWarning("takeExperience", "Using the 'take' command to take experience is deprecated in favor of the 'experience' command.");

// Added 2024/02/19, deprecate officially by 2027.
public static Warning lecternPage = new FutureWarning("lecternPage", "'LocationTag.lectern_page' is deprecated in favor of 'LocationTag.page'.");

// ==================== PAST deprecations of things that are already gone but still have a warning left behind ====================

// Removed upstream 2023/10/29 without warning.
Expand Down

0 comments on commit 62e96a3

Please sign in to comment.