use of net.minecraft.world.WorldServer in project RecurrentComplex by Ivorforce.
the class CommandDecorate method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
BlockSurfaceArea area = new BlockSurfaceArea(parameters.iv().surfacePos(commandSender.getPosition(), false).require(), parameters.iv().move(2).surfacePos(commandSender.getPosition(), false).require());
BlockSurfaceArea chunkArea = new BlockSurfaceArea(getChunkPos(area.getPoint1()), getChunkPos(area.getPoint2()));
Predicate<Structure> structurePredicate = parameters.rc("exp").structurePredicate().optional().orElse(structureInfo -> true);
WorldServer world = (WorldServer) commandSender.getEntityWorld();
chunkArea.forEach(coord -> WorldGenStructures.decorate(world, world.rand, new ChunkPos(coord.x, coord.z), structurePredicate));
}
use of net.minecraft.world.WorldServer in project RecurrentComplex by Ivorforce.
the class CommandGenerateStructure method execute.
@Override
@ParametersAreNonnullByDefault
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args, "mirror", "select");
String structureID = parameters.get().first().require();
Structure<?> structure = parameters.rc().structure().require();
WorldServer world = parameters.mc("dimension").dimension(server, sender).require();
AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(null);
GenerationType generationType = parameters.rc("gen").generationType(structure).require();
BlockSurfacePos pos = parameters.surfacePos("x", "z", sender.getPosition(), false).require();
String seed = parameters.get("seed").first().optional().orElse(null);
boolean select = parameters.has("select");
Placer placer = generationType.placer();
StructureGenerator<?> generator = new StructureGenerator<>(structure).world(world).generationInfo(generationType).seed(RCStrings.seed(seed)).structureID(structureID).randomPosition(pos, placer).fromCenter(true).transform(transform);
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(), generator.transform(), lowerCoord, false).withSeed(seed).withStructureID(structureID).prepare(world), sender);
} else {
if (generator.generate() == null)
throw ServerTranslations.commandException("commands.strucGen.noPlace");
}
if (select) {
SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
owner.setSelection(RCBlockAreas.from(boundingBox.get()));
}
}
use of net.minecraft.world.WorldServer in project RecurrentComplex by Ivorforce.
the class RCSaplingGenerator method growSapling.
public static void growSapling(WorldServer world, BlockPos pos, Random random, Structure<?> structure, SaplingGeneration saplingGenInfo) {
int[] strucSize = structure.size();
Multimap<AxisAlignedTransform2D, BlockPos> placeables = saplingGenInfo.pattern.testAll(world, pos, strucSize, structure.isRotatable(), structure.isMirrorable());
// Use keys() here to get the correct distribution
AxisAlignedTransform2D transform = Lists.newArrayList(placeables.keys()).get(random.nextInt(placeables.keys().size()));
Collection<BlockPos> transformedPositions = placeables.get(transform);
BlockPos startPos = Lists.newArrayList(transformedPositions).get(random.nextInt(transformedPositions.size()));
Map<BlockPos, IBlockState> before = new HashMap<>();
IBlockState air = Blocks.AIR.getDefaultState();
saplingGenInfo.pattern.copy(transform, strucSize).forEach(i -> i.delete, entry -> {
BlockPos ePos = entry.getKey().add(startPos);
before.put(ePos, world.getBlockState(ePos));
world.setBlockState(ePos, air, 4);
});
BlockPos spawnPos = transform.apply(saplingGenInfo.spawnShift, new int[] { 1, 1, 1 }).add(startPos);
boolean success = new StructureGenerator<>(structure).world(world).generationInfo(saplingGenInfo).transform(transform).seed(random.nextLong()).maturity(StructureSpawnContext.GenerateMaturity.SUGGEST).memorize(RCConfig.memorizeSaplings).allowOverlaps(true).randomPosition(BlockSurfacePos.from(spawnPos), (context, blockCollection) -> spawnPos.getY()).generate() != null;
if (!success)
before.forEach((pos1, state) -> world.setBlockState(pos1, state, 4));
}
use of net.minecraft.world.WorldServer in project RecurrentComplex by Ivorforce.
the class StructureGenerator method generate.
/**
* @return null when creation failed, empty when no entry was created and an entry when there was
*/
public Optional<WorldStructureGenerationData.StructureEntry> generate() {
Optional<S> optionalInstanceData = instanceData();
if (!optionalInstanceData.isPresent())
return failGenerate("failed to place");
S instanceData = optionalInstanceData.get();
StructureSpawnContext spawn = spawn().get();
Structure<S> structure = structure();
String structureID = structureID();
boolean firstTime = spawn.generateMaturity.isFirstTime();
WorldServer world = spawn.environment.world;
StructureBoundingBox boundingBox = spawn.boundingBox;
if (maturity().isSuggest() && (boundingBox.minY < MIN_DIST_TO_LIMIT || boundingBox.maxY > world.getHeight() - 1 - MIN_DIST_TO_LIMIT || (RCConfig.avoidOverlappingGeneration && !allowOverlaps && !WorldStructureGenerationData.get(world).entriesAt(boundingBox).noneMatch(WorldStructureGenerationData.Entry::blocking)) || RCEventBus.INSTANCE.post(new StructureGenerationEvent.Suggest(structure, spawn)) || (structureID != null && MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Suggest(world, structureID, boundingBox, spawn.generationLayer, firstTime)))))
return failGenerate("unknown reason");
if (firstTime) {
RCEventBus.INSTANCE.post(new StructureGenerationEvent.Pre(structure, spawn));
if (structureID != null)
MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Pre(world, structureID, boundingBox, spawn.generationLayer, firstTime));
}
structure.generate(spawn, instanceData, RCConfig.getUniversalTransformer());
if (!firstTime)
return Optional.empty();
RecurrentComplex.logger.trace(String.format("Generated structure '%s' in %s (%d)", name(structureID), boundingBox, world.provider.getDimension()));
RCEventBus.INSTANCE.post(new StructureGenerationEvent.Post(structure, spawn));
if (structureID != null)
MinecraftForge.EVENT_BUS.post(new StructureGenerationEventLite.Post(world, structureID, boundingBox, spawn.generationLayer, firstTime));
if (structureID == null || !memorize)
return Optional.empty();
String generationInfoID = generationType != null ? generationType.id() : null;
WorldStructureGenerationData.StructureEntry structureEntry = WorldStructureGenerationData.StructureEntry.complete(structureID, generationInfoID, boundingBox, spawn.transform, !partially);
structureEntry.blocking = structure.isBlocking();
// Been there done that
structureEntry.firstTime = false;
structureEntry.seed = seed();
try {
structureEntry.instanceData = instanceData.writeToNBT();
} catch (Exception e) {
RecurrentComplex.logger.error(String.format("Error saving instance data for structure %s in %s", structure, boundingBox), e);
}
Collection<ChunkPos> existingChunks = WorldStructureGenerationData.get(world).addEntry(structureEntry).stream().collect(Collectors.toList());
// Complement in all chunks that already exist
if (partially) {
maturity(StructureSpawnContext.GenerateMaturity.COMPLEMENT);
StructureBoundingBox oldBB = this.generationBB;
for (ChunkPos existingChunk : existingChunks) {
generationBB(Structures.chunkBoundingBox(existingChunk));
structure.generate(spawn().get(), instanceData, RCConfig.getUniversalTransformer());
}
generationBB(oldBB);
}
return Optional.of(structureEntry);
}
use of net.minecraft.world.WorldServer in project RecurrentComplex by Ivorforce.
the class GenericStructure method setBlock.
public static void setBlock(@Nonnull StructureSpawnContext context, int[] areaSize, @Nonnull BlockPos worldPos, @Nonnull IBlockState state, @Nonnull Supplier<NBTTagCompound> tileEntity) {
WorldServer world = context.environment.world;
if (context.setBlock(worldPos, state, 2)) {
// Wants to set
NBTTagCompound tileEntityCompound = tileEntity.get();
if (tileEntityCompound != null && world.getBlockState(worldPos).getBlock() == state.getBlock()) {
TileEntity worldTileEntity = world.getTileEntity(worldPos);
if (// Do set
worldTileEntity != null) {
tileEntityCompound = RCMover.setTileEntityPos(tileEntityCompound, worldPos);
worldTileEntity.readFromNBT(tileEntityCompound);
RCPosTransformer.transformAdditionalData(worldTileEntity, context.transform, areaSize);
RCMover.setAdditionalDataPos(worldTileEntity, worldPos);
generateTileEntityContents(context, worldTileEntity);
}
}
}
}
Aggregations