12
12
import net .minecraft .command .argument .BlockPosArgumentType ;
13
13
import net .minecraft .command .argument .EntityArgumentType ;
14
14
import net .minecraft .command .argument .GameProfileArgumentType ;
15
+ import net .minecraft .component .DataComponentTypes ;
16
+ import net .minecraft .component .type .ProfileComponent ;
15
17
import net .minecraft .item .ItemStack ;
16
18
import net .minecraft .item .Items ;
17
19
import net .minecraft .nbt .NbtCompound ;
@@ -94,11 +96,8 @@ private static int give(ServerCommandSource source, Collection<ServerPlayerEntit
94
96
95
97
for (ServerPlayerEntity player : targets ) {
96
98
for (GameProfile profile : profiles ) {
97
- final NbtCompound nbt = new NbtCompound ();
98
- nbt .putString ("SkullOwner" , profile .getName ());
99
-
100
99
final ItemStack stack = Items .PLAYER_HEAD .getDefaultStack ();
101
- stack .setNbt ( nbt );
100
+ stack .set ( DataComponentTypes . PROFILE , new ProfileComponent ( profile ) );
102
101
103
102
player .giveItemStack (stack );
104
103
i ++;
@@ -131,10 +130,10 @@ private static int queryUUID(ServerCommandSource source, BlockPos pos) {
131
130
ServerWorld world = source .getWorld ();
132
131
133
132
if (world .getBlockEntity (pos ) instanceof SkullBlockEntity head ) {
134
- GameProfile owner = head .getOwner ();
133
+ ProfileComponent owner = head .getOwner ();
135
134
136
135
if (owner != null ) {
137
- source .sendFeedback (() -> copyText ("commands.head.query.uuid.success" , owner .getId ().toString ()), false );
136
+ source .sendFeedback (() -> copyText ("commands.head.query.uuid.success" , owner .gameProfile (). getId ().toString ()), false );
138
137
i = 1 ;
139
138
}
140
139
}
@@ -148,10 +147,10 @@ private static int queryName(ServerCommandSource source, BlockPos pos) {
148
147
ServerWorld world = source .getWorld ();
149
148
150
149
if (world .getBlockEntity (pos ) instanceof SkullBlockEntity head ) {
151
- GameProfile owner = head .getOwner ();
150
+ ProfileComponent owner = head .getOwner ();
152
151
153
152
if (owner != null ) {
154
- source .sendFeedback (() -> copyText ("commands.head.query.name.success" , owner .getName ()), false );
153
+ source .sendFeedback (() -> copyText ("commands.head.query.name.success" , owner .gameProfile (). getName ()), false );
155
154
i = 1 ;
156
155
}
157
156
}
@@ -179,7 +178,7 @@ private static Text copyText(String key, String copyText) {
179
178
);
180
179
}
181
180
182
- private static int updateHead (ServerCommandSource source , BlockPos pos , GameProfile profile ) {
181
+ private static int updateHead (ServerCommandSource source , BlockPos pos , ProfileComponent profile ) {
183
182
int i = 0 ;
184
183
185
184
if (source .getWorld ().getBlockEntity (pos ) instanceof SkullBlockEntity entity ) {
@@ -192,7 +191,15 @@ private static int updateHead(ServerCommandSource source, BlockPos pos, GameProf
192
191
return i ;
193
192
}
194
193
194
+ private static int updateHead (ServerCommandSource source , BlockPos pos , GameProfile profile ) {
195
+ return updateHead (source , pos , new ProfileComponent (profile ));
196
+ }
197
+
195
198
private static int updateHead (ServerCommandSource source , BlockPos pos ) {
196
- return updateHead (source , pos , source .getPlayer ().getGameProfile ());
199
+ ServerPlayerEntity player = source .getPlayer ();
200
+
201
+ if (player == null ) return -1 ;
202
+
203
+ return updateHead (source , pos , player .getGameProfile ());
197
204
}
198
205
}
0 commit comments