diff --git a/paper-api/src/main/java/org/bukkit/block/Jigsaw.java b/paper-api/src/main/java/org/bukkit/block/Jigsaw.java index 02c7fa58ec4a..e5b7672d8eec 100644 --- a/paper-api/src/main/java/org/bukkit/block/Jigsaw.java +++ b/paper-api/src/main/java/org/bukkit/block/Jigsaw.java @@ -1,6 +1,56 @@ package org.bukkit.block; +import org.bukkit.NamespacedKey; +import org.jetbrains.annotations.NotNull; + /** * Represents a captured state of a jigsaw. */ -public interface Jigsaw extends TileState { } +public interface Jigsaw extends TileState { + + /** + * Gets the target pool structure key. + * + * @return the {@link NamespacedKey} of the jigsaw's target pool. + */ + @NotNull + NamespacedKey getTargetPool(); + + /** + * Sets the target pool structure key. + * + * @param targetPool the key of target pool + */ + void setTargetPool(@NotNull NamespacedKey targetPool); + + /** + * Gets the name of the jigsaw block. + * + * @return The NamespacedKey of the jigsaw block + */ + @NotNull + NamespacedKey getName(); + + /** + * Sets the name of the jigsaw block. + * + * @param name the name of the jigsaw block + */ + void setName(@NotNull NamespacedKey name); + + /** + * Gets the target name of the jigsaw block. + * + * @return The NamespacedKey of the jigsaw's target name + */ + @NotNull + NamespacedKey getTargetName(); + + /** + * Sets the target name of the jigsaw block. + * + * @param targetName the target name of the jigsaw block + */ + void setTargetName(@NotNull NamespacedKey targetName); + +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java index 1c9d54fc516f..a79239045bc6 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftJigsaw.java @@ -1,9 +1,16 @@ package org.bukkit.craftbukkit.block; +import com.google.common.base.Preconditions; +import net.minecraft.resources.Identifier; import net.minecraft.world.level.block.entity.JigsawBlockEntity; import org.bukkit.Location; +import org.bukkit.NamespacedKey; import org.bukkit.World; import org.bukkit.block.Jigsaw; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.jetbrains.annotations.NotNull; + +import static net.minecraft.core.registries.Registries.TEMPLATE_POOL; public class CraftJigsaw extends CraftBlockEntityState implements Jigsaw { @@ -15,6 +22,45 @@ protected CraftJigsaw(CraftJigsaw state, Location location) { super(state, location); } + @Override + @NotNull + public NamespacedKey getTargetPool() { + final Identifier targetPoolKey = getSnapshot().getPool().identifier(); + return CraftNamespacedKey.fromMinecraft(targetPoolKey); + } + + @Override + public void setTargetPool(final @NotNull NamespacedKey targetPool) { + Preconditions.checkArgument(targetPool != null, "targetPool cannot be null"); + getSnapshot().setPool(CraftNamespacedKey.toResourceKey(TEMPLATE_POOL, targetPool)); + } + + @Override + @NotNull + public NamespacedKey getName() { + final Identifier nameKey = this.getSnapshot().getName(); + return CraftNamespacedKey.fromMinecraft(nameKey); + } + + @Override + public void setName(final @NotNull NamespacedKey name) { + Preconditions.checkArgument(name != null, "name cannot be null"); + getSnapshot().setName(CraftNamespacedKey.toMinecraft(name)); + } + + @Override + @NotNull + public NamespacedKey getTargetName() { + final Identifier targetNameKey = this.getSnapshot().getTarget(); + return CraftNamespacedKey.fromMinecraft(targetNameKey); + } + + @Override + public void setTargetName(final @NotNull NamespacedKey targetName) { + Preconditions.checkArgument(targetName != null, "targetName cannot be null"); + getSnapshot().setTarget(CraftNamespacedKey.toMinecraft(targetName)); + } + @Override public CraftJigsaw copy() { return new CraftJigsaw(this, null);