1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
|
--- a/net/minecraft/server/commands/LootCommand.java
+++ b/net/minecraft/server/commands/LootCommand.java
@@ -4,16 +4,17 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.suggestion.SuggestionProvider;
-import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.Collection;
+import java.util.Iterator;
import java.util.List;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.commands.arguments.ResourceLocationArgument;
@@ -35,7 +36,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
-import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.storage.loot.LootDataManager;
import net.minecraft.world.level.storage.loot.LootDataType;
import net.minecraft.world.level.storage.loot.LootParams;
@@ -45,277 +46,114 @@
import net.minecraft.world.phys.Vec3;
public class LootCommand {
- public static final SuggestionProvider<CommandSourceStack> SUGGEST_LOOT_TABLE = (context, builder) -> {
- LootDataManager lootData = context.getSource().getServer().getLootData();
- return SharedSuggestionProvider.suggestResource(lootData.getKeys(LootDataType.TABLE), builder);
+
+ public static final SuggestionProvider<CommandSourceStack> SUGGEST_LOOT_TABLE = (commandcontext, suggestionsbuilder) -> {
+ LootDataManager lootdatamanager = ((CommandSourceStack) commandcontext.getSource()).getServer().getLootData();
+
+ return SharedSuggestionProvider.suggestResource((Iterable) lootdatamanager.getKeys(LootDataType.TABLE), suggestionsbuilder);
};
- private static final DynamicCommandExceptionType ERROR_NO_HELD_ITEMS = new DynamicCommandExceptionType(
- target -> Component.translatableEscape("commands.drop.no_held_items", target)
- );
- private static final DynamicCommandExceptionType ERROR_NO_LOOT_TABLE = new DynamicCommandExceptionType(
- target -> Component.translatableEscape("commands.drop.no_loot_table", target)
- );
+ private static final DynamicCommandExceptionType ERROR_NO_HELD_ITEMS = new DynamicCommandExceptionType((object) -> {
+ return Component.translatableEscape("commands.drop.no_held_items", object);
+ });
+ private static final DynamicCommandExceptionType ERROR_NO_LOOT_TABLE = new DynamicCommandExceptionType((object) -> {
+ return Component.translatableEscape("commands.drop.no_loot_table", object);
+ });
+ public LootCommand() {}
+
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
- dispatcher.register(
- addTargets(
- Commands.literal("loot").requires(source -> source.hasPermission(2)),
- (argumentBuilder, dropConsumer) -> argumentBuilder.then(
- Commands.literal("fish")
- .then(
- Commands.argument("loot_table", ResourceLocationArgument.id())
- .suggests(SUGGEST_LOOT_TABLE)
- .then(
- Commands.argument("pos", BlockPosArgument.blockPos())
- .executes(
- context1 -> dropFishingLoot(
- context1,
- ResourceLocationArgument.getId(context1, "loot_table"),
- BlockPosArgument.getLoadedBlockPos(context1, "pos"),
- ItemStack.EMPTY,
- dropConsumer
- )
- )
- .then(
- Commands.argument("tool", ItemArgument.item(context))
- .executes(
- context1 -> dropFishingLoot(
- context1,
- ResourceLocationArgument.getId(context1, "loot_table"),
- BlockPosArgument.getLoadedBlockPos(context1, "pos"),
- ItemArgument.getItem(context1, "tool").createItemStack(1, false),
- dropConsumer
- )
- )
- )
- .then(
- Commands.literal("mainhand")
- .executes(
- context1 -> dropFishingLoot(
- context1,
- ResourceLocationArgument.getId(context1, "loot_table"),
- BlockPosArgument.getLoadedBlockPos(context1, "pos"),
- getSourceHandItem(context1.getSource(), EquipmentSlot.MAINHAND),
- dropConsumer
- )
- )
- )
- .then(
- Commands.literal("offhand")
- .executes(
- context1 -> dropFishingLoot(
- context1,
- ResourceLocationArgument.getId(context1, "loot_table"),
- BlockPosArgument.getLoadedBlockPos(context1, "pos"),
- getSourceHandItem(context1.getSource(), EquipmentSlot.OFFHAND),
- dropConsumer
- )
- )
- )
- )
- )
- )
- .then(
- Commands.literal("loot")
- .then(
- Commands.argument("loot_table", ResourceLocationArgument.id())
- .suggests(SUGGEST_LOOT_TABLE)
- .executes(context1 -> dropChestLoot(context1, ResourceLocationArgument.getId(context1, "loot_table"), dropConsumer))
- )
- )
- .then(
- Commands.literal("kill")
- .then(
- Commands.argument("target", EntityArgument.entity())
- .executes(context1 -> dropKillLoot(context1, EntityArgument.getEntity(context1, "target"), dropConsumer))
- )
- )
- .then(
- Commands.literal("mine")
- .then(
- Commands.argument("pos", BlockPosArgument.blockPos())
- .executes(
- context1 -> dropBlockLoot(
- context1, BlockPosArgument.getLoadedBlockPos(context1, "pos"), ItemStack.EMPTY, dropConsumer
- )
- )
- .then(
- Commands.argument("tool", ItemArgument.item(context))
- .executes(
- context1 -> dropBlockLoot(
- context1,
- BlockPosArgument.getLoadedBlockPos(context1, "pos"),
- ItemArgument.getItem(context1, "tool").createItemStack(1, false),
- dropConsumer
- )
- )
- )
- .then(
- Commands.literal("mainhand")
- .executes(
- context1 -> dropBlockLoot(
- context1,
- BlockPosArgument.getLoadedBlockPos(context1, "pos"),
- getSourceHandItem(context1.getSource(), EquipmentSlot.MAINHAND),
- dropConsumer
- )
- )
- )
- .then(
- Commands.literal("offhand")
- .executes(
- context1 -> dropBlockLoot(
- context1,
- BlockPosArgument.getLoadedBlockPos(context1, "pos"),
- getSourceHandItem(context1.getSource(), EquipmentSlot.OFFHAND),
- dropConsumer
- )
- )
- )
- )
- )
- )
- );
+ dispatcher.register((LiteralArgumentBuilder) addTargets((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("loot").requires((commandlistenerwrapper) -> {
+ return commandlistenerwrapper.hasPermission(2);
+ }), (argumentbuilder, commandloot_b) -> {
+ return argumentbuilder.then(net.minecraft.commands.Commands.literal("fish").then(net.minecraft.commands.Commands.argument("loot_table", ResourceLocationArgument.id()).suggests(LootCommand.SUGGEST_LOOT_TABLE).then(((RequiredArgumentBuilder) ((RequiredArgumentBuilder) ((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+ return dropFishingLoot(commandcontext, ResourceLocationArgument.getId(commandcontext, "loot_table"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), ItemStack.EMPTY, commandloot_b);
+ })).then(net.minecraft.commands.Commands.argument("tool", ItemArgument.item(context)).executes((commandcontext) -> {
+ return dropFishingLoot(commandcontext, ResourceLocationArgument.getId(commandcontext, "loot_table"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), ItemArgument.getItem(commandcontext, "tool").createItemStack(1, false), commandloot_b);
+ }))).then(net.minecraft.commands.Commands.literal("mainhand").executes((commandcontext) -> {
+ return dropFishingLoot(commandcontext, ResourceLocationArgument.getId(commandcontext, "loot_table"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), getSourceHandItem((CommandSourceStack) commandcontext.getSource(), EquipmentSlot.MAINHAND), commandloot_b);
+ }))).then(net.minecraft.commands.Commands.literal("offhand").executes((commandcontext) -> {
+ return dropFishingLoot(commandcontext, ResourceLocationArgument.getId(commandcontext, "loot_table"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), getSourceHandItem((CommandSourceStack) commandcontext.getSource(), EquipmentSlot.OFFHAND), commandloot_b);
+ }))))).then(net.minecraft.commands.Commands.literal("loot").then(net.minecraft.commands.Commands.argument("loot_table", ResourceLocationArgument.id()).suggests(LootCommand.SUGGEST_LOOT_TABLE).executes((commandcontext) -> {
+ return dropChestLoot(commandcontext, ResourceLocationArgument.getId(commandcontext, "loot_table"), commandloot_b);
+ }))).then(net.minecraft.commands.Commands.literal("kill").then(net.minecraft.commands.Commands.argument("target", EntityArgument.entity()).executes((commandcontext) -> {
+ return dropKillLoot(commandcontext, EntityArgument.getEntity(commandcontext, "target"), commandloot_b);
+ }))).then(net.minecraft.commands.Commands.literal("mine").then(((RequiredArgumentBuilder) ((RequiredArgumentBuilder) ((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+ return dropBlockLoot(commandcontext, BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), ItemStack.EMPTY, commandloot_b);
+ })).then(net.minecraft.commands.Commands.argument("tool", ItemArgument.item(context)).executes((commandcontext) -> {
+ return dropBlockLoot(commandcontext, BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), ItemArgument.getItem(commandcontext, "tool").createItemStack(1, false), commandloot_b);
+ }))).then(net.minecraft.commands.Commands.literal("mainhand").executes((commandcontext) -> {
+ return dropBlockLoot(commandcontext, BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), getSourceHandItem((CommandSourceStack) commandcontext.getSource(), EquipmentSlot.MAINHAND), commandloot_b);
+ }))).then(net.minecraft.commands.Commands.literal("offhand").executes((commandcontext) -> {
+ return dropBlockLoot(commandcontext, BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), getSourceHandItem((CommandSourceStack) commandcontext.getSource(), EquipmentSlot.OFFHAND), commandloot_b);
+ }))));
+ }));
}
private static <T extends ArgumentBuilder<CommandSourceStack, T>> T addTargets(T builder, LootCommand.TailProvider tailProvider) {
- return builder.then(
- Commands.literal("replace")
- .then(
- Commands.literal("entity")
- .then(
- Commands.argument("entities", EntityArgument.entities())
- .then(
- tailProvider.construct(
- Commands.argument("slot", SlotArgument.slot()),
- (context, items, callback) -> entityReplace(
- EntityArgument.getEntities(context, "entities"),
- SlotArgument.getSlot(context, "slot"),
- items.size(),
- items,
- callback
- )
- )
- .then(
- tailProvider.construct(
- Commands.argument("count", IntegerArgumentType.integer(0)),
- (context, items, callback) -> entityReplace(
- EntityArgument.getEntities(context, "entities"),
- SlotArgument.getSlot(context, "slot"),
- IntegerArgumentType.getInteger(context, "count"),
- items,
- callback
- )
- )
- )
- )
- )
- )
- .then(
- Commands.literal("block")
- .then(
- Commands.argument("targetPos", BlockPosArgument.blockPos())
- .then(
- tailProvider.construct(
- Commands.argument("slot", SlotArgument.slot()),
- (context, items, callback) -> blockReplace(
- context.getSource(),
- BlockPosArgument.getLoadedBlockPos(context, "targetPos"),
- SlotArgument.getSlot(context, "slot"),
- items.size(),
- items,
- callback
- )
- )
- .then(
- tailProvider.construct(
- Commands.argument("count", IntegerArgumentType.integer(0)),
- (context, items, callback) -> blockReplace(
- context.getSource(),
- BlockPosArgument.getLoadedBlockPos(context, "targetPos"),
- IntegerArgumentType.getInteger(context, "slot"),
- IntegerArgumentType.getInteger(context, "count"),
- items,
- callback
- )
- )
- )
- )
- )
- )
- )
- .then(
- Commands.literal("insert")
- .then(
- tailProvider.construct(
- Commands.argument("targetPos", BlockPosArgument.blockPos()),
- (context, items, callback) -> blockDistribute(
- context.getSource(), BlockPosArgument.getLoadedBlockPos(context, "targetPos"), items, callback
- )
- )
- )
- )
- .then(
- Commands.literal("give")
- .then(
- tailProvider.construct(
- Commands.argument("players", EntityArgument.players()),
- (context, items, callback) -> playerGive(EntityArgument.getPlayers(context, "players"), items, callback)
- )
- )
- )
- .then(
- Commands.literal("spawn")
- .then(
- tailProvider.construct(
- Commands.argument("targetPos", Vec3Argument.vec3()),
- (context, items, callback) -> dropInWorld(context.getSource(), Vec3Argument.getVec3(context, "targetPos"), items, callback)
- )
- )
- );
+ return (T) builder.then(((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("replace").then(net.minecraft.commands.Commands.literal("entity").then(net.minecraft.commands.Commands.argument("entities", EntityArgument.entities()).then(tailProvider.construct(net.minecraft.commands.Commands.argument("slot", SlotArgument.slot()), (commandcontext, list, commandloot_a) -> { // CraftBukkit - decompile error
+ return entityReplace(EntityArgument.getEntities(commandcontext, "entities"), SlotArgument.getSlot(commandcontext, "slot"), list.size(), list, commandloot_a);
+ }).then(tailProvider.construct(net.minecraft.commands.Commands.argument("count", IntegerArgumentType.integer(0)), (commandcontext, list, commandloot_a) -> {
+ return entityReplace(EntityArgument.getEntities(commandcontext, "entities"), SlotArgument.getSlot(commandcontext, "slot"), IntegerArgumentType.getInteger(commandcontext, "count"), list, commandloot_a);
+ })))))).then(net.minecraft.commands.Commands.literal("block").then(net.minecraft.commands.Commands.argument("targetPos", BlockPosArgument.blockPos()).then(tailProvider.construct(net.minecraft.commands.Commands.argument("slot", SlotArgument.slot()), (commandcontext, list, commandloot_a) -> {
+ return blockReplace((CommandSourceStack) commandcontext.getSource(), BlockPosArgument.getLoadedBlockPos(commandcontext, "targetPos"), SlotArgument.getSlot(commandcontext, "slot"), list.size(), list, commandloot_a);
+ }).then(tailProvider.construct(net.minecraft.commands.Commands.argument("count", IntegerArgumentType.integer(0)), (commandcontext, list, commandloot_a) -> {
+ return blockReplace((CommandSourceStack) commandcontext.getSource(), BlockPosArgument.getLoadedBlockPos(commandcontext, "targetPos"), IntegerArgumentType.getInteger(commandcontext, "slot"), IntegerArgumentType.getInteger(commandcontext, "count"), list, commandloot_a);
+ })))))).then(net.minecraft.commands.Commands.literal("insert").then(tailProvider.construct(net.minecraft.commands.Commands.argument("targetPos", BlockPosArgument.blockPos()), (commandcontext, list, commandloot_a) -> {
+ return blockDistribute((CommandSourceStack) commandcontext.getSource(), BlockPosArgument.getLoadedBlockPos(commandcontext, "targetPos"), list, commandloot_a);
+ }))).then(net.minecraft.commands.Commands.literal("give").then(tailProvider.construct(net.minecraft.commands.Commands.argument("players", EntityArgument.players()), (commandcontext, list, commandloot_a) -> {
+ return playerGive(EntityArgument.getPlayers(commandcontext, "players"), list, commandloot_a);
+ }))).then(net.minecraft.commands.Commands.literal("spawn").then(tailProvider.construct(net.minecraft.commands.Commands.argument("targetPos", Vec3Argument.vec3()), (commandcontext, list, commandloot_a) -> {
+ return dropInWorld((CommandSourceStack) commandcontext.getSource(), Vec3Argument.getVec3(commandcontext, "targetPos"), list, commandloot_a);
+ })));
}
private static Container getContainer(CommandSourceStack source, BlockPos pos) throws CommandSyntaxException {
- BlockEntity blockEntity = source.getLevel().getBlockEntity(pos);
- if (!(blockEntity instanceof Container)) {
+ BlockEntity tileentity = source.getLevel().getBlockEntity(pos);
+
+ if (!(tileentity instanceof Container)) {
throw ItemCommands.ERROR_TARGET_NOT_A_CONTAINER.create(pos.getX(), pos.getY(), pos.getZ());
} else {
- return (Container)blockEntity;
+ return (Container) tileentity;
}
}
private static int blockDistribute(CommandSourceStack source, BlockPos pos, List<ItemStack> items, LootCommand.Callback callback) throws CommandSyntaxException {
- Container container = getContainer(source, pos);
- List<ItemStack> list = Lists.newArrayListWithCapacity(items.size());
+ Container iinventory = getContainer(source, pos);
+ List<ItemStack> list1 = Lists.newArrayListWithCapacity(items.size());
+ Iterator iterator = items.iterator();
- for (ItemStack itemStack : items) {
- if (distributeToContainer(container, itemStack.copy())) {
- container.setChanged();
- list.add(itemStack);
+ while (iterator.hasNext()) {
+ ItemStack itemstack = (ItemStack) iterator.next();
+
+ if (distributeToContainer(iinventory, itemstack.copy())) {
+ iinventory.setChanged();
+ list1.add(itemstack);
}
}
- callback.accept(list);
- return list.size();
+ callback.accept(list1);
+ return list1.size();
}
private static boolean distributeToContainer(Container container, ItemStack item) {
boolean flag = false;
- for (int i = 0; i < container.getContainerSize() && !item.isEmpty(); i++) {
- ItemStack item1 = container.getItem(i);
+ for (int i = 0; i < container.getContainerSize() && !item.isEmpty(); ++i) {
+ ItemStack itemstack1 = container.getItem(i);
+
if (container.canPlaceItem(i, item)) {
- if (item1.isEmpty()) {
+ if (itemstack1.isEmpty()) {
container.setItem(i, item);
flag = true;
break;
}
- if (canMergeItems(item1, item)) {
- int i1 = item.getMaxStackSize() - item1.getCount();
- int min = Math.min(item.getCount(), i1);
- item.shrink(min);
- item1.grow(min);
+ if (canMergeItems(itemstack1, item)) {
+ int j = item.getMaxStackSize() - itemstack1.getCount();
+ int k = Math.min(item.getCount(), j);
+
+ item.shrink(k);
+ itemstack1.grow(k);
flag = true;
}
}
@@ -325,22 +163,24 @@
}
private static int blockReplace(CommandSourceStack source, BlockPos pos, int slot, int numSlots, List<ItemStack> items, LootCommand.Callback callback) throws CommandSyntaxException {
- Container container = getContainer(source, pos);
- int containerSize = container.getContainerSize();
- if (slot >= 0 && slot < containerSize) {
- List<ItemStack> list = Lists.newArrayListWithCapacity(items.size());
+ Container iinventory = getContainer(source, pos);
+ int k = iinventory.getContainerSize();
- for (int i = 0; i < numSlots; i++) {
- int i1 = slot + i;
- ItemStack itemStack = i < items.size() ? items.get(i) : ItemStack.EMPTY;
- if (container.canPlaceItem(i1, itemStack)) {
- container.setItem(i1, itemStack);
- list.add(itemStack);
+ if (slot >= 0 && slot < k) {
+ List<ItemStack> list1 = Lists.newArrayListWithCapacity(items.size());
+
+ for (int l = 0; l < numSlots; ++l) {
+ int i1 = slot + l;
+ ItemStack itemstack = l < items.size() ? (ItemStack) items.get(l) : ItemStack.EMPTY;
+
+ if (iinventory.canPlaceItem(i1, itemstack)) {
+ iinventory.setItem(i1, itemstack);
+ list1.add(itemstack);
}
}
- callback.accept(list);
- return list.size();
+ callback.accept(list1);
+ return list1.size();
} else {
throw ItemCommands.ERROR_TARGET_INAPPLICABLE_SLOT.create(slot);
}
@@ -351,52 +191,68 @@
}
private static int playerGive(Collection<ServerPlayer> targets, List<ItemStack> items, LootCommand.Callback callback) throws CommandSyntaxException {
- List<ItemStack> list = Lists.newArrayListWithCapacity(items.size());
+ List<ItemStack> list1 = Lists.newArrayListWithCapacity(items.size());
+ Iterator iterator = items.iterator();
- for (ItemStack itemStack : items) {
- for (ServerPlayer serverPlayer : targets) {
- if (serverPlayer.getInventory().add(itemStack.copy())) {
- list.add(itemStack);
+ while (iterator.hasNext()) {
+ ItemStack itemstack = (ItemStack) iterator.next();
+ Iterator iterator1 = targets.iterator();
+
+ while (iterator1.hasNext()) {
+ ServerPlayer entityplayer = (ServerPlayer) iterator1.next();
+
+ if (entityplayer.getInventory().add(itemstack.copy())) {
+ list1.add(itemstack);
}
}
}
- callback.accept(list);
- return list.size();
+ callback.accept(list1);
+ return list1.size();
}
private static void setSlots(Entity target, List<ItemStack> items, int startSlot, int numSlots, List<ItemStack> setItems) {
- for (int i = 0; i < numSlots; i++) {
- ItemStack itemStack = i < items.size() ? items.get(i) : ItemStack.EMPTY;
- SlotAccess slot = target.getSlot(startSlot + i);
- if (slot != SlotAccess.NULL && slot.set(itemStack.copy())) {
- setItems.add(itemStack);
+ for (int k = 0; k < numSlots; ++k) {
+ ItemStack itemstack = k < items.size() ? (ItemStack) items.get(k) : ItemStack.EMPTY;
+ SlotAccess slotaccess = target.getSlot(startSlot + k);
+
+ if (slotaccess != SlotAccess.NULL && slotaccess.set(itemstack.copy())) {
+ setItems.add(itemstack);
}
}
+
}
private static int entityReplace(Collection<? extends Entity> targets, int startSlot, int numSlots, List<ItemStack> items, LootCommand.Callback callback) throws CommandSyntaxException {
- List<ItemStack> list = Lists.newArrayListWithCapacity(items.size());
+ List<ItemStack> list1 = Lists.newArrayListWithCapacity(items.size());
+ Iterator iterator = targets.iterator();
- for (Entity entity : targets) {
- if (entity instanceof ServerPlayer serverPlayer) {
- setSlots(entity, items, startSlot, numSlots, list);
- serverPlayer.containerMenu.broadcastChanges();
+ while (iterator.hasNext()) {
+ Entity entity = (Entity) iterator.next();
+
+ if (entity instanceof ServerPlayer) {
+ ServerPlayer entityplayer = (ServerPlayer) entity;
+
+ setSlots(entity, items, startSlot, numSlots, list1);
+ entityplayer.containerMenu.broadcastChanges();
} else {
- setSlots(entity, items, startSlot, numSlots, list);
+ setSlots(entity, items, startSlot, numSlots, list1);
}
}
- callback.accept(list);
- return list.size();
+ callback.accept(list1);
+ return list1.size();
}
private static int dropInWorld(CommandSourceStack source, Vec3 pos, List<ItemStack> items, LootCommand.Callback callback) throws CommandSyntaxException {
- ServerLevel level = source.getLevel();
- items.forEach(itemStack -> {
- ItemEntity itemEntity = new ItemEntity(level, pos.x, pos.y, pos.z, itemStack.copy());
- itemEntity.setDefaultPickUpDelay();
- level.addFreshEntity(itemEntity);
+ ServerLevel worldserver = source.getLevel();
+
+ items.removeIf(ItemStack::isEmpty); // CraftBukkit - SPIGOT-6959 Remove empty items for avoid throw an error in new EntityItem
+ items.forEach((itemstack) -> {
+ ItemEntity entityitem = new ItemEntity(worldserver, pos.x, pos.y, pos.z, itemstack.copy());
+
+ entityitem.setDefaultPickUpDelay();
+ worldserver.addFreshEntity(entityitem);
});
callback.accept(items);
return items.size();
@@ -404,117 +260,126 @@
private static void callback(CommandSourceStack source, List<ItemStack> items) {
if (items.size() == 1) {
- ItemStack itemStack = items.get(0);
- source.sendSuccess(() -> Component.translatable("commands.drop.success.single", itemStack.getCount(), itemStack.getDisplayName()), false);
+ ItemStack itemstack = (ItemStack) items.get(0);
+
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.drop.success.single", itemstack.getCount(), itemstack.getDisplayName());
+ }, false);
} else {
- source.sendSuccess(() -> Component.translatable("commands.drop.success.multiple", items.size()), false);
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.drop.success.multiple", items.size());
+ }, false);
}
+
}
private static void callback(CommandSourceStack source, List<ItemStack> items, ResourceLocation lootTable) {
if (items.size() == 1) {
- ItemStack itemStack = items.get(0);
- source.sendSuccess(
- () -> Component.translatable(
- "commands.drop.success.single_with_table", itemStack.getCount(), itemStack.getDisplayName(), Component.translationArg(lootTable)
- ),
- false
- );
+ ItemStack itemstack = (ItemStack) items.get(0);
+
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.drop.success.single_with_table", itemstack.getCount(), itemstack.getDisplayName(), Component.translationArg(lootTable));
+ }, false);
} else {
- source.sendSuccess(
- () -> Component.translatable("commands.drop.success.multiple_with_table", items.size(), Component.translationArg(lootTable)), false
- );
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.drop.success.multiple_with_table", items.size(), Component.translationArg(lootTable));
+ }, false);
}
+
}
private static ItemStack getSourceHandItem(CommandSourceStack source, EquipmentSlot slot) throws CommandSyntaxException {
- Entity entityOrException = source.getEntityOrException();
- if (entityOrException instanceof LivingEntity) {
- return ((LivingEntity)entityOrException).getItemBySlot(slot);
+ Entity entity = source.getEntityOrException();
+
+ if (entity instanceof LivingEntity) {
+ return ((LivingEntity) entity).getItemBySlot(slot);
} else {
- throw ERROR_NO_HELD_ITEMS.create(entityOrException.getDisplayName());
+ throw LootCommand.ERROR_NO_HELD_ITEMS.create(entity.getDisplayName());
}
}
private static int dropBlockLoot(CommandContext<CommandSourceStack> context, BlockPos pos, ItemStack tool, LootCommand.DropConsumer dropConsumer) throws CommandSyntaxException {
- CommandSourceStack commandSourceStack = context.getSource();
- ServerLevel level = commandSourceStack.getLevel();
- BlockState blockState = level.getBlockState(pos);
- BlockEntity blockEntity = level.getBlockEntity(pos);
- LootParams.Builder builder = new LootParams.Builder(level)
- .withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
- .withParameter(LootContextParams.BLOCK_STATE, blockState)
- .withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity)
- .withOptionalParameter(LootContextParams.THIS_ENTITY, commandSourceStack.getEntity())
- .withParameter(LootContextParams.TOOL, tool);
- List<ItemStack> drops = blockState.getDrops(builder);
- return dropConsumer.accept(context, drops, itemsDropped -> callback(commandSourceStack, itemsDropped, blockState.getBlock().getLootTable()));
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource();
+ ServerLevel worldserver = commandlistenerwrapper.getLevel();
+ IBlockData iblockdata = worldserver.getBlockState(pos);
+ BlockEntity tileentity = worldserver.getBlockEntity(pos);
+ LootParams.Builder lootparams_a = (new LootParams.Builder(worldserver)).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos)).withParameter(LootContextParams.BLOCK_STATE, iblockdata).withOptionalParameter(LootContextParams.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParams.THIS_ENTITY, commandlistenerwrapper.getEntity()).withParameter(LootContextParams.TOOL, tool);
+ List<ItemStack> list = iblockdata.getDrops(lootparams_a);
+
+ return dropConsumer.accept(context, list, (list1) -> {
+ callback(commandlistenerwrapper, list1, iblockdata.getBlock().getLootTable());
+ });
}
private static int dropKillLoot(CommandContext<CommandSourceStack> context, Entity entity, LootCommand.DropConsumer dropConsumer) throws CommandSyntaxException {
if (!(entity instanceof LivingEntity)) {
- throw ERROR_NO_LOOT_TABLE.create(entity.getDisplayName());
+ throw LootCommand.ERROR_NO_LOOT_TABLE.create(entity.getDisplayName());
} else {
- ResourceLocation lootTable = ((LivingEntity)entity).getLootTable();
- CommandSourceStack commandSourceStack = context.getSource();
- LootParams.Builder builder = new LootParams.Builder(commandSourceStack.getLevel());
- Entity entity1 = commandSourceStack.getEntity();
- if (entity1 instanceof Player player) {
- builder.withParameter(LootContextParams.LAST_DAMAGE_PLAYER, player);
+ ResourceLocation minecraftkey = ((LivingEntity) entity).getLootTable();
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource();
+ LootParams.Builder lootparams_a = new LootParams.Builder(commandlistenerwrapper.getLevel());
+ Entity entity1 = commandlistenerwrapper.getEntity();
+
+ if (entity1 instanceof Player) {
+ Player entityhuman = (Player) entity1;
+
+ lootparams_a.withParameter(LootContextParams.LAST_DAMAGE_PLAYER, entityhuman);
}
- builder.withParameter(LootContextParams.DAMAGE_SOURCE, entity.damageSources().magic());
- builder.withOptionalParameter(LootContextParams.DIRECT_KILLER_ENTITY, entity1);
- builder.withOptionalParameter(LootContextParams.KILLER_ENTITY, entity1);
- builder.withParameter(LootContextParams.THIS_ENTITY, entity);
- builder.withParameter(LootContextParams.ORIGIN, commandSourceStack.getPosition());
- LootParams lootParams = builder.create(LootContextParamSets.ENTITY);
- LootTable lootTable1 = commandSourceStack.getServer().getLootData().getLootTable(lootTable);
- List<ItemStack> randomItems = lootTable1.getRandomItems(lootParams);
- return dropConsumer.accept(context, randomItems, itemsDropped -> callback(commandSourceStack, itemsDropped, lootTable));
+ lootparams_a.withParameter(LootContextParams.DAMAGE_SOURCE, entity.damageSources().magic());
+ lootparams_a.withOptionalParameter(LootContextParams.DIRECT_KILLER_ENTITY, entity1);
+ lootparams_a.withOptionalParameter(LootContextParams.KILLER_ENTITY, entity1);
+ lootparams_a.withParameter(LootContextParams.THIS_ENTITY, entity);
+ lootparams_a.withParameter(LootContextParams.ORIGIN, commandlistenerwrapper.getPosition());
+ LootParams lootparams = lootparams_a.create(LootContextParamSets.ENTITY);
+ LootTable loottable = commandlistenerwrapper.getServer().getLootData().getLootTable(minecraftkey);
+ List<ItemStack> list = loottable.getRandomItems(lootparams);
+
+ return dropConsumer.accept(context, list, (list1) -> {
+ callback(commandlistenerwrapper, list1, minecraftkey);
+ });
}
}
private static int dropChestLoot(CommandContext<CommandSourceStack> context, ResourceLocation lootTable, LootCommand.DropConsumer dropConsumer) throws CommandSyntaxException {
- CommandSourceStack commandSourceStack = context.getSource();
- LootParams lootParams = new LootParams.Builder(commandSourceStack.getLevel())
- .withOptionalParameter(LootContextParams.THIS_ENTITY, commandSourceStack.getEntity())
- .withParameter(LootContextParams.ORIGIN, commandSourceStack.getPosition())
- .create(LootContextParamSets.CHEST);
- return drop(context, lootTable, lootParams, dropConsumer);
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource();
+ LootParams lootparams = (new LootParams.Builder(commandlistenerwrapper.getLevel())).withOptionalParameter(LootContextParams.THIS_ENTITY, commandlistenerwrapper.getEntity()).withParameter(LootContextParams.ORIGIN, commandlistenerwrapper.getPosition()).create(LootContextParamSets.CHEST);
+
+ return drop(context, lootTable, lootparams, dropConsumer);
}
- private static int dropFishingLoot(
- CommandContext<CommandSourceStack> context, ResourceLocation lootTable, BlockPos pos, ItemStack tool, LootCommand.DropConsumer dropConsumer
- ) throws CommandSyntaxException {
- CommandSourceStack commandSourceStack = context.getSource();
- LootParams lootParams = new LootParams.Builder(commandSourceStack.getLevel())
- .withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos))
- .withParameter(LootContextParams.TOOL, tool)
- .withOptionalParameter(LootContextParams.THIS_ENTITY, commandSourceStack.getEntity())
- .create(LootContextParamSets.FISHING);
- return drop(context, lootTable, lootParams, dropConsumer);
+ private static int dropFishingLoot(CommandContext<CommandSourceStack> context, ResourceLocation lootTable, BlockPos pos, ItemStack tool, LootCommand.DropConsumer dropConsumer) throws CommandSyntaxException {
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource();
+ LootParams lootparams = (new LootParams.Builder(commandlistenerwrapper.getLevel())).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos)).withParameter(LootContextParams.TOOL, tool).withOptionalParameter(LootContextParams.THIS_ENTITY, commandlistenerwrapper.getEntity()).create(LootContextParamSets.FISHING);
+
+ return drop(context, lootTable, lootparams, dropConsumer);
}
private static int drop(CommandContext<CommandSourceStack> context, ResourceLocation lootTable, LootParams params, LootCommand.DropConsumer dropConsumer) throws CommandSyntaxException {
- CommandSourceStack commandSourceStack = context.getSource();
- LootTable lootTable1 = commandSourceStack.getServer().getLootData().getLootTable(lootTable);
- List<ItemStack> randomItems = lootTable1.getRandomItems(params);
- return dropConsumer.accept(context, randomItems, itemsDropped -> callback(commandSourceStack, itemsDropped));
+ CommandSourceStack commandlistenerwrapper = (CommandSourceStack) context.getSource();
+ LootTable loottable = commandlistenerwrapper.getServer().getLootData().getLootTable(lootTable);
+ List<ItemStack> list = loottable.getRandomItems(params);
+
+ return dropConsumer.accept(context, list, (list1) -> {
+ callback(commandlistenerwrapper, list1);
+ });
}
@FunctionalInterface
- interface Callback {
- void accept(List<ItemStack> items) throws CommandSyntaxException;
+ private interface TailProvider {
+
+ ArgumentBuilder<CommandSourceStack, ?> construct(ArgumentBuilder<CommandSourceStack, ?> builder, LootCommand.DropConsumer dropConsumer);
}
@FunctionalInterface
- interface DropConsumer {
+ private interface DropConsumer {
+
int accept(CommandContext<CommandSourceStack> context, List<ItemStack> items, LootCommand.Callback callback) throws CommandSyntaxException;
}
@FunctionalInterface
- interface TailProvider {
- ArgumentBuilder<CommandSourceStack, ?> construct(ArgumentBuilder<CommandSourceStack, ?> builder, LootCommand.DropConsumer dropConsumer);
+ private interface Callback {
+
+ void accept(List<ItemStack> items) throws CommandSyntaxException;
}
}
|