Search in sources :

Example 6 with BlockBox

use of net.minecraft.util.math.BlockBox in project SeedcrackerX by 19MisterX98.

the class WarpedFungusFinder method findInChunk.

@Override
public List<BlockPos> findInChunk() {
    Biome biome = this.world.getBiomeForNoiseGen((this.chunkPos.x << 2) + 2, 64, (this.chunkPos.z << 2) + 2).value();
    List<BlockPos> newResult = new ArrayList<>();
    if (!Features.WARPED_FUNGUS.isValidBiome(BiomeFixer.swap(biome)))
        return new ArrayList<>();
    List<BlockPos> result = super.findInChunk();
    List<FullFungusData> fullFungusData = new ArrayList<>();
    List<BlockBox> renderBox = new ArrayList<>();
    result.removeIf(pos -> {
        Block soil = this.world.getBlockState(pos.down()).getBlock();
        if (soil != Blocks.NETHERRACK && soil != Blocks.WARPED_NYLIUM) {
            return true;
        }
        int bigCount = 0;
        if (this.world.getBlockState(pos.north()).getBlock() == Blocks.WARPED_STEM)
            bigCount++;
        if (this.world.getBlockState(pos.east()).getBlock() == Blocks.WARPED_STEM)
            bigCount++;
        if (this.world.getBlockState(pos.west()).getBlock() == Blocks.WARPED_STEM)
            bigCount++;
        if (this.world.getBlockState(pos.south()).getBlock() == Blocks.WARPED_STEM)
            bigCount++;
        if (bigCount != 0 && bigCount != 4)
            return true;
        boolean big = bigCount == 4;
        newResult.add(pos);
        BlockPos.Mutable trunk = pos.mutableCopy();
        int i = 0;
        while (this.world.getBlockState(trunk.add(0, i, 0)).getBlock() == Blocks.WARPED_STEM) {
            i++;
        }
        if (i < 4 || i > 26 || (i > 14 && i % 2 == 1)) {
            return false;
        }
        int dataCounter = 0;
        ArrayList<Integer> bigTrunkData = new ArrayList<>();
        if (big) {
            dataCounter++;
            for (int x = -1; x < 2; x += 2) {
                for (int z = -1; z < 2; z += 2) {
                    for (int height = 0; height < i; height++) {
                        Block block = this.world.getBlockState(trunk.add(x, height, z)).getBlock();
                        if (block == Blocks.WARPED_STEM) {
                            dataCounter++;
                            bigTrunkData.add(1);
                        } else if (block.getDefaultState().getMaterial() == Material.PLANT || block.getDefaultState().getMaterial() == Material.SOLID_ORGANIC || block == Blocks.AIR) {
                            bigTrunkData.add(0);
                        }
                    }
                }
            }
        }
        boolean validLayer;
        int height = i;
        ArrayList<Integer> layerSizes = new ArrayList<>();
        int upperLayerSize = 1;
        do {
            validLayer = false;
            for (int layerSize = upperLayerSize + 1; upperLayerSize - 1 <= layerSize; layerSize--) {
                if (layerSize < 1)
                    break;
                int countRing = countRing(pos.add(0, i, 0), layerSize);
                if (countRing == 0) {
                    i--;
                    layerSizes.add(layerSize);
                    upperLayerSize = layerSize;
                    validLayer = true;
                    break;
                } else if (countRing == 3) {
                    // found a wrong block
                    return false;
                } else // not enough blocks for a full layer, might be vines
                if (countRing == 2)
                    break;
            }
        } while (validLayer);
        if (layerSizes.size() < 2)
            return false;
        int heeeight = height;
        // testing for things inside of the vines
        int ring = countRing(pos.add(0, i, 0), upperLayerSize + 1);
        int vineRingSize = upperLayerSize;
        if (ring == 0 || ring == 2) {
            vineRingSize++;
        } else if (ring == 3) {
            return false;
        }
        for (int y = i - 2; y <= i; y++) {
            for (int x = -vineRingSize + 1; x < vineRingSize; x++) {
                for (int z = -vineRingSize + 1; z < vineRingSize; z++) {
                    if (big && -2 < x && x < 2 && -2 < z && z < 2)
                        continue;
                    if (x == 0 && z == 0)
                        continue;
                    Block block = this.world.getBlockState(pos.add(x, y, z)).getBlock();
                    if (block.getDefaultState().getMaterial() != Material.PLANT && block != Blocks.AIR)
                        return false;
                }
            }
        }
        // vine data
        ArrayList<Integer> vine = new ArrayList<>();
        for (int x = -vineRingSize; x <= vineRingSize; x++) {
            for (int z = -vineRingSize; z <= vineRingSize; z++) {
                if (Math.abs(x) != vineRingSize && Math.abs(z) != vineRingSize)
                    continue;
                boolean isVine = false;
                for (int y = i - 2; y <= i; y++) {
                    Block block = this.world.getBlockState(pos.add(x, y, z)).getBlock();
                    if (block == Blocks.WARPED_WART_BLOCK) {
                        if (isVine)
                            continue;
                        vine.add(i - y + 1);
                        // System.out.println(i-y+1+" at x: "+ x+" z: "+z);
                        isVine = true;
                        dataCounter++;
                    } else if (block.getDefaultState().getMaterial() != Material.PLANT && block != Blocks.AIR || isVine) {
                        return false;
                    } else if (y == i) {
                        vine.add(0);
                    // System.out.println("0 at x: "+ x+" z: "+z);
                    }
                }
            }
        }
        Collections.reverse(layerSizes);
        int counter = 0;
        int[][][] layers = new int[layerSizes.size()][11][11];
        for (int y = i + 1; y <= height; y++) {
            int layerSize = layerSizes.get(counter);
            for (int x = -layerSize; x <= layerSize; x++) {
                for (int z = -layerSize; z <= layerSize; z++) {
                    Block block = this.world.getBlockState(pos.add(x, y, z)).getBlock();
                    int blocktype = -1;
                    if (block == Blocks.AIR) {
                        blocktype = 0;
                    } else if (block == Blocks.WARPED_WART_BLOCK) {
                        blocktype = 1;
                    } else if (block == Blocks.SHROOMLIGHT) {
                        dataCounter++;
                        blocktype = 2;
                    } else if (block == Blocks.WARPED_STEM) {
                        blocktype = 3;
                    } else {
                        blocktype = 0;
                        System.out.println("error found illegal Block: " + block.getName() + " at " + pos.add(x, y, z).toShortString());
                    }
                    layers[counter][x + layerSize][z + layerSize] = blocktype;
                }
            }
            counter++;
        }
        if (dataCounter < 13)
            return true;
        FullFungusData fungusData = new FullFungusData(layerSizes, layers, vine, big, height, vineRingSize, bigTrunkData, dataCounter);
        fullFungusData.add(fungusData);
        Collections.reverse(layerSizes);
        for (int layerSize : layerSizes) {
            renderBox.add(BlockBox.create(pos.add(layerSize + 1, heeeight, layerSize + 1), pos.add(-layerSize, heeeight + 1, -layerSize)));
            heeeight--;
        }
        renderBox.add(BlockBox.create(pos.add(-vineRingSize + 1, i - 2, -vineRingSize + 1), pos.add(vineRingSize, i + 1, vineRingSize)));
        renderBox.add(BlockBox.create(pos.add(-vineRingSize, i - 2, -vineRingSize), pos.add(vineRingSize + 1, i + 1, vineRingSize + 1)));
        return false;
    });
    if (fullFungusData.isEmpty())
        return new ArrayList<>();
    if (newResult.size() < 5)
        return new ArrayList<>();
    FullFungusData bestFungus = FullFungusData.getBestFungus(fullFungusData);
    if (bestFungus == null)
        return new ArrayList<>();
    WarpedFungus.Data data = Features.WARPED_FUNGUS.at(chunkPos.getStartX(), chunkPos.getStartZ(), BiomeFixer.swap(biome), newResult, bestFungus);
    if (SeedCracker.get().getDataStorage().addBaseData(data, data::onDataAdded)) {
        for (BlockBox box : renderBox) {
            this.renderers.add(new Cuboid(box, new Color(0, 255, 255)));
        }
        for (BlockPos pos : newResult) {
            this.renderers.add(new Cube(pos, new Color(255, 30, 0)));
        }
    }
    return newResult;
}
Also used : BlockBox(net.minecraft.util.math.BlockBox) WarpedFungus(kaptainwutax.seedcrackerX.cracker.decorator.WarpedFungus) Color(kaptainwutax.seedcrackerX.render.Color) ArrayList(java.util.ArrayList) Cuboid(kaptainwutax.seedcrackerX.render.Cuboid) FullFungusData(kaptainwutax.seedcrackerX.cracker.decorator.FullFungusData) Biome(net.minecraft.world.biome.Biome) Cube(kaptainwutax.seedcrackerX.render.Cube) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 7 with BlockBox

use of net.minecraft.util.math.BlockBox in project Biome-Makeover by Lemonszz.

the class WaterTreeFeature method generate.

public final boolean generate(StructureWorldAccess structureWorldAccess, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, TreeFeatureConfig treeFeatureConfig) {
    Set<BlockPos> set = Sets.newHashSet();
    Set<BlockPos> set2 = Sets.newHashSet();
    Set<BlockPos> set3 = Sets.newHashSet();
    BlockBox blockBox = BlockBox.empty();
    boolean bl = this.generate(structureWorldAccess, random, blockPos, set, set2, blockBox, treeFeatureConfig);
    if (blockBox.minX <= blockBox.maxX && bl && !set.isEmpty()) {
        if (!treeFeatureConfig.decorators.isEmpty()) {
            List<BlockPos> list = Lists.newArrayList(set);
            List<BlockPos> list2 = Lists.newArrayList(set2);
            list.sort(Comparator.comparingInt(Vec3i::getY));
            list2.sort(Comparator.comparingInt(Vec3i::getY));
            treeFeatureConfig.decorators.forEach((decorator) -> {
                decorator.generate(structureWorldAccess, random, list, list2, set3, blockBox);
            });
        }
        VoxelSet voxelSet = this.placeLogsAndLeaves(structureWorldAccess, blockBox, set, set3);
        Structure.updateCorner(structureWorldAccess, 3, voxelSet, blockBox.minX, blockBox.minY, blockBox.minZ);
        return true;
    } else {
        return false;
    }
}
Also used : BlockBox(net.minecraft.util.math.BlockBox) VoxelSet(net.minecraft.util.shape.VoxelSet) BitSetVoxelSet(net.minecraft.util.shape.BitSetVoxelSet) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockBox (net.minecraft.util.math.BlockBox)7 BlockPos (net.minecraft.util.math.BlockPos)7 Color (kaptainwutax.seedcrackerX.render.Color)2 Cube (kaptainwutax.seedcrackerX.render.Cube)2 Cuboid (kaptainwutax.seedcrackerX.render.Cuboid)2 BlockRotation (net.minecraft.util.BlockRotation)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 Direction (net.minecraft.util.math.Direction)2 Products (com.mojang.datafixers.Products)1 Codec (com.mojang.serialization.Codec)1 RecordCodecBuilder (com.mojang.serialization.codecs.RecordCodecBuilder)1 RegionStructure (com.seedfinding.mcfeature.structure.RegionStructure)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Set (java.util.Set)1 FullFungusData (kaptainwutax.seedcrackerX.cracker.decorator.FullFungusData)1 WarpedFungus (kaptainwutax.seedcrackerX.cracker.decorator.WarpedFungus)1 EntityTrackerSection (me.jellysquid.mods.lithium.common.entity.tracker.EntityTrackerSection)1 Range6Int (me.jellysquid.mods.lithium.common.util.tuples.Range6Int)1 Block (net.minecraft.block.Block)1