aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower/net/minecraft/server/commands/PlaceCommand.java.patch
blob: 6a92ffd458d8ab51e4d00f38777dc4c3dad8f143 (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
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
--- a/net/minecraft/server/commands/PlaceCommand.java
+++ b/net/minecraft/server/commands/PlaceCommand.java
@@ -12,7 +12,6 @@
 import java.util.Optional;
 import net.minecraft.ResourceLocationException;
 import net.minecraft.commands.CommandSourceStack;
-import net.minecraft.commands.Commands;
 import net.minecraft.commands.SharedSuggestionProvider;
 import net.minecraft.commands.arguments.ResourceKeyArgument;
 import net.minecraft.commands.arguments.ResourceLocationArgument;
@@ -59,135 +58,136 @@
 
     public PlaceCommand() {}
 
-    public static void register(CommandDispatcher<CommandSourceStack> commanddispatcher) {
-        commanddispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) Commands.literal("place").requires((commandsourcestack) -> {
-            return commandsourcestack.hasPermission(2);
-        })).then(Commands.literal("feature").then(((RequiredArgumentBuilder) Commands.argument("feature", ResourceKeyArgument.key(Registries.CONFIGURED_FEATURE)).executes((commandcontext) -> {
+    public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
+        dispatcher.register((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) ((LiteralArgumentBuilder) net.minecraft.commands.Commands.literal("place").requires((commandlistenerwrapper) -> {
+            return commandlistenerwrapper.hasPermission(2);
+        })).then(net.minecraft.commands.Commands.literal("feature").then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("feature", ResourceKeyArgument.key(Registries.CONFIGURED_FEATURE)).executes((commandcontext) -> {
             return placeFeature((CommandSourceStack) commandcontext.getSource(), ResourceKeyArgument.getConfiguredFeature(commandcontext, "feature"), BlockPos.containing(((CommandSourceStack) commandcontext.getSource()).getPosition()));
-        })).then(Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+        })).then(net.minecraft.commands.Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
             return placeFeature((CommandSourceStack) commandcontext.getSource(), ResourceKeyArgument.getConfiguredFeature(commandcontext, "feature"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"));
-        }))))).then(Commands.literal("jigsaw").then(Commands.argument("pool", ResourceKeyArgument.key(Registries.TEMPLATE_POOL)).then(Commands.argument("target", ResourceLocationArgument.id()).then(((RequiredArgumentBuilder) Commands.argument("max_depth", IntegerArgumentType.integer(1, 7)).executes((commandcontext) -> {
+        }))))).then(net.minecraft.commands.Commands.literal("jigsaw").then(net.minecraft.commands.Commands.argument("pool", ResourceKeyArgument.key(Registries.TEMPLATE_POOL)).then(net.minecraft.commands.Commands.argument("target", ResourceLocationArgument.id()).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("max_depth", IntegerArgumentType.integer(1, 7)).executes((commandcontext) -> {
             return placeJigsaw((CommandSourceStack) commandcontext.getSource(), ResourceKeyArgument.getStructureTemplatePool(commandcontext, "pool"), ResourceLocationArgument.getId(commandcontext, "target"), IntegerArgumentType.getInteger(commandcontext, "max_depth"), BlockPos.containing(((CommandSourceStack) commandcontext.getSource()).getPosition()));
-        })).then(Commands.argument("position", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+        })).then(net.minecraft.commands.Commands.argument("position", BlockPosArgument.blockPos()).executes((commandcontext) -> {
             return placeJigsaw((CommandSourceStack) commandcontext.getSource(), ResourceKeyArgument.getStructureTemplatePool(commandcontext, "pool"), ResourceLocationArgument.getId(commandcontext, "target"), IntegerArgumentType.getInteger(commandcontext, "max_depth"), BlockPosArgument.getLoadedBlockPos(commandcontext, "position"));
-        }))))))).then(Commands.literal("structure").then(((RequiredArgumentBuilder) Commands.argument("structure", ResourceKeyArgument.key(Registries.STRUCTURE)).executes((commandcontext) -> {
+        }))))))).then(net.minecraft.commands.Commands.literal("structure").then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("structure", ResourceKeyArgument.key(Registries.STRUCTURE)).executes((commandcontext) -> {
             return placeStructure((CommandSourceStack) commandcontext.getSource(), ResourceKeyArgument.getStructure(commandcontext, "structure"), BlockPos.containing(((CommandSourceStack) commandcontext.getSource()).getPosition()));
-        })).then(Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+        })).then(net.minecraft.commands.Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
             return placeStructure((CommandSourceStack) commandcontext.getSource(), ResourceKeyArgument.getStructure(commandcontext, "structure"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"));
-        }))))).then(Commands.literal("template").then(((RequiredArgumentBuilder) Commands.argument("template", ResourceLocationArgument.id()).suggests(PlaceCommand.SUGGEST_TEMPLATES).executes((commandcontext) -> {
+        }))))).then(net.minecraft.commands.Commands.literal("template").then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("template", ResourceLocationArgument.id()).suggests(PlaceCommand.SUGGEST_TEMPLATES).executes((commandcontext) -> {
             return placeTemplate((CommandSourceStack) commandcontext.getSource(), ResourceLocationArgument.getId(commandcontext, "template"), BlockPos.containing(((CommandSourceStack) commandcontext.getSource()).getPosition()), Rotation.NONE, Mirror.NONE, 1.0F, 0);
-        })).then(((RequiredArgumentBuilder) Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+        })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
             return placeTemplate((CommandSourceStack) commandcontext.getSource(), ResourceLocationArgument.getId(commandcontext, "template"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), Rotation.NONE, Mirror.NONE, 1.0F, 0);
-        })).then(((RequiredArgumentBuilder) Commands.argument("rotation", TemplateRotationArgument.templateRotation()).executes((commandcontext) -> {
+        })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("rotation", TemplateRotationArgument.templateRotation()).executes((commandcontext) -> {
             return placeTemplate((CommandSourceStack) commandcontext.getSource(), ResourceLocationArgument.getId(commandcontext, "template"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), TemplateRotationArgument.getRotation(commandcontext, "rotation"), Mirror.NONE, 1.0F, 0);
-        })).then(((RequiredArgumentBuilder) Commands.argument("mirror", TemplateMirrorArgument.templateMirror()).executes((commandcontext) -> {
+        })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("mirror", TemplateMirrorArgument.templateMirror()).executes((commandcontext) -> {
             return placeTemplate((CommandSourceStack) commandcontext.getSource(), ResourceLocationArgument.getId(commandcontext, "template"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), TemplateRotationArgument.getRotation(commandcontext, "rotation"), TemplateMirrorArgument.getMirror(commandcontext, "mirror"), 1.0F, 0);
-        })).then(((RequiredArgumentBuilder) Commands.argument("integrity", FloatArgumentType.floatArg(0.0F, 1.0F)).executes((commandcontext) -> {
+        })).then(((RequiredArgumentBuilder) net.minecraft.commands.Commands.argument("integrity", FloatArgumentType.floatArg(0.0F, 1.0F)).executes((commandcontext) -> {
             return placeTemplate((CommandSourceStack) commandcontext.getSource(), ResourceLocationArgument.getId(commandcontext, "template"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), TemplateRotationArgument.getRotation(commandcontext, "rotation"), TemplateMirrorArgument.getMirror(commandcontext, "mirror"), FloatArgumentType.getFloat(commandcontext, "integrity"), 0);
-        })).then(Commands.argument("seed", IntegerArgumentType.integer()).executes((commandcontext) -> {
+        })).then(net.minecraft.commands.Commands.argument("seed", IntegerArgumentType.integer()).executes((commandcontext) -> {
             return placeTemplate((CommandSourceStack) commandcontext.getSource(), ResourceLocationArgument.getId(commandcontext, "template"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"), TemplateRotationArgument.getRotation(commandcontext, "rotation"), TemplateMirrorArgument.getMirror(commandcontext, "mirror"), FloatArgumentType.getFloat(commandcontext, "integrity"), IntegerArgumentType.getInteger(commandcontext, "seed"));
         })))))))));
     }
 
-    public static int placeFeature(CommandSourceStack commandsourcestack, Holder.Reference<ConfiguredFeature<?, ?>> holder_reference, BlockPos blockpos) throws CommandSyntaxException {
-        ServerLevel serverlevel = commandsourcestack.getLevel();
-        ConfiguredFeature<?, ?> configuredfeature = (ConfiguredFeature) holder_reference.value();
-        ChunkPos chunkpos = new ChunkPos(blockpos);
+    public static int placeFeature(CommandSourceStack source, Holder.Reference<ConfiguredFeature<?, ?>> feature, BlockPos pos) throws CommandSyntaxException {
+        ServerLevel worldserver = source.getLevel();
+        ConfiguredFeature<?, ?> worldgenfeatureconfigured = (ConfiguredFeature) feature.value();
+        ChunkPos chunkcoordintpair = new ChunkPos(pos);
 
-        checkLoaded(serverlevel, new ChunkPos(chunkpos.x - 1, chunkpos.z - 1), new ChunkPos(chunkpos.x + 1, chunkpos.z + 1));
-        if (!configuredfeature.place(serverlevel, serverlevel.getChunkSource().getGenerator(), serverlevel.getRandom(), blockpos)) {
+        checkLoaded(worldserver, new ChunkPos(chunkcoordintpair.x - 1, chunkcoordintpair.z - 1), new ChunkPos(chunkcoordintpair.x + 1, chunkcoordintpair.z + 1));
+        if (!worldgenfeatureconfigured.place(worldserver, worldserver.getChunkSource().getGenerator(), worldserver.getRandom(), pos)) {
             throw PlaceCommand.ERROR_FEATURE_FAILED.create();
         } else {
-            String s = holder_reference.key().location().toString();
+            String s = feature.key().location().toString();
 
-            commandsourcestack.sendSuccess(() -> {
-                return Component.translatable("commands.place.feature.success", s, blockpos.getX(), blockpos.getY(), blockpos.getZ());
+            source.sendSuccess(() -> {
+                return Component.translatable("commands.place.feature.success", s, pos.getX(), pos.getY(), pos.getZ());
             }, true);
             return 1;
         }
     }
 
-    public static int placeJigsaw(CommandSourceStack commandsourcestack, Holder<StructureTemplatePool> holder, ResourceLocation resourcelocation, int i, BlockPos blockpos) throws CommandSyntaxException {
-        ServerLevel serverlevel = commandsourcestack.getLevel();
+    public static int placeJigsaw(CommandSourceStack source, Holder<StructureTemplatePool> templatePool, ResourceLocation target, int maxDepth, BlockPos pos) throws CommandSyntaxException {
+        ServerLevel worldserver = source.getLevel();
 
-        if (!JigsawPlacement.generateJigsaw(serverlevel, holder, resourcelocation, i, blockpos, false)) {
+        if (!JigsawPlacement.generateJigsaw(worldserver, templatePool, target, maxDepth, pos, false)) {
             throw PlaceCommand.ERROR_JIGSAW_FAILED.create();
         } else {
-            commandsourcestack.sendSuccess(() -> {
-                return Component.translatable("commands.place.jigsaw.success", blockpos.getX(), blockpos.getY(), blockpos.getZ());
+            source.sendSuccess(() -> {
+                return Component.translatable("commands.place.jigsaw.success", pos.getX(), pos.getY(), pos.getZ());
             }, true);
             return 1;
         }
     }
 
-    public static int placeStructure(CommandSourceStack commandsourcestack, Holder.Reference<Structure> holder_reference, BlockPos blockpos) throws CommandSyntaxException {
-        ServerLevel serverlevel = commandsourcestack.getLevel();
-        Structure structure = (Structure) holder_reference.value();
-        ChunkGenerator chunkgenerator = serverlevel.getChunkSource().getGenerator();
-        StructureStart structurestart = structure.generate(commandsourcestack.registryAccess(), chunkgenerator, chunkgenerator.getBiomeSource(), serverlevel.getChunkSource().randomState(), serverlevel.getStructureManager(), serverlevel.getSeed(), new ChunkPos(blockpos), 0, serverlevel, (holder) -> {
+    public static int placeStructure(CommandSourceStack source, Holder.Reference<Structure> structure, BlockPos pos) throws CommandSyntaxException {
+        ServerLevel worldserver = source.getLevel();
+        Structure structure1 = (Structure) structure.value();
+        ChunkGenerator chunkgenerator = worldserver.getChunkSource().getGenerator();
+        StructureStart structurestart = structure1.generate(source.registryAccess(), chunkgenerator, chunkgenerator.getBiomeSource(), worldserver.getChunkSource().randomState(), worldserver.getStructureManager(), worldserver.getSeed(), new ChunkPos(pos), 0, worldserver, (holder) -> {
             return true;
         });
 
         if (!structurestart.isValid()) {
             throw PlaceCommand.ERROR_STRUCTURE_FAILED.create();
         } else {
-            BoundingBox boundingbox = structurestart.getBoundingBox();
-            ChunkPos chunkpos = new ChunkPos(SectionPos.blockToSectionCoord(boundingbox.minX()), SectionPos.blockToSectionCoord(boundingbox.minZ()));
-            ChunkPos chunkpos1 = new ChunkPos(SectionPos.blockToSectionCoord(boundingbox.maxX()), SectionPos.blockToSectionCoord(boundingbox.maxZ()));
+            structurestart.generationEventCause = org.bukkit.event.world.AsyncStructureGenerateEvent.Cause.COMMAND; // CraftBukkit - set AsyncStructureGenerateEvent.Cause.COMMAND as generation cause
+            BoundingBox structureboundingbox = structurestart.getBoundingBox();
+            ChunkPos chunkcoordintpair = new ChunkPos(SectionPos.blockToSectionCoord(structureboundingbox.minX()), SectionPos.blockToSectionCoord(structureboundingbox.minZ()));
+            ChunkPos chunkcoordintpair1 = new ChunkPos(SectionPos.blockToSectionCoord(structureboundingbox.maxX()), SectionPos.blockToSectionCoord(structureboundingbox.maxZ()));
 
-            checkLoaded(serverlevel, chunkpos, chunkpos1);
-            ChunkPos.rangeClosed(chunkpos, chunkpos1).forEach((chunkpos2) -> {
-                structurestart.placeInChunk(serverlevel, serverlevel.structureManager(), chunkgenerator, serverlevel.getRandom(), new BoundingBox(chunkpos2.getMinBlockX(), serverlevel.getMinBuildHeight(), chunkpos2.getMinBlockZ(), chunkpos2.getMaxBlockX(), serverlevel.getMaxBuildHeight(), chunkpos2.getMaxBlockZ()), chunkpos2);
+            checkLoaded(worldserver, chunkcoordintpair, chunkcoordintpair1);
+            ChunkPos.rangeClosed(chunkcoordintpair, chunkcoordintpair1).forEach((chunkcoordintpair2) -> {
+                structurestart.placeInChunk(worldserver, worldserver.structureManager(), chunkgenerator, worldserver.getRandom(), new BoundingBox(chunkcoordintpair2.getMinBlockX(), worldserver.getMinBuildHeight(), chunkcoordintpair2.getMinBlockZ(), chunkcoordintpair2.getMaxBlockX(), worldserver.getMaxBuildHeight(), chunkcoordintpair2.getMaxBlockZ()), chunkcoordintpair2);
             });
-            String s = holder_reference.key().location().toString();
+            String s = structure.key().location().toString();
 
-            commandsourcestack.sendSuccess(() -> {
-                return Component.translatable("commands.place.structure.success", s, blockpos.getX(), blockpos.getY(), blockpos.getZ());
+            source.sendSuccess(() -> {
+                return Component.translatable("commands.place.structure.success", s, pos.getX(), pos.getY(), pos.getZ());
             }, true);
             return 1;
         }
     }
 
-    public static int placeTemplate(CommandSourceStack commandsourcestack, ResourceLocation resourcelocation, BlockPos blockpos, Rotation rotation, Mirror mirror, float f, int i) throws CommandSyntaxException {
-        ServerLevel serverlevel = commandsourcestack.getLevel();
-        StructureTemplateManager structuretemplatemanager = serverlevel.getStructureManager();
+    public static int placeTemplate(CommandSourceStack source, ResourceLocation template, BlockPos pos, Rotation rotation, Mirror mirror, float integrity, int seed) throws CommandSyntaxException {
+        ServerLevel worldserver = source.getLevel();
+        StructureTemplateManager structuretemplatemanager = worldserver.getStructureManager();
 
         Optional optional;
 
         try {
-            optional = structuretemplatemanager.get(resourcelocation);
-        } catch (ResourceLocationException resourcelocationexception) {
-            throw PlaceCommand.ERROR_TEMPLATE_INVALID.create(resourcelocation);
+            optional = structuretemplatemanager.get(template);
+        } catch (ResourceLocationException resourcekeyinvalidexception) {
+            throw PlaceCommand.ERROR_TEMPLATE_INVALID.create(template);
         }
 
         if (optional.isEmpty()) {
-            throw PlaceCommand.ERROR_TEMPLATE_INVALID.create(resourcelocation);
+            throw PlaceCommand.ERROR_TEMPLATE_INVALID.create(template);
         } else {
-            StructureTemplate structuretemplate = (StructureTemplate) optional.get();
+            StructureTemplate definedstructure = (StructureTemplate) optional.get();
 
-            checkLoaded(serverlevel, new ChunkPos(blockpos), new ChunkPos(blockpos.offset(structuretemplate.getSize())));
-            StructurePlaceSettings structureplacesettings = (new StructurePlaceSettings()).setMirror(mirror).setRotation(rotation);
+            checkLoaded(worldserver, new ChunkPos(pos), new ChunkPos(pos.offset(definedstructure.getSize())));
+            StructurePlaceSettings definedstructureinfo = (new StructurePlaceSettings()).setMirror(mirror).setRotation(rotation);
 
-            if (f < 1.0F) {
-                structureplacesettings.clearProcessors().addProcessor(new BlockRotProcessor(f)).setRandom(StructureBlockEntity.createRandom((long) i));
+            if (integrity < 1.0F) {
+                definedstructureinfo.clearProcessors().addProcessor(new BlockRotProcessor(integrity)).setRandom(StructureBlockEntity.createRandom((long) seed));
             }
 
-            boolean flag = structuretemplate.placeInWorld(serverlevel, blockpos, blockpos, structureplacesettings, StructureBlockEntity.createRandom((long) i), 2);
+            boolean flag = definedstructure.placeInWorld(worldserver, pos, pos, definedstructureinfo, StructureBlockEntity.createRandom((long) seed), 2);
 
             if (!flag) {
                 throw PlaceCommand.ERROR_TEMPLATE_FAILED.create();
             } else {
-                commandsourcestack.sendSuccess(() -> {
-                    return Component.translatable("commands.place.template.success", Component.translationArg(resourcelocation), blockpos.getX(), blockpos.getY(), blockpos.getZ());
+                source.sendSuccess(() -> {
+                    return Component.translatable("commands.place.template.success", Component.translationArg(template), pos.getX(), pos.getY(), pos.getZ());
                 }, true);
                 return 1;
             }
         }
     }
 
-    private static void checkLoaded(ServerLevel serverlevel, ChunkPos chunkpos, ChunkPos chunkpos1) throws CommandSyntaxException {
-        if (ChunkPos.rangeClosed(chunkpos, chunkpos1).filter((chunkpos2) -> {
-            return !serverlevel.isLoaded(chunkpos2.getWorldPosition());
+    private static void checkLoaded(ServerLevel level, ChunkPos start, ChunkPos end) throws CommandSyntaxException {
+        if (ChunkPos.rangeClosed(start, end).filter((chunkcoordintpair2) -> {
+            return !level.isLoaded(chunkcoordintpair2.getWorldPosition());
         }).findAny().isPresent()) {
             throw BlockPosArgument.ERROR_NOT_LOADED.create();
         }