Search in sources :

Example 56 with WorldServer

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));
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockSurfaceArea(ivorius.ivtoolkit.blocks.BlockSurfaceArea) WorldServer(net.minecraft.world.WorldServer) ChunkPos(net.minecraft.util.math.ChunkPos) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure)

Example 57 with WorldServer

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()));
    }
}
Also used : OperationGenerateStructure(ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) Placer(ivorius.reccomplex.world.gen.feature.structure.Placer) WorldServer(net.minecraft.world.WorldServer) GenerationType(ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 58 with WorldServer

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));
}
Also used : BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) java.util(java.util) Blocks(net.minecraft.init.Blocks) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) World(net.minecraft.world.World) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) Multimap(com.google.common.collect.Multimap) WeightedSelector(ivorius.ivtoolkit.random.WeightedSelector) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) IBlockState(net.minecraft.block.state.IBlockState) IvFunctions(ivorius.ivtoolkit.util.IvFunctions) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) WorldServer(net.minecraft.world.WorldServer) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) Nullable(javax.annotation.Nullable) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) IBlockState(net.minecraft.block.state.IBlockState) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) BlockPos(net.minecraft.util.math.BlockPos)

Example 59 with WorldServer

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);
}
Also used : StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) StructureGenerationEvent(ivorius.reccomplex.events.StructureGenerationEvent) WorldServer(net.minecraft.world.WorldServer) ChunkPos(net.minecraft.util.math.ChunkPos) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)

Example 60 with WorldServer

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);
            }
        }
    }
}
Also used : GeneratingTileEntity(ivorius.reccomplex.block.GeneratingTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) RCAccessorWorldServer(ivorius.reccomplex.utils.accessor.RCAccessorWorldServer)

Aggregations

WorldServer (net.minecraft.world.WorldServer)67 BlockPos (net.minecraft.util.math.BlockPos)24 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)12 IBlockState (net.minecraft.block.state.IBlockState)11 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 Entity (net.minecraft.entity.Entity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 World (net.minecraft.world.World)8 StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)8 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)7 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)7 Nullable (javax.annotation.Nullable)6 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)5 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)5 StructureSpawnContext (ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)5 Collectors (java.util.stream.Collectors)5 Block (net.minecraft.block.Block)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 Chunk (net.minecraft.world.chunk.Chunk)4 ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)4