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
|
--- a/net/minecraft/server/commands/PlaceCommand.java
+++ b/net/minecraft/server/commands/PlaceCommand.java
@@ -3,16 +3,15 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
-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.DynamicCommandExceptionType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.SuggestionProvider;
-import com.mojang.brigadier.suggestion.SuggestionsBuilder;
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;
@@ -43,309 +42,153 @@
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplateManager;
public class PlaceCommand {
- private static final SimpleCommandExceptionType ERROR_FEATURE_FAILED = new SimpleCommandExceptionType(
- Component.translatable("commands.place.feature.failed")
- );
+
+ private static final SimpleCommandExceptionType ERROR_FEATURE_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.place.feature.failed"));
private static final SimpleCommandExceptionType ERROR_JIGSAW_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.place.jigsaw.failed"));
- private static final SimpleCommandExceptionType ERROR_STRUCTURE_FAILED = new SimpleCommandExceptionType(
- Component.translatable("commands.place.structure.failed")
- );
- private static final DynamicCommandExceptionType ERROR_TEMPLATE_INVALID = new DynamicCommandExceptionType(
- template -> Component.translatableEscape("commands.place.template.invalid", template)
- );
- private static final SimpleCommandExceptionType ERROR_TEMPLATE_FAILED = new SimpleCommandExceptionType(
- Component.translatable("commands.place.template.failed")
- );
- private static final SuggestionProvider<CommandSourceStack> SUGGEST_TEMPLATES = (context, builder) -> {
- StructureTemplateManager structureManager = context.getSource().getLevel().getStructureManager();
- return SharedSuggestionProvider.suggestResource(structureManager.listTemplates(), builder);
+ private static final SimpleCommandExceptionType ERROR_STRUCTURE_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.place.structure.failed"));
+ private static final DynamicCommandExceptionType ERROR_TEMPLATE_INVALID = new DynamicCommandExceptionType((object) -> {
+ return Component.translatableEscape("commands.place.template.invalid", object);
+ });
+ private static final SimpleCommandExceptionType ERROR_TEMPLATE_FAILED = new SimpleCommandExceptionType(Component.translatable("commands.place.template.failed"));
+ private static final SuggestionProvider<CommandSourceStack> SUGGEST_TEMPLATES = (commandcontext, suggestionsbuilder) -> {
+ StructureTemplateManager structuretemplatemanager = ((CommandSourceStack) commandcontext.getSource()).getLevel().getStructureManager();
+
+ return SharedSuggestionProvider.suggestResource(structuretemplatemanager.listTemplates(), suggestionsbuilder);
};
+ public PlaceCommand() {}
+
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
- dispatcher.register(
- Commands.literal("place")
- .requires(source -> source.hasPermission(2))
- .then(
- Commands.literal("feature")
- .then(
- Commands.argument("feature", ResourceKeyArgument.key(Registries.CONFIGURED_FEATURE))
- .executes(
- context -> placeFeature(
- context.getSource(),
- ResourceKeyArgument.getConfiguredFeature(context, "feature"),
- BlockPos.containing(context.getSource().getPosition())
- )
- )
- .then(
- Commands.argument("pos", BlockPosArgument.blockPos())
- .executes(
- context -> placeFeature(
- context.getSource(),
- ResourceKeyArgument.getConfiguredFeature(context, "feature"),
- BlockPosArgument.getLoadedBlockPos(context, "pos")
- )
- )
- )
- )
- )
- .then(
- Commands.literal("jigsaw")
- .then(
- Commands.argument("pool", ResourceKeyArgument.key(Registries.TEMPLATE_POOL))
- .then(
- Commands.argument("target", ResourceLocationArgument.id())
- .then(
- Commands.argument("max_depth", IntegerArgumentType.integer(1, 7))
- .executes(
- context -> placeJigsaw(
- context.getSource(),
- ResourceKeyArgument.getStructureTemplatePool(context, "pool"),
- ResourceLocationArgument.getId(context, "target"),
- IntegerArgumentType.getInteger(context, "max_depth"),
- BlockPos.containing(context.getSource().getPosition())
- )
- )
- .then(
- Commands.argument("position", BlockPosArgument.blockPos())
- .executes(
- context -> placeJigsaw(
- context.getSource(),
- ResourceKeyArgument.getStructureTemplatePool(context, "pool"),
- ResourceLocationArgument.getId(context, "target"),
- IntegerArgumentType.getInteger(context, "max_depth"),
- BlockPosArgument.getLoadedBlockPos(context, "position")
- )
- )
- )
- )
- )
- )
- )
- .then(
- Commands.literal("structure")
- .then(
- Commands.argument("structure", ResourceKeyArgument.key(Registries.STRUCTURE))
- .executes(
- context -> placeStructure(
- context.getSource(),
- ResourceKeyArgument.getStructure(context, "structure"),
- BlockPos.containing(context.getSource().getPosition())
- )
- )
- .then(
- Commands.argument("pos", BlockPosArgument.blockPos())
- .executes(
- context -> placeStructure(
- context.getSource(),
- ResourceKeyArgument.getStructure(context, "structure"),
- BlockPosArgument.getLoadedBlockPos(context, "pos")
- )
- )
- )
- )
- )
- .then(
- Commands.literal("template")
- .then(
- Commands.argument("template", ResourceLocationArgument.id())
- .suggests(SUGGEST_TEMPLATES)
- .executes(
- context -> placeTemplate(
- context.getSource(),
- ResourceLocationArgument.getId(context, "template"),
- BlockPos.containing(context.getSource().getPosition()),
- Rotation.NONE,
- Mirror.NONE,
- 1.0F,
- 0
- )
- )
- .then(
- Commands.argument("pos", BlockPosArgument.blockPos())
- .executes(
- context -> placeTemplate(
- context.getSource(),
- ResourceLocationArgument.getId(context, "template"),
- BlockPosArgument.getLoadedBlockPos(context, "pos"),
- Rotation.NONE,
- Mirror.NONE,
- 1.0F,
- 0
- )
- )
- .then(
- Commands.argument("rotation", TemplateRotationArgument.templateRotation())
- .executes(
- context -> placeTemplate(
- context.getSource(),
- ResourceLocationArgument.getId(context, "template"),
- BlockPosArgument.getLoadedBlockPos(context, "pos"),
- TemplateRotationArgument.getRotation(context, "rotation"),
- Mirror.NONE,
- 1.0F,
- 0
- )
- )
- .then(
- Commands.argument("mirror", TemplateMirrorArgument.templateMirror())
- .executes(
- context -> placeTemplate(
- context.getSource(),
- ResourceLocationArgument.getId(context, "template"),
- BlockPosArgument.getLoadedBlockPos(context, "pos"),
- TemplateRotationArgument.getRotation(context, "rotation"),
- TemplateMirrorArgument.getMirror(context, "mirror"),
- 1.0F,
- 0
- )
- )
- .then(
- Commands.argument("integrity", FloatArgumentType.floatArg(0.0F, 1.0F))
- .executes(
- context -> placeTemplate(
- context.getSource(),
- ResourceLocationArgument.getId(context, "template"),
- BlockPosArgument.getLoadedBlockPos(context, "pos"),
- TemplateRotationArgument.getRotation(context, "rotation"),
- TemplateMirrorArgument.getMirror(context, "mirror"),
- FloatArgumentType.getFloat(context, "integrity"),
- 0
- )
- )
- .then(
- Commands.argument("seed", IntegerArgumentType.integer())
- .executes(
- context -> placeTemplate(
- context.getSource(),
- ResourceLocationArgument.getId(context, "template"),
- BlockPosArgument.getLoadedBlockPos(context, "pos"),
- TemplateRotationArgument.getRotation(context, "rotation"),
- TemplateMirrorArgument.getMirror(context, "mirror"),
- FloatArgumentType.getFloat(context, "integrity"),
- IntegerArgumentType.getInteger(context, "seed")
- )
- )
- )
- )
- )
- )
- )
- )
- )
- );
+ 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(net.minecraft.commands.Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+ return placeFeature((CommandSourceStack) commandcontext.getSource(), ResourceKeyArgument.getConfiguredFeature(commandcontext, "feature"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"));
+ }))))).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(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(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(net.minecraft.commands.Commands.argument("pos", BlockPosArgument.blockPos()).executes((commandcontext) -> {
+ return placeStructure((CommandSourceStack) commandcontext.getSource(), ResourceKeyArgument.getStructure(commandcontext, "structure"), BlockPosArgument.getLoadedBlockPos(commandcontext, "pos"));
+ }))))).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) 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) 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) 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) 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(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 source, Holder.Reference<ConfiguredFeature<?, ?>> feature, BlockPos pos) throws CommandSyntaxException {
- ServerLevel level = source.getLevel();
- ConfiguredFeature<?, ?> configuredFeature = feature.value();
- ChunkPos chunkPos = new ChunkPos(pos);
- checkLoaded(level, new ChunkPos(chunkPos.x - 1, chunkPos.z - 1), new ChunkPos(chunkPos.x + 1, chunkPos.z + 1));
- if (!configuredFeature.place(level, level.getChunkSource().getGenerator(), level.getRandom(), pos)) {
- throw ERROR_FEATURE_FAILED.create();
+ ServerLevel worldserver = source.getLevel();
+ ConfiguredFeature<?, ?> worldgenfeatureconfigured = (ConfiguredFeature) feature.value();
+ ChunkPos chunkcoordintpair = new ChunkPos(pos);
+
+ 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 string = feature.key().location().toString();
- source.sendSuccess(() -> Component.translatable("commands.place.feature.success", string, pos.getX(), pos.getY(), pos.getZ()), true);
+ String s = feature.key().location().toString();
+
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.place.feature.success", s, pos.getX(), pos.getY(), pos.getZ());
+ }, true);
return 1;
}
}
public static int placeJigsaw(CommandSourceStack source, Holder<StructureTemplatePool> templatePool, ResourceLocation target, int maxDepth, BlockPos pos) throws CommandSyntaxException {
- ServerLevel level = source.getLevel();
- if (!JigsawPlacement.generateJigsaw(level, templatePool, target, maxDepth, pos, false)) {
- throw ERROR_JIGSAW_FAILED.create();
+ ServerLevel worldserver = source.getLevel();
+
+ if (!JigsawPlacement.generateJigsaw(worldserver, templatePool, target, maxDepth, pos, false)) {
+ throw PlaceCommand.ERROR_JIGSAW_FAILED.create();
} else {
- source.sendSuccess(() -> Component.translatable("commands.place.jigsaw.success", pos.getX(), pos.getY(), pos.getZ()), true);
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.place.jigsaw.success", pos.getX(), pos.getY(), pos.getZ());
+ }, true);
return 1;
}
}
public static int placeStructure(CommandSourceStack source, Holder.Reference<Structure> structure, BlockPos pos) throws CommandSyntaxException {
- ServerLevel level = source.getLevel();
- Structure structure1 = structure.value();
- ChunkGenerator generator = level.getChunkSource().getGenerator();
- StructureStart structureStart = structure1.generate(
- source.registryAccess(),
- generator,
- generator.getBiomeSource(),
- level.getChunkSource().randomState(),
- level.getStructureManager(),
- level.getSeed(),
- new ChunkPos(pos),
- 0,
- level,
- biome -> true
- );
- if (!structureStart.isValid()) {
- throw ERROR_STRUCTURE_FAILED.create();
+ 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()));
- checkLoaded(level, chunkPos, chunkPos1);
- ChunkPos.rangeClosed(chunkPos, chunkPos1)
- .forEach(
- chunkPos2 -> structureStart.placeInChunk(
- level,
- level.structureManager(),
- generator,
- level.getRandom(),
- new BoundingBox(
- chunkPos2.getMinBlockX(),
- level.getMinBuildHeight(),
- chunkPos2.getMinBlockZ(),
- chunkPos2.getMaxBlockX(),
- level.getMaxBuildHeight(),
- chunkPos2.getMaxBlockZ()
- ),
- chunkPos2
- )
- );
- String string = structure.key().location().toString();
- source.sendSuccess(() -> Component.translatable("commands.place.structure.success", string, pos.getX(), pos.getY(), pos.getZ()), true);
+ 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(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 = structure.key().location().toString();
+
+ source.sendSuccess(() -> {
+ return Component.translatable("commands.place.structure.success", s, pos.getX(), pos.getY(), pos.getZ());
+ }, true);
return 1;
}
}
- public static int placeTemplate(
- CommandSourceStack source, ResourceLocation template, BlockPos pos, Rotation rotation, Mirror mirror, float integrity, int seed
- ) throws CommandSyntaxException {
- ServerLevel level = source.getLevel();
- StructureTemplateManager structureManager = level.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<StructureTemplate> optional;
+ Optional optional;
+
try {
- optional = structureManager.get(template);
- } catch (ResourceLocationException var13) {
- throw ERROR_TEMPLATE_INVALID.create(template);
+ optional = structuretemplatemanager.get(template);
+ } catch (ResourceLocationException resourcekeyinvalidexception) {
+ throw PlaceCommand.ERROR_TEMPLATE_INVALID.create(template);
}
if (optional.isEmpty()) {
- throw ERROR_TEMPLATE_INVALID.create(template);
+ throw PlaceCommand.ERROR_TEMPLATE_INVALID.create(template);
} else {
- StructureTemplate structureTemplate = optional.get();
- checkLoaded(level, new ChunkPos(pos), new ChunkPos(pos.offset(structureTemplate.getSize())));
- StructurePlaceSettings structurePlaceSettings = new StructurePlaceSettings().setMirror(mirror).setRotation(rotation);
+ StructureTemplate definedstructure = (StructureTemplate) optional.get();
+
+ checkLoaded(worldserver, new ChunkPos(pos), new ChunkPos(pos.offset(definedstructure.getSize())));
+ StructurePlaceSettings definedstructureinfo = (new StructurePlaceSettings()).setMirror(mirror).setRotation(rotation);
+
if (integrity < 1.0F) {
- structurePlaceSettings.clearProcessors()
- .addProcessor(new BlockRotProcessor(integrity))
- .setRandom(StructureBlockEntity.createRandom((long)seed));
+ definedstructureinfo.clearProcessors().addProcessor(new BlockRotProcessor(integrity)).setRandom(StructureBlockEntity.createRandom((long) seed));
}
- boolean flag = structureTemplate.placeInWorld(level, pos, pos, structurePlaceSettings, StructureBlockEntity.createRandom((long)seed), 2);
+ boolean flag = definedstructure.placeInWorld(worldserver, pos, pos, definedstructureinfo, StructureBlockEntity.createRandom((long) seed), 2);
+
if (!flag) {
- throw ERROR_TEMPLATE_FAILED.create();
+ throw PlaceCommand.ERROR_TEMPLATE_FAILED.create();
} else {
- source.sendSuccess(
- () -> Component.translatable("commands.place.template.success", Component.translationArg(template), pos.getX(), pos.getY(), pos.getZ()),
- true
- );
+ 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 level, ChunkPos start, ChunkPos end) throws CommandSyntaxException {
- if (ChunkPos.rangeClosed(start, end).filter(chunkPos -> !level.isLoaded(chunkPos.getWorldPosition())).findAny().isPresent()) {
+ if (ChunkPos.rangeClosed(start, end).filter((chunkcoordintpair2) -> {
+ return !level.isLoaded(chunkcoordintpair2.getWorldPosition());
+ }).findAny().isPresent()) {
throw BlockPosArgument.ERROR_NOT_LOADED.create();
}
}
|