Extend Jigsaw TileState - #14182
Conversation
There was a problem hiding this comment.
Pull request overview
Extends the Bukkit Jigsaw TileState API to expose and mutate key jigsaw configuration (target pool, name, target name) so plugins can inspect/adjust jigsaw block behavior more directly.
Changes:
- Adds new
NamespacedKey-based getters/setters toorg.bukkit.block.Jigsaw. - Implements the new API in
CraftJigsawby bridging between BukkitNamespacedKeyand NMS identifiers/resource keys.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java | Implements the new Jigsaw API by reading/writing NMS jigsaw fields and converting to/from NamespacedKey. |
| paper-api/src/main/java/org/bukkit/block/Jigsaw.java | Expands the public API surface for jigsaw tile states with getters/setters for pool/name/target. |
Suppressed comments (3)
paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java:49
- Avoid using Objects.nonNull(...) here; prefer a direct null check (or Preconditions.checkNotNull) for readability and to match existing CraftBukkit validation patterns.
public void setName(final @NotNull NamespacedKey name) {
Preconditions.checkArgument(Objects.nonNull(name), "name cannot be null");
getSnapshot().setName(CraftNamespacedKey.toMinecraft(name));
paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java:62
- Avoid using Objects.nonNull(...) here; prefer a direct null check (or Preconditions.checkNotNull) for readability and to match existing CraftBukkit validation patterns.
public void setTargetName(final @NotNull NamespacedKey targetName) {
Preconditions.checkArgument(Objects.nonNull(targetName), "targetName cannot be null");
getSnapshot().setTarget(CraftNamespacedKey.toMinecraft(targetName));
paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java:57
- Local variable name
targetPoolKeyis misleading here (this method reads the jigsaw's target name). Renaming improves clarity and reduces copy/paste confusion.
public NamespacedKey getTargetName() {
final Identifier targetPoolKey = this.getSnapshot().getTarget();
return CraftNamespacedKey.fromMinecraft(targetPoolKey);
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- prefer != null instead of Objects.nonNull - inconsistent variable naming - typos inside of javadoc
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java:13
- Unused import
java.util.Objectsis present but not referenced in this class. This is likely to fail formatting/checkstyle steps and should be removed.
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java:17
- Avoid static-importing NMS registry keys here; the surrounding codebase consistently references them via
Registries.*(e.g.CraftHumanEntityusesRegistries.RECIPE). Using a normal import keeps this file aligned with existing style and makes the registry origin clearer.
import static net.minecraft.core.registries.Registries.TEMPLATE_POOL;
public class CraftJigsaw extends CraftBlockEntityState<JigsawBlockEntity> implements Jigsaw {
public CraftJigsaw(World world, JigsawBlockEntity blockEntity) {
paper-api/src/main/java/org/bukkit/block/Jigsaw.java:15
- The javadocs refer to a "structure key", but this is actually the jigsaw's target pool (template pool) key. Tightening the wording helps avoid confusion about what registry this refers to.
/**
* Gets the target pool structure key.
*
* @return the {@link NamespacedKey} of the jigsaw's target pool.
*/
Currently there is no way to fetch information from the tilestate from jigsaw blocks. This PR extends the functionality of the Jigsaw tile state to allow fetching and changing of the target pool, target name and name. This allows Developers to use the jigsaw block to place own structures in a more profound way.
Arguably one could make the methods (setTargetPool(final @NotNull NamespacedKey targetPool), setName(final @NotNull NamespacedKey name) and void setTargetName(final @NotNull NamespacedKey targetName)) @nullable, and change the default Identifier in case of null to minecraft:empty (default value when placing a jigsaw). However this might be counterintuitive as developers default namespace is not minecraft, so I dont see any reason to change this. Also I haven't implemented the remaining options from the tilestate (joint, finalState, ...), this can be done using a different PR.
I've verified the changes using a small sample plugin. The Plugin intercepts the BlockPlacesEvent of an Jigsaw Block and prints the target pool, target name and name. Then it changes the target pool, target name and name using the setters and updates the tilestates. Afterwards it prints out the target pool, target name and name again. The output is plausible.