Skip to content

Commit 1220b0c

Browse files
authored
Add API for CreakingHeart (#12095)
1 parent a00ccce commit 1220b0c

3 files changed

Lines changed: 100 additions & 1 deletion

File tree

build-data/paper.at

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,10 @@ public net.minecraft.world.level.block.entity.ConduitBlockEntity effectBlocks
558558
public net.minecraft.world.level.block.entity.ConduitBlockEntity getDestroyRangeAABB(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/phys/AABB;
559559
public net.minecraft.world.level.block.entity.ConduitBlockEntity updateDestroyTarget(Lnet/minecraft/world/entity/EntityReference;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;Z)Lnet/minecraft/world/entity/EntityReference;
560560
public net.minecraft.world.level.block.entity.CrafterBlockEntity craftingTicksRemaining
561+
public net.minecraft.world.level.block.entity.CreakingHeartBlockEntity clearCreakingInfo()V
562+
public net.minecraft.world.level.block.entity.CreakingHeartBlockEntity getCreakingProtector()Ljava/util/Optional;
563+
public net.minecraft.world.level.block.entity.CreakingHeartBlockEntity spawnProtector(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/block/entity/CreakingHeartBlockEntity;)Lnet/minecraft/world/entity/monster/creaking/Creaking;
564+
public net.minecraft.world.level.block.entity.CreakingHeartBlockEntity spreadResin(Lnet/minecraft/server/level/ServerLevel;)Ljava/util/Optional;
561565
public net.minecraft.world.level.block.entity.DecoratedPotBlockEntity decorations
562566
public net.minecraft.world.level.block.entity.EnderChestBlockEntity openersCounter
563567
public net.minecraft.world.level.block.entity.HopperBlockEntity cooldownTime
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
package org.bukkit.block;
22

3+
import org.bukkit.Location;
4+
import org.bukkit.entity.Creaking;
5+
import org.jspecify.annotations.NullMarked;
6+
import org.jspecify.annotations.Nullable;
7+
38
/**
49
* Represents a captured state of a creaking heart.
510
*/
11+
@NullMarked
612
public interface CreakingHeart extends TileState {
13+
14+
/**
15+
* Gets the creaking protecting this creaking heart.
16+
*
17+
* @return the creaking, or {@code null} if this creaking heart doesn't have a protector.
18+
*/
19+
@Nullable Creaking getCreaking();
20+
21+
/**
22+
* Sets the creaking protecting this creaking heart.
23+
*
24+
* @param creaking the creaking, or {@code null} to remove any existing creaking.
25+
* @throws IllegalArgumentException if the creaking is in another world.
26+
* @throws IllegalStateException if this block state is not placed.
27+
*/
28+
void setCreaking(@Nullable Creaking creaking);
29+
30+
/**
31+
* Attempts to spawn a creaking to protect this creaking heart.
32+
*
33+
* @return the {@link Creaking} that was spawned to protect this heart, or {@code null} if it failed.
34+
* @throws IllegalStateException if this block state is not placed.
35+
*/
36+
@Nullable Creaking spawnCreaking();
37+
38+
/**
39+
* Attempts to spread resin to adjacent blocks.
40+
*
41+
* @apiNote This method triggers events related to a block being modified.
42+
* @return the location resin was spread to, or {@code null} if it failed to spread.
43+
* @throws IllegalStateException if this block state is not placed.
44+
*/
45+
@Nullable Location spreadResin();
746
}

paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftCreakingHeart.java

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package org.bukkit.craftbukkit.block;
22

3+
import com.google.common.base.Preconditions;
4+
import net.minecraft.server.level.ServerLevel;
35
import net.minecraft.world.level.block.entity.CreakingHeartBlockEntity;
46
import org.bukkit.Location;
57
import org.bukkit.World;
68
import org.bukkit.block.CreakingHeart;
9+
import org.bukkit.craftbukkit.entity.CraftCreaking;
10+
import org.bukkit.craftbukkit.util.CraftLocation;
11+
import org.bukkit.entity.Creaking;
12+
import org.jspecify.annotations.NullMarked;
13+
import org.jspecify.annotations.Nullable;
714

15+
@NullMarked
816
public class CraftCreakingHeart extends CraftBlockEntityState<CreakingHeartBlockEntity> implements CreakingHeart {
917

1018
public CraftCreakingHeart(World world, CreakingHeartBlockEntity blockEntity) {
1119
super(world, blockEntity);
1220
}
1321

14-
protected CraftCreakingHeart(CraftCreakingHeart state, Location location) {
22+
protected CraftCreakingHeart(CraftCreakingHeart state, @Nullable Location location) {
1523
super(state, location);
1624
}
1725

@@ -24,4 +32,52 @@ public CraftCreakingHeart copy() {
2432
public CraftCreakingHeart copy(Location location) {
2533
return new CraftCreakingHeart(this, location);
2634
}
35+
36+
@Override
37+
public @Nullable Creaking getCreaking() {
38+
if (!this.isPlaced()) {
39+
return null;
40+
}
41+
return this.getBlockEntity().getCreakingProtector().map(creaking -> ((Creaking) creaking.getBukkitEntity())).orElse(null);
42+
}
43+
44+
@Override
45+
public void setCreaking(final @Nullable Creaking creaking) {
46+
this.requirePlaced();
47+
if (creaking == null) {
48+
this.getBlockEntity().clearCreakingInfo();
49+
} else {
50+
Preconditions.checkArgument(this.getLocation().getWorld().equals(creaking.getLocation().getWorld()), "the location of the creaking must be in the same world as this CreakingHeart");
51+
this.getBlockEntity().setCreakingInfo(((CraftCreaking) creaking).getHandle());
52+
}
53+
}
54+
55+
@Nullable
56+
@Override
57+
public Creaking spawnCreaking() {
58+
this.requirePlaced();
59+
if (!(this.getBlockEntity().getLevel() instanceof ServerLevel serverLevel)) {
60+
return null;
61+
}
62+
63+
final net.minecraft.world.entity.monster.creaking.Creaking creaking = CreakingHeartBlockEntity.spawnProtector(serverLevel, this.getBlockEntity());
64+
if (creaking == null) {
65+
return null;
66+
}
67+
68+
this.getBlockEntity().setCreakingInfo(creaking);
69+
70+
return (Creaking) creaking.getBukkitEntity();
71+
}
72+
73+
@Nullable
74+
@Override
75+
public Location spreadResin() {
76+
this.requirePlaced();
77+
if (!(this.getBlockEntity().getLevel() instanceof ServerLevel serverLevel)) {
78+
return null;
79+
}
80+
81+
return this.getBlockEntity().spreadResin(serverLevel).map(blockPos -> CraftLocation.toBukkit(blockPos, this.getWorld())).orElse(null);
82+
}
2783
}

0 commit comments

Comments
 (0)