Search in sources :

Example 1 with StructureBoundingBox

use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.

the class CommandPaste method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "mirror", "generate", "select");
    EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(sender);
    RCEntityInfo entityInfo = RCCommands.getStructureEntityInfo(entityPlayerMP, null);
    NBTTagCompound worldData = entityInfo.getWorldDataClipboard();
    if (worldData == null)
        throw ServerTranslations.commandException("commands.strucPaste.noClipboard");
    WorldServer world = (WorldServer) sender.getEntityWorld();
    BlockPos pos = parameters.pos("x", "y", "z", sender.getPosition(), false).require();
    AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    String seed = parameters.get("seed").first().optional().orElse(null);
    boolean generate = parameters.has("generate");
    boolean select = parameters.has("select");
    GenericStructure structure = GenericStructure.createDefaultStructure();
    structure.worldDataCompound = worldData;
    // TODO Generate with generation info?
    OperationRegistry.queueOperation(new OperationGenerateStructure(structure, null, transform, pos, generate).withSeed(seed).prepare(world), sender);
    if (select) {
        StructureGenerator<?> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
        // Can never not place so don't handle
        //noinspection OptionalGetWithoutIsPresent
        StructureBoundingBox boundingBox = generator.boundingBox().get();
        SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
        owner.setSelection(RCBlockAreas.from(boundingBox));
    }
}
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) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 2 with StructureBoundingBox

use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.

the class CommandImportStructure method execute.

@Override
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(AxisAlignedTransform2D.ORIGINAL);
    BlockPos pos = parameters.pos("x", "y", "z", sender.getPosition(), false).require();
    boolean select = parameters.has("select");
    StructureGenerator<?> generator = new StructureGenerator<>(structure).world(world).transform(transform).lowerCoord(pos).asSource(true);
    // Can never not place so don't handle
    //noinspection OptionalGetWithoutIsPresent
    StructureBoundingBox boundingBox = generator.boundingBox().get();
    if (structure instanceof GenericStructure && world == sender.getEntityWorld())
        OperationRegistry.queueOperation(new OperationGenerateStructure((GenericStructure) structure, structureID, transform, pos, true).withStructureID(structureID).prepare(world), sender);
    else
        generator.generate();
    if (select) {
        SelectionOwner owner = RCCommands.getSelectionOwner(sender, null, false);
        owner.setSelection(RCBlockAreas.from(boundingBox));
    }
}
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) WorldServer(net.minecraft.world.WorldServer) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 3 with StructureBoundingBox

use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.

the class GenericStructure method generate.

@Override
public void generate(@Nonnull final StructureSpawnContext context, @Nonnull InstanceData instanceData, @Nonnull TransformerMulti foreignTransformer) {
    WorldServer world = context.environment.world;
    IvWorldData worldData = constructWorldData();
    boolean asSource = context.generateAsSource;
    RunTransformer transformer = getRunTransformer(instanceData, foreignTransformer, asSource);
    instanceData.variableDomain.fill(context.environment.variables);
    // The world initializes the block event array after it generates the world - in the constructor
    // This hackily sets the field to a temporary value. Yay.
    // Hax
    RCAccessorWorldServer.ensureBlockEventArray(world);
    IvBlockCollection blockCollection = worldData.blockCollection;
    int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
    BlockPos origin = StructureBoundingBoxes.min(context.boundingBox);
    Map<BlockPos, GeneratingTileEntity<?>> generatingTEs = new HashMap<>();
    Map<BlockPos, NBTTagCompound> tileEntityCompounds = new HashMap<>();
    for (NBTTagCompound tileEntityCompound : worldData.tileEntities) {
        BlockPos src = RCMover.getTileEntityPos(tileEntityCompound);
        tileEntityCompounds.put(src, tileEntityCompound);
        asGeneratingTileEntity(context, world, areaSize, origin, tileEntityCompound, generatingTEs::put);
    }
    if (transformer != null)
        transformer.transformer.transform(transformer.instanceData, Transformer.Phase.BEFORE, context, worldData, transformer);
    StructureBoundingBox relevantSourceArea = context.intersection(BlockAreas.toBoundingBox(blockCollection.area()));
    if (// Why did we get asked to generate again?
    relevantSourceArea != null) {
        BlockPos.MutableBlockPos worldPos = new BlockPos.MutableBlockPos();
        for (int pass = 0; pass < 2; pass++) {
            for (BlockPos sourcePos : RCStructureBoundingBoxes.mutablePositions(relevantSourceArea)) {
                IvMutableBlockPos.add(context.transform.applyOn(sourcePos, worldPos, areaSize), origin);
                if (context.includesComplex(worldPos)) {
                    IBlockState state = PosTransformer.transformBlockState(blockCollection.getBlockState(sourcePos), context.transform);
                    if (RecurrentComplex.specialRegistry.isSafe(state.getBlock()) && pass == getPass(state) && (transformer == null || !transformer.transformer.skipGeneration(transformer.instanceData, context, worldPos, state, worldData, sourcePos))) {
                        GeneratingTileEntity<?> generatingTE = generatingTEs.get(sourcePos);
                        //noinspection unchecked
                        if (asSource || generatingTE == null || ((GeneratingTileEntity) generatingTE).shouldPlaceInWorld(context, instanceData.tileEntities.get(sourcePos)))
                            setBlock(context, areaSize, worldPos, state, () -> tileEntityCompounds.get(sourcePos));
                        else
                            // Replace with air
                            context.setBlock(worldPos, Blocks.AIR.getDefaultState(), 2);
                    }
                }
            }
        }
    }
    if (transformer != null)
        transformer.transformer.transform(transformer.instanceData, Transformer.Phase.AFTER, context, worldData, transformer);
    for (NBTTagCompound entityCompound : worldData.entities) {
        double[] transformedEntityPos = context.transform.applyOn(getEntityPos(entityCompound), areaSize);
        if (context.includes(new Vec3i(transformedEntityPos[0] + origin.getX(), transformedEntityPos[1] + origin.getY(), transformedEntityPos[2] + origin.getZ()))) {
            Entity entity = EntityList.createEntityFromNBT(entityCompound, world);
            if (entity != null) {
                PosTransformer.transformEntityPos(entity, context.transform, areaSize);
                Mover.moveEntity(entity, origin);
                RCAccessorEntity.setEntityUniqueID(entity, UUID.randomUUID());
                generateEntityContents(context, entity);
                world.spawnEntity(entity);
            } else {
                RecurrentComplex.logger.error("Error loading entity with ID '" + entityCompound.getString("id") + "'");
            }
        }
    }
    if (!asSource) {
        if (context.generationLayer < MAX_GENERATING_LAYERS) {
            generatingTEs.entrySet().forEach(entry -> {
                NBTStorable teData = instanceData.tileEntities.get(entry.getKey());
                if (teData != null)
                    ((GeneratingTileEntity) entry.getValue()).generate(context, teData);
            });
        } else {
            RecurrentComplex.logger.warn("Structure generated with over " + MAX_GENERATING_LAYERS + " layers; most likely infinite loop!");
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) GeneratingTileEntity(ivorius.reccomplex.block.GeneratingTileEntity) RCAccessorEntity(ivorius.reccomplex.utils.accessor.RCAccessorEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) IBlockState(net.minecraft.block.state.IBlockState) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) WorldServer(net.minecraft.world.WorldServer) RCAccessorWorldServer(ivorius.reccomplex.utils.accessor.RCAccessorWorldServer) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) RunTransformer(ivorius.reccomplex.world.gen.feature.structure.generic.transformers.RunTransformer) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) NBTStorable(ivorius.reccomplex.nbt.NBTStorable) GeneratingTileEntity(ivorius.reccomplex.block.GeneratingTileEntity) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos)

Example 4 with StructureBoundingBox

use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.

the class RCSaplingGenerator method findRandomSapling.

@Nullable
public static Pair<Structure<?>, SaplingGeneration> findRandomSapling(WorldServer world, BlockPos pos, Random random, boolean considerVanilla) {
    Environment baseEnv = Environment.inNature(world, new StructureBoundingBox(pos, pos));
    List<Pair<Structure<?>, SaplingGeneration>> applicable = StructureRegistry.INSTANCE.getStructureGenerations(SaplingGeneration.class).stream().filter(pair1 -> pair1.getRight().generatesIn(baseEnv.withGeneration(pair1.getRight()))).collect(Collectors.toCollection(ArrayList::new));
    // Hackily consider big vanilla trees too
    int vanillaComplexity = complexity(world, pos, random, predictors);
    ImmutableMultimap<Integer, Pair<Structure<?>, SaplingGeneration>> groups = IvFunctions.groupMap(applicable, pair -> pair.getRight().pattern.pattern.compile(true).size());
    List<Integer> complexities = Lists.newArrayList(groups.keySet());
    if (vanillaComplexity > 0)
        complexities.add(vanillaComplexity);
    Collections.sort(complexities);
    Pair<Structure<?>, SaplingGeneration> pair = null;
    while (complexities.size() > 0 && pair == null) {
        Integer complexity = complexities.remove(complexities.size() - 1);
        Set<Pair<Structure<?>, SaplingGeneration>> placeable = groups.get(complexity).stream().filter(p -> p.getRight().pattern.canPlace(world, pos, p.getLeft().size(), p.getLeft().isRotatable(), p.getLeft().isMirrorable())).collect(Collectors.toSet());
        double totalWeight = placeable.stream().mapToDouble(RCSaplingGenerator::getSpawnWeight).sum();
        if (complexity == vanillaComplexity && considerVanilla) {
            if (random.nextDouble() * (totalWeight * RCConfig.baseSaplingSpawnWeight + 1) < 1)
                break;
        }
        if (totalWeight > 0)
            pair = WeightedSelector.select(random, placeable, RCSaplingGenerator::getSpawnWeight);
    }
    return pair;
}
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) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) Pair(org.apache.commons.lang3.tuple.Pair) Nullable(javax.annotation.Nullable)

Example 5 with StructureBoundingBox

use of net.minecraft.world.gen.structure.StructureBoundingBox in project RecurrentComplex by Ivorforce.

the class CommandSelectMove method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "mirror", "noselect");
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockPos pos = parameters.pos("x", "y", "z", selectionOwner.getSelectedPoint1(), false).require();
    AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
    boolean noselect = parameters.has("noselect");
    BlockArea area = selectionOwner.getSelection();
    IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
    NBTTagCompound worldDataCompound = worldData.createTagCompound();
    GenericStructure structure = GenericStructure.createDefaultStructure();
    structure.worldDataCompound = worldDataCompound;
    OperationRegistry.queueOperation(new OperationMulti(new OperationClearArea(area), new OperationGenerateStructure(structure, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld())), commandSender);
    if (!noselect) {
        StructureGenerator<GenericStructure.InstanceData> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
        //noinspection OptionalGetWithoutIsPresent
        StructureBoundingBox boundingBox = generator.boundingBox().get();
        selectionOwner.setSelection(RCBlockAreas.from(boundingBox));
    }
}
Also used : OperationGenerateStructure(ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) OperationClearArea(ivorius.reccomplex.world.gen.feature.structure.OperationClearArea) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) OperationMulti(ivorius.reccomplex.world.gen.feature.structure.OperationMulti) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Aggregations

StructureBoundingBox (net.minecraft.world.gen.structure.StructureBoundingBox)11 BlockPos (net.minecraft.util.math.BlockPos)10 WorldServer (net.minecraft.world.WorldServer)7 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)6 IBlockState (net.minecraft.block.state.IBlockState)5 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)4 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)4 StructureGenerator (ivorius.reccomplex.world.gen.feature.StructureGenerator)4 OperationGenerateStructure (ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure)4 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 BlockSurfacePos (ivorius.ivtoolkit.blocks.BlockSurfacePos)2 IvBlockCollection (ivorius.ivtoolkit.blocks.IvBlockCollection)2 IvMutableBlockPos (ivorius.ivtoolkit.blocks.IvMutableBlockPos)2 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)2 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)2 StructureSpawnContext (ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext)2 GenerationType (ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Lists (com.google.common.collect.Lists)1