Last active
June 5, 2017 23:30
-
-
Save Ivorforce/5f44a2c7063dbc024936bbf7df13f163 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CommandGenerateStructure extends SimpleCommand | |
{ | |
public CommandGenerateStructure() | |
{ | |
super(RCConfig.commandPrefix + "gen"); | |
permitFor(2); | |
} | |
@Override | |
public Expect<?> expect() | |
{ | |
return RCExpect.expectRC() | |
.structure() | |
.surfacePos("x", "z") | |
.named("gen") | |
.next(params -> new RCParameters(params).rc().genericStructure().tryGet() | |
.map(structure -> structure.generationTypes(GenerationType.class).stream().map(GenerationType::id)) | |
).optionalU("generation type id") | |
} | |
@Override | |
@ParametersAreNonnullByDefault | |
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException | |
{ | |
RCParameters parameters = RCParameters.of(args, expect()::declare); | |
String structureID = parameters.get().first().require(); | |
Structure<?> structure = parameters.rc().structure().require(); | |
GenerationType generationType = parameters.rc("gen").generationType(structure).require(); | |
BlockSurfacePos pos = parameters.surfacePos("x", "z", sender.getPosition(), false).require(); | |
Placer placer = generationType.placer(); | |
StructureGenerator<?> generator = new StructureGenerator<>(structure).world(sender.getWorld()).generationInfo(generationType) | |
.structureID(structureID).randomPosition(pos, placer).fromCenter(true); | |
Optional<StructureBoundingBox> boundingBox = generator.boundingBox(); | |
if (!boundingBox.isPresent()) | |
throw ServerTranslations.commandException("commands.strucGen.noPlace"); | |
if (structure instanceof GenericStructure && world == sender.getEntityWorld()) | |
{ | |
GenericStructure genericStructureInfo = (GenericStructure) structure; | |
BlockPos lowerCoord = StructureBoundingBoxes.min(boundingBox.get()); | |
OperationRegistry.queueOperation(new OperationGenerateStructure(genericStructureInfo, generationType.id(), lowerCoord, false) | |
.withStructureID(structureID).prepare(world), sender); | |
} | |
else | |
{ | |
if (generator.generate() == null) | |
throw ServerTranslations.commandException("commands.strucGen.noPlace"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment