aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/server/commands/SummonCommand.java.patch
blob: fb70452a26dc1f98249b97506cbe2183d4ca56da (plain)
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
--- a/net/minecraft/server/commands/SummonCommand.java
+++ b/net/minecraft/server/commands/SummonCommand.java
@@ -1,12 +1,12 @@
 package net.minecraft.server.commands;
 
 import com.mojang.brigadier.CommandDispatcher;
-import com.mojang.brigadier.context.CommandContext;
+import com.mojang.brigadier.builder.LiteralArgumentBuilder;
+import com.mojang.brigadier.builder.RequiredArgumentBuilder;
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
 import net.minecraft.commands.CommandBuildContext;
 import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
 import net.minecraft.commands.arguments.CompoundTagArgument;
 import net.minecraft.commands.arguments.ResourceArgument;
 import net.minecraft.commands.arguments.coordinates.Vec3Argument;
@@ -19,82 +19,56 @@
 import net.minecraft.server.level.ServerLevel;
 import net.minecraft.world.entity.Entity;
 import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.entity.EnumMobSpawn;
+import net.minecraft.world.entity.GroupDataEntity;
 import net.minecraft.world.entity.Mob;
-import net.minecraft.world.entity.MobSpawnType;
 import net.minecraft.world.level.Level;
 import net.minecraft.world.phys.Vec3;
 
 public class SummonCommand {
+
     private static final SimpleCommandExceptionType ERROR_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.summon.failed"));
     private static final SimpleCommandExceptionType ERROR_DUPLICATE_UUID = new SimpleCommandExceptionType(Component.translatable("commands.summon.failed.uuid"));
     private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(Component.translatable("commands.summon.invalidPosition"));
 
+    public SummonCommand() {}
+
     public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
-        dispatcher.register(
-            Commands.literal("summon")
-                .requires(source -> source.hasPermission(2))
-                .then(
-                    Commands.argument("entity", ResourceArgument.resource(context, Registries.ENTITY_TYPE))
-                        .suggests(SuggestionProviders.SUMMONABLE_ENTITIES)
-                        .executes(
-                            context1 -> spawnEntity(
-                                    context1.getSource(),
-                                    ResourceArgument.getSummonableEntityType(context1, "entity"),
-                                    context1.getSource().getPosition(),
-                                    new CompoundTag(),
-                                    true
-                                )
-                        )
-                        .then(
-                            Commands.argument("pos", Vec3Argument.vec3())
-                                .executes(
-                                    context1 -> spawnEntity(
-                                            context1.getSource(),
-                                            ResourceArgument.getSummonableEntityType(context1, "entity"),
-                                            Vec3Argument.getVec3(context1, "pos"),
-                                            new CompoundTag(),
-                                            true
-                                        )
-                                )
-                                .then(
-                                    Commands.argument("nbt", CompoundTagArgument.compoundTag())
-                                        .executes(
-                                            context1 -> spawnEntity(
-                                                    context1.getSource(),
-                                                    ResourceArgument.getSummonableEntityType(context1, "entity"),
-                                                    Vec3Argument.getVec3(context1, "pos"),
-                                                    CompoundTagArgument.getCompoundTag(context1, "nbt"),
-                                                    false
-                                                )
-                                        )
-                                )
-                        )
-                )
-        );
+        dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("summon").requires((commandlistenerwrapper) -> {
+            return commandlistenerwrapper.hasPermission(2);
+        })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("entity", ResourceArgument.resource(context, Registries.ENTITY_TYPE)).suggests(SuggestionProviders.SUMMONABLE_ENTITIES).executes((commandcontext) -> {
+            return spawnEntity((CommandSourceStack) commandcontext.getSource(), ResourceArgument.getSummonableEntityType(commandcontext, "entity"), ((CommandSourceStack) commandcontext.getSource()).getPosition(), new CompoundTag(), true);
+        })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("pos", Vec3Argument.vec3()).executes((commandcontext) -> {
+            return spawnEntity((CommandSourceStack) commandcontext.getSource(), ResourceArgument.getSummonableEntityType(commandcontext, "entity"), Vec3Argument.getVec3(commandcontext, "pos"), new CompoundTag(), true);
+        })).then(net.minecraft.commands.Commands.argument("nbt", CompoundTagArgument.compoundTag()).executes((commandcontext) -> {
+            return spawnEntity((CommandSourceStack) commandcontext.getSource(), ResourceArgument.getSummonableEntityType(commandcontext, "entity"), Vec3Argument.getVec3(commandcontext, "pos"), CompoundTagArgument.getCompoundTag(commandcontext, "nbt"), false);
+        })))));
     }
 
     public static Entity createEntity(CommandSourceStack source, Holder.Reference<EntityType<?>> type, Vec3 pos, CompoundTag tag, boolean randomizeProperties) throws CommandSyntaxException {
-        BlockPos blockPos = BlockPos.containing(pos);
-        if (!Level.isInSpawnableBounds(blockPos)) {
-            throw INVALID_POSITION.create();
+        BlockPos blockposition = BlockPos.containing(pos);
+
+        if (!Level.isInSpawnableBounds(blockposition)) {
+            throw SummonCommand.INVALID_POSITION.create();
         } else {
-            CompoundTag compoundTag = tag.copy();
-            compoundTag.putString("id", type.key().location().toString());
-            ServerLevel level = source.getLevel();
-            Entity entity = EntityType.loadEntityRecursive(compoundTag, level, entity1 -> {
+            CompoundTag nbttagcompound1 = tag.copy();
+
+            nbttagcompound1.putString("id", type.key().location().toString());
+            ServerLevel worldserver = source.getLevel();
+            Entity entity = EntityType.loadEntityRecursive(nbttagcompound1, worldserver, (entity1) -> {
                 entity1.moveTo(pos.x, pos.y, pos.z, entity1.getYRot(), entity1.getXRot());
                 return entity1;
             });
+
             if (entity == null) {
-                throw ERROR_FAILED.create();
+                throw SummonCommand.ERROR_FAILED.create();
             } else {
                 if (randomizeProperties && entity instanceof Mob) {
-                    ((Mob)entity)
-                        .finalizeSpawn(source.getLevel(), source.getLevel().getCurrentDifficultyAt(entity.blockPosition()), MobSpawnType.COMMAND, null, null);
+                    ((Mob) entity).finalizeSpawn(source.getLevel(), source.getLevel().getCurrentDifficultyAt(entity.blockPosition()), EnumMobSpawn.COMMAND, (GroupDataEntity) null, (CompoundTag) null);
                 }
 
-                if (!level.tryAddFreshEntityWithPassengers(entity)) {
-                    throw ERROR_DUPLICATE_UUID.create();
+                if (!worldserver.tryAddFreshEntityWithPassengers(entity, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.COMMAND)) { // CraftBukkit - pass a spawn reason of "COMMAND"
+                    throw SummonCommand.ERROR_DUPLICATE_UUID.create();
                 } else {
                     return entity;
                 }
@@ -104,7 +78,10 @@
 
     private static int spawnEntity(CommandSourceStack source, Holder.Reference<EntityType<?>> type, Vec3 pos, CompoundTag tag, boolean randomizeProperties) throws CommandSyntaxException {
         Entity entity = createEntity(source, type, pos, tag, randomizeProperties);
-        source.sendSuccess(() -> Component.translatable("commands.summon.success", entity.getDisplayName()), true);
+
+        source.sendSuccess(() -> {
+            return Component.translatable("commands.summon.success", entity.getDisplayName());
+        }, true);
         return 1;
     }
 }