Skip to content

Commit f49d18d

Browse files
authored
Add get/set customName to Skull block (#12302)
1 parent 7cc6cb5 commit f49d18d

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

build-data/paper.at

+1
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ public net.minecraft.world.level.block.entity.SculkSensorBlockEntity lastVibrati
605605
public net.minecraft.world.level.block.entity.SculkShriekerBlockEntity warningLevel
606606
public net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity openCount
607607
public net.minecraft.world.level.block.entity.SignBlockEntity playerWhoMayEdit
608+
public net.minecraft.world.level.block.entity.SkullBlockEntity customName
608609
public net.minecraft.world.level.block.entity.SkullBlockEntity noteBlockSound
609610
public net.minecraft.world.level.block.entity.SkullBlockEntity owner
610611
public net.minecraft.world.level.block.entity.StructureBlockEntity author

paper-api/src/main/java/org/bukkit/block/Skull.java

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bukkit.block;
22

3+
import net.kyori.adventure.text.Component;
34
import org.bukkit.Material;
45
import org.bukkit.NamespacedKey;
56
import org.bukkit.OfflinePlayer;
@@ -168,4 +169,24 @@ public interface Skull extends TileState {
168169
@Deprecated(since = "1.13", forRemoval = true)
169170
@Contract("_ -> fail")
170171
public void setSkullType(SkullType skullType);
172+
173+
/**
174+
* Get the custom name of skull.
175+
* <p>This name is set when placing a skull item that has a custom name.
176+
* This name is only carried back to the item when broken for player heads
177+
* (skeleton/creeper heads will not retain the name).</p>
178+
*
179+
* @return Custom name of skull
180+
*/
181+
public @Nullable Component customName();
182+
183+
/**
184+
* Set the custom name of skull.
185+
* <p>This name is set when placing a skull item that has a custom name.
186+
* This name is only carried back to the item when broken for player heads
187+
* (skeleton/creeper heads will not retain the name).</p>
188+
*
189+
* @param customName Custom name of skull
190+
*/
191+
public void customName(@Nullable Component customName);
171192
}

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

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.google.common.base.Preconditions;
44
import com.mojang.authlib.GameProfile;
5+
import io.papermc.paper.adventure.PaperAdventure;
6+
import net.kyori.adventure.text.Component;
57
import net.minecraft.Util;
68
import net.minecraft.resources.ResourceLocation;
79
import net.minecraft.server.MinecraftServer;
@@ -216,4 +218,16 @@ public CraftSkull copy() {
216218
public CraftSkull copy(Location location) {
217219
return new CraftSkull(this, location);
218220
}
221+
222+
@Override
223+
public @Nullable Component customName() {
224+
SkullBlockEntity snapshot = getSnapshot();
225+
return snapshot.customName == null ? null : PaperAdventure.asAdventure(snapshot.customName);
226+
}
227+
228+
@Override
229+
public void customName(@Nullable Component customName) {
230+
SkullBlockEntity snapshot = getSnapshot();
231+
snapshot.customName = customName == null ? null : PaperAdventure.asVanilla(customName);
232+
}
219233
}

0 commit comments

Comments
 (0)