Search in sources :

Example 1 with IvBlockCollection

use of ivorius.ivtoolkit.blocks.IvBlockCollection in project RecurrentComplex by Ivorforce.

the class TransformerEnsureBlocks method mayGenerate.

@Override
public boolean mayGenerate(NBTNone instanceData, StructurePrepareContext context, IvWorldData worldData, RunTransformer transformer) {
    IvBlockCollection blockCollection = worldData.blockCollection;
    int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
    BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
    BlockPos.MutableBlockPos worldCoord = new BlockPos.MutableBlockPos();
    for (BlockPos sourcePos : BlockAreas.mutablePositions(blockCollection.area())) {
        IvMutableBlockPos.add(context.transform.applyOn(sourcePos, worldCoord, areaSize), lowerCoord);
        IBlockState state = blockCollection.getBlockState(sourcePos);
        if (sourceMatcher.test(state) && !(destMatcher.expressionIsEmpty() || destMatcher.evaluate(() -> PositionedBlockExpression.Argument.at(context.environment.world, worldCoord))))
            return false;
    }
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection)

Example 2 with IvBlockCollection

use of ivorius.ivtoolkit.blocks.IvBlockCollection in project RecurrentComplex by Ivorforce.

the class FactorMatch method consider.

@Override
public List<Pair<LineSelection, Float>> consider(WorldCache cache, LineSelection considerable, @Nullable IvBlockCollection blockCollection, StructurePlaceContext context) {
    if (blockCollection == null)
        throw new IllegalArgumentException("Missing a block collection!");
    List<Pair<LineSelection, Float>> consideration = new ArrayList<>();
    int[] size = StructureBoundingBoxes.size(context.boundingBox);
    BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
    Set<BlockPos.MutableBlockPos> sources = BlockAreas.streamMutablePositions(blockCollection.area()).filter(p -> sourceMatcher.evaluate(() -> blockCollection.getBlockState(p))).map(p -> new BlockPos.MutableBlockPos(context.transform.apply(p, size).add(lowerCoord.getX(), 0, lowerCoord.getZ()))).collect(Collectors.toSet());
    for (IntegerRange range : (Iterable<IntegerRange>) considerable.streamSections(null, true)::iterator) {
        Float curConformity = null;
        int lastY = range.getMax();
        int end = range.getMin();
        for (int y = lastY; y >= end; y--) {
            int finalY = y;
            sources.forEach(p -> p.move(EnumFacing.UP, finalY));
            float conformity = weight(cache, sources, requiredConformity);
            sources.forEach(p -> p.move(EnumFacing.DOWN, finalY));
            if (curConformity == null) {
                curConformity = conformity;
                lastY = y;
            } else if (!DoubleMath.fuzzyEquals(conformity, curConformity, 0.01)) {
                consideration.add(Pair.of(LineSelection.fromRange(IntegerRanges.from(lastY, y + 1), true), weight(curConformity)));
                curConformity = conformity;
                lastY = y;
            }
        }
        if (curConformity != null)
            consideration.add(Pair.of(LineSelection.fromRange(IntegerRanges.from(lastY, end), true), weight(curConformity)));
    }
    return consideration;
}
Also used : IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) java.util(java.util) BlockAreas(ivorius.ivtoolkit.blocks.BlockAreas) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) StructureBoundingBoxes(ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes) Pair(org.apache.commons.lang3.tuple.Pair) ivorius.reccomplex.utils(ivorius.reccomplex.utils) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) JsonUtils(ivorius.reccomplex.json.JsonUtils) Nullable(javax.annotation.Nullable) ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) DoubleMath(com.google.common.math.DoubleMath) TableDataSourceFactorMatch(ivorius.reccomplex.gui.editstructure.placer.TableDataSourceFactorMatch) WorldCache(ivorius.ivtoolkit.world.WorldCache) EnumFacing(net.minecraft.util.EnumFacing) LineSelection(ivorius.ivtoolkit.util.LineSelection) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) Type(java.lang.reflect.Type) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) com.google.gson(com.google.gson) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) BlockPos(net.minecraft.util.math.BlockPos) Pair(org.apache.commons.lang3.tuple.Pair)

Example 3 with IvBlockCollection

use of ivorius.ivtoolkit.blocks.IvBlockCollection in project RecurrentComplex by Ivorforce.

the class TransformerEnsureBlocks method mayGenerate.

@Override
public boolean mayGenerate(NBTNone instanceData, StructurePrepareContext context, IvWorldData worldData) {
    IvBlockCollection blockCollection = worldData.blockCollection;
    int[] areaSize = new int[] { blockCollection.width, blockCollection.height, blockCollection.length };
    BlockPos lowerCoord = StructureBoundingBoxes.min(context.boundingBox);
    BlockPos.MutableBlockPos worldCoord = new BlockPos.MutableBlockPos();
    for (BlockPos sourcePos : BlockAreas.mutablePositions(blockCollection.area())) {
        if (sourceMatcher.test(blockCollection.getBlockState(sourcePos))) {
            IvMutableBlockPos.add(context.transform.applyOn(sourcePos, worldCoord, areaSize), lowerCoord);
            if (!(destMatcher.expressionIsEmpty() || destMatcher.evaluate(() -> PositionedBlockExpression.Argument.at(context.environment.world, worldCoord))))
                return false;
        }
    }
    return true;
}
Also used : IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection)

Example 4 with IvBlockCollection

use of ivorius.ivtoolkit.blocks.IvBlockCollection 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) Side(net.minecraftforge.fml.relauncher.Side) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) 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 5 with IvBlockCollection

use of ivorius.ivtoolkit.blocks.IvBlockCollection 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, NBTTagCompound> tileEntityCompounds = new HashMap<>();
    for (NBTTagCompound tileEntityCompound : worldData.tileEntities) {
        BlockPos src = RCMover.getTileEntityPos(tileEntityCompound);
        tileEntityCompounds.put(src, tileEntityCompound);
    }
    if (transformer != null)
        transformer.transformer.transform(transformer.instanceData, Transformer.Phase.BEFORE, context, worldData, transformer);
    StructureBoundingBox relevantSourceArea = context.sourceIntersection(BlockAreas.toBoundingBox(blockCollection.area()));
    if (// Why did we get asked to generate again?
    relevantSourceArea != null) {
        context.freezeHeightMap(relevantSourceArea);
        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 (pass == getPass(state) && (transformer == null || !transformer.transformer.skipGeneration(transformer.instanceData, context, worldPos, state, worldData, sourcePos))) {
                        setBlock(context, areaSize, worldPos, state, () -> tileEntityCompounds.get(sourcePos));
                    }
                }
            }
        }
        context.meltHeightMap();
    }
    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") + "'");
            }
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) 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) IvMutableBlockPos(ivorius.ivtoolkit.blocks.IvMutableBlockPos)

Aggregations

IvBlockCollection (ivorius.ivtoolkit.blocks.IvBlockCollection)11 BlockPos (net.minecraft.util.math.BlockPos)10 com.google.gson (com.google.gson)6 IvMutableBlockPos (ivorius.ivtoolkit.blocks.IvMutableBlockPos)6 StructureBoundingBoxes (ivorius.ivtoolkit.world.chunk.gen.StructureBoundingBoxes)6 TableDelegate (ivorius.reccomplex.gui.table.TableDelegate)6 TableNavigator (ivorius.reccomplex.gui.table.TableNavigator)6 TableDataSource (ivorius.reccomplex.gui.table.datasource.TableDataSource)6 JsonUtils (ivorius.reccomplex.json.JsonUtils)6 Type (java.lang.reflect.Type)6 Collectors (java.util.stream.Collectors)6 WorldCache (ivorius.ivtoolkit.world.WorldCache)5 Nullable (javax.annotation.Nullable)5 IntegerRange (ivorius.ivtoolkit.gui.IntegerRange)4 LineSelection (ivorius.ivtoolkit.util.LineSelection)4 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)4 PositionedBlockExpression (ivorius.reccomplex.utils.expression.PositionedBlockExpression)4 WorldServer (net.minecraft.world.WorldServer)4 Side (net.minecraftforge.fml.relauncher.Side)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4