Skip to content
Open
Show file tree
Hide file tree
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
52 changes: 51 additions & 1 deletion paper-api/src/main/java/org/bukkit/block/Jigsaw.java
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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<JigsawBlockEntity> implements Jigsaw {

Expand All @@ -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);
Expand Down