Search in sources :

Example 1 with IvWorldData

use of ivorius.ivtoolkit.tools.IvWorldData in project RecurrentComplex by Ivorforce.

the class CommandSelectCopy method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCEntityInfo RCEntityInfo = RCCommands.getStructureEntityInfo(commandSender, null);
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockArea area = selectionOwner.getSelection();
    IvWorldData worldData = IvWorldData.capture(world, area, true);
    RCEntityInfo.setWorldDataClipboard(worldData.createTagCompound());
    commandSender.sendMessage(ServerTranslations.format("commands.selectCopy.success", RCTextStyle.area(area)));
}
Also used : BlockArea(ivorius.ivtoolkit.blocks.BlockArea) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo)

Example 2 with IvWorldData

use of ivorius.ivtoolkit.tools.IvWorldData in project RecurrentComplex by Ivorforce.

the class TransformerNaturalAir method transform.

@Override
public void transform(InstanceData instanceData, Phase phase, StructureSpawnContext context, IvWorldData worldData, RunTransformer transformer) {
    super.transform(instanceData, phase, context, worldData, transformer);
    if (phase == Phase.AFTER) {
        WorldServer world = context.environment.world;
        IvBlockCollection blockCollection = worldData.blockCollection;
        int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
        BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
        // Remove dying foliage
        HashSet<BlockPos> check = instanceData.cloud.keySet().stream().flatMap(pos -> new BlockArea(pos.subtract(new Vec3i(2, 2, 2)), pos.add(new Vec3i(2, 2, 2))).stream()).filter(pos -> !instanceData.cloud.containsKey(pos)).map(pos -> context.transform.apply(pos, areaSize).add(lowerCoord)).collect(Collectors.toCollection(HashSet::new));
        Set<BlockPos> remove = new HashSet<>();
        HashSet<BlockPos> start = new HashSet<>();
        // Do each one separately, since each block needs to be connected to floor separately
        check.forEach(checking -> {
            start.add(checking);
            if (visitRecursively(start, (changed, pos) -> {
                IBlockState state = world.getBlockState(pos);
                boolean isFoliage = RCBlockLogic.isFoliage(state, world, pos);
                if (!RCBlockLogic.canStay(state, world, pos))
                    context.setBlock(pos, Blocks.AIR.getDefaultState(), 2);
                else if (!isFoliage && !state.getBlock().isReplaceable(world, pos))
                    return false;
                else if (isFoliage && remove.size() < MAX_TREE_SIZE && remove.add(pos))
                    neighbors(pos).forEach(changed::add);
                return true;
            })) {
                remove.forEach(pos -> context.setBlock(pos, Blocks.AIR.getDefaultState(), 2));
            }
            start.clear();
            remove.clear();
        });
    }
}
Also used : IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) Blocks(net.minecraft.init.Blocks) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) BlockAreas(ivorius.ivtoolkit.blocks.BlockAreas) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) TableDataSourceBTNaturalAir(ivorius.reccomplex.gui.editstructure.transformers.TableDataSourceBTNaturalAir) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) StructureBoundingBoxes(ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes) HashSet(java.util.HashSet) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) Vec3i(net.minecraft.util.math.Vec3i) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) WorldServer(net.minecraft.world.WorldServer) JsonUtils(ivorius.reccomplex.json.JsonUtils) Nullable(javax.annotation.Nullable) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) StructureLoadContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureLoadContext) StructurePrepareContext(ivorius.reccomplex.world.gen.feature.structure.context.StructurePrepareContext) NBTBase(net.minecraft.nbt.NBTBase) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) RCBlocks(ivorius.reccomplex.block.RCBlocks) Collectors(java.util.stream.Collectors) MCRegistry(ivorius.ivtoolkit.tools.MCRegistry) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) IBlockState(net.minecraft.block.state.IBlockState) Stream(java.util.stream.Stream) RCBlockLogic(ivorius.reccomplex.utils.RCBlockLogic) Type(java.lang.reflect.Type) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) com.google.gson(com.google.gson) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) Vec3i(net.minecraft.util.math.Vec3i) IBlockState(net.minecraft.block.state.IBlockState) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) HashSet(java.util.HashSet)

Example 3 with IvWorldData

use of ivorius.ivtoolkit.tools.IvWorldData in project RecurrentComplex by Ivorforce.

the class CommandMapAllStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    ResourceExpression expression = new ResourceExpression(StructureRegistry.INSTANCE::has);
    IvOptional.ifAbsent(parameters.rc("exp").expression(expression).optional(), () -> expression.setExpression(""));
    ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
    CommandVirtual virtual = parameters.rc().virtualCommand(server).require();
    int saved = 0, failed = 0, skipped = 0;
    for (String id : StructureRegistry.INSTANCE.ids()) {
        if (!expression.test(new RawResourceLocation(StructureRegistry.INSTANCE.status(id).getDomain(), id)))
            continue;
        Structure<?> info = StructureRegistry.INSTANCE.get(id);
        if (!(info instanceof GenericStructure)) {
            skipped++;
            continue;
        }
        GenericStructure structure = (GenericStructure) info;
        IvWorldData worldData = structure.constructWorldData();
        MockWorld world = new MockWorld.WorldData(worldData);
        try {
            virtual.execute(world, new CommandSelecting.SelectingSender(commandSender, BlockPos.ORIGIN, worldData.blockCollection.area().getHigherCorner()), parameters.get().move(1).varargs());
        } catch (MockWorld.VirtualWorldException ex) {
            throw ServerTranslations.commandException("commands.rcmap.nonvirtual.arguments");
        }
        structure.worldDataCompound = worldData.createTagCompound();
        if (PacketSaveStructureHandler.write(commandSender, structure, id, directory, true, false))
            saved++;
        else
            failed++;
    }
    commandSender.sendMessage(ServerTranslations.format("commands.rcmapall.result", saved, RCTextStyle.path(directory), failed, skipped));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) CommandSelecting(ivorius.reccomplex.commands.CommandSelecting) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) MockWorld(ivorius.ivtoolkit.world.MockWorld) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression)

Example 4 with IvWorldData

use of ivorius.ivtoolkit.tools.IvWorldData 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 5 with IvWorldData

use of ivorius.ivtoolkit.tools.IvWorldData in project RecurrentComplex by Ivorforce.

the class GenericStructure method prepareInstanceData.

@Nullable
@Override
public InstanceData prepareInstanceData(@Nonnull StructurePrepareContext context, @Nonnull TransformerMulti foreignTransformer) {
    InstanceData instanceData = new InstanceData();
    if (!context.generateAsSource) {
        IvWorldData worldData = constructWorldData();
        IvBlockCollection blockCollection = worldData.blockCollection;
        int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
        BlockPos origin = StructureBoundingBoxes.min(context.boundingBox);
        variableDomain.fill(instanceData.variableDomain, context.environment, context.random);
        instanceData.variableDomain.fill(context.environment.variables);
        instanceData.transformerData = this.transformer.prepareInstanceData(context, worldData);
        instanceData.foreignTransformerData = foreignTransformer.prepareInstanceData(context, worldData);
        TransformerMulti transformer = TransformerMulti.fuse(Arrays.asList(this.transformer, foreignTransformer));
        TransformerMulti.InstanceData cInstanceData = transformer.fuseDatas(Arrays.asList(instanceData.transformerData, instanceData.foreignTransformerData));
        RunTransformer runTransformer = new RunTransformer(transformer, cInstanceData);
        transformer.configureInstanceData(cInstanceData, context, worldData, runTransformer);
        if (context.generateMaturity.isSuggest() && !transformer.mayGenerate(cInstanceData, context, worldData, runTransformer))
            return null;
        worldData.tileEntities.forEach(tileEntityCompound -> {
            asGeneratingTileEntity(context, IvTileEntityHelper.getAnyWorld(), areaSize, origin, tileEntityCompound, (src, tileEntity) -> {
                NBTStorable tileEntityInstanceData = (NBTStorable) tileEntity.prepareInstanceData(context);
                if (tileEntityInstanceData != null)
                    instanceData.tileEntities.put(src, tileEntityInstanceData);
            });
        });
    }
    return instanceData;
}
Also used : RunTransformer(ivorius.reccomplex.world.gen.feature.structure.generic.transformers.RunTransformer) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) TransformerMulti(ivorius.reccomplex.world.gen.feature.structure.generic.transformers.TransformerMulti) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) NBTStorable(ivorius.reccomplex.nbt.NBTStorable) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) Nullable(javax.annotation.Nullable)

Aggregations

IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)10 BlockPos (net.minecraft.util.math.BlockPos)7 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)5 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)5 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)5 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)4 IvBlockCollection (ivorius.ivtoolkit.blocks.IvBlockCollection)3 OperationGenerateStructure (ivorius.reccomplex.world.gen.feature.structure.OperationGenerateStructure)3 Nullable (javax.annotation.Nullable)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 WorldServer (net.minecraft.world.WorldServer)3 IvMutableBlockPos (ivorius.ivtoolkit.blocks.IvMutableBlockPos)2 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)2 MockWorld (ivorius.ivtoolkit.world.MockWorld)2 CommandSelecting (ivorius.reccomplex.commands.CommandSelecting)2 CommandVirtual (ivorius.reccomplex.commands.CommandVirtual)2 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)2 NBTStorable (ivorius.reccomplex.nbt.NBTStorable)2 OperationClearArea (ivorius.reccomplex.world.gen.feature.structure.OperationClearArea)2 RunTransformer (ivorius.reccomplex.world.gen.feature.structure.generic.transformers.RunTransformer)2