Search in sources :

Example 11 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project NetherEx by LogicTechCorp.

the class WorldGenElderMushroom method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    while (isWorldGen && world.isAirBlock(pos) && pos.getY() > 32) {
        pos = pos.down();
    }
    for (int posX = -1; posX < 2; posX++) {
        for (int posZ = -1; posZ < 2; posZ++) {
            BlockPos newPos = pos.add(posX, 0, posZ);
            IBlockState state = world.getBlockState(newPos);
            if (!state.getBlock().canSustainPlant(state, world, newPos, EnumFacing.UP, NetherExBlocks.PLANT_MUSHROOM_ELDER) && state.getBlock() != Blocks.SOUL_SAND) {
                return false;
            }
        }
    }
    pos = pos.up();
    Mirror[] mirrors = Mirror.values();
    Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
    Rotation[] rotations = Rotation.values();
    Rotation rotation = rotations[rand.nextInt(rotations.length)];
    MinecraftServer minecraftServer = world.getMinecraftServer();
    TemplateManager templateManager = world.getSaveHandler().getStructureTemplateManager();
    Template template = templateManager.getTemplate(minecraftServer, WeightedUtil.getRandomStructure(rand, variants));
    PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.AIR);
    BlockPos structureSize = Template.transformedBlockPos(placementSettings.copy(), template.getSize());
    float airAmount = 0;
    float blockAmount = MathHelper.abs((structureSize.getX() + 2) * (structureSize.getY() + 1) * (structureSize.getZ() + 2));
    for (int posX = -1; posX < structureSize.getX() + 1; posX++) {
        for (int posZ = -1; posZ < structureSize.getZ() + 1; posZ++) {
            for (int posY = 0; posY < structureSize.getY() + 1; posY++) {
                BlockPos newPos = pos.add(-(posX / 2), posY, -(posZ / 2));
                Block block = world.getBlockState(newPos).getBlock();
                if (world.isAirBlock(newPos)) {
                    airAmount += 1.0F;
                } else if (block == Blocks.NETHERRACK || block == Blocks.GLOWSTONE || block == NetherExBlocks.BLOCK_NETHERRACK || block == NetherExBlocks.PLANT_MUSHROOM_ELDER_CAP || block == NetherExBlocks.PLANT_MUSHROOM_ELDER_STEM) {
                    return false;
                }
            }
        }
    }
    if (MathHelper.abs(airAmount) / MathHelper.abs(blockAmount) >= 0.75F) {
        if (!isWorldGen) {
            world.setBlockToAir(pos);
        }
        template.addBlocksToWorld(world, pos.add(-(structureSize.getX() / 2), 0, -(structureSize.getZ() / 2)), placementSettings.copy());
        return true;
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template) TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Mirror(net.minecraft.util.Mirror)

Example 12 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project NetherEx by LogicTechCorp.

the class WorldGenAirStructure method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    rand = world.getChunkFromBlockCoords(pos).getRandomWithSeed(world.getSeed());
    Mirror[] mirrors = Mirror.values();
    Rotation[] rotations = Rotation.values();
    Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
    Rotation rotation = rotations[rand.nextInt(rotations.length)];
    MinecraftServer server = world.getMinecraftServer();
    TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
    Template template = manager.getTemplate(server, WeightedUtil.getRandomStructure(rand, variants));
    PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.STRUCTURE_VOID).setRandom(rand);
    BlockPos structureSize = Template.transformedBlockPos(placementSettings, template.getSize());
    BlockPos newPos = new BlockPos(pos.getX() - structureSize.getX() / 2, 112, pos.getZ() - structureSize.getZ() / 2);
    BlockPos spawnPos = WorldGenUtil.getSuitableAirPos(world, newPos, structureSize);
    if (!spawnPos.equals(BlockPos.ORIGIN)) {
        WorldGenUtil.generateStructure(world, spawnPos, rand, template, placementSettings, lootTables, spawnerMobs);
        return true;
    }
    return false;
}
Also used : TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Mirror(net.minecraft.util.Mirror) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template)

Example 13 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project NetherEx by LogicTechCorp.

the class WorldGenGroundStructure method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    rand = world.getChunkFromBlockCoords(pos).getRandomWithSeed(world.getSeed());
    Mirror[] mirrors = Mirror.values();
    Rotation[] rotations = Rotation.values();
    Mirror mirror = mirrors[rand.nextInt(mirrors.length)];
    Rotation rotation = rotations[rand.nextInt(rotations.length)];
    MinecraftServer server = world.getMinecraftServer();
    TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
    Template template = manager.getTemplate(server, WeightedUtil.getRandomStructure(rand, variants));
    PlacementSettings placementSettings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.STRUCTURE_VOID).setRandom(rand);
    BlockPos structureSize = Template.transformedBlockPos(placementSettings, template.getSize());
    BlockPos newPos = new BlockPos(pos.getX() - structureSize.getX() / 2, 96, pos.getZ() - structureSize.getZ() / 2);
    BlockPos spawnPos = WorldGenUtil.getSuitableGroundPos(world, newPos, allowedBlocks, structureSize, 0.8F);
    if (!spawnPos.equals(BlockPos.ORIGIN)) {
        WorldGenUtil.generateStructure(world, spawnPos, rand, template, placementSettings, lootTables, spawnerMobs);
        return true;
    }
    return false;
}
Also used : TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Mirror(net.minecraft.util.Mirror) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template)

Example 14 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project Solar by ArekkuusuJerii.

the class ObeliskDecorator method gen.

@Override
void gen(World world, int x, int z, IChunkGenerator generator, IChunkProvider provider) {
    random.setSeed(world.getSeed());
    long good = random.nextLong();
    long succ = random.nextLong();
    good *= x >> 3;
    succ *= z >> 3;
    random.setSeed(good * succ * world.getSeed());
    // Generate
    if (GEN_CONFIG.monolith.decorator.rarity > 0D && GEN_CONFIG.monolith.decorator.rarity / 100D > random.nextDouble()) {
        List<AxisAlignedBB> occupied = Lists.newArrayList();
        for (int i = 0; i < GEN_CONFIG.monolith.decorator.size; i++) {
            BlockPos top = world.getTopSolidOrLiquidBlock(randomVector().add(x, 0, z).toBlockPos());
            int below = random.nextInt(7);
            if (top.getY() > below) {
                top = top.add(0, -below, 0);
            }
            Template obelisk = obelisks.next().load(world);
            Rotation rotation = Rotation.values()[random.nextInt(4)];
            Vector3 vec = rotate(new Vector3.WrappedVec3i(obelisk.getSize()).asImmutable(), rotation);
            vec = vec.offset(rotate(Vector3.apply(-1, -1, -1), rotation), 1);
            AxisAlignedBB obeliskBB = new AxisAlignedBB(top, top.add(vec.toBlockPos())).grow(1);
            if (occupied.stream().noneMatch(bb -> bb.intersects(obeliskBB))) {
                PlacementSettings settings = new PlacementSettings();
                settings.setRotation(rotation);
                settings.setRandom(random);
                obelisk.addBlocksToWorld(world, top, settings);
                BlockPos.getAllInBox(top, top.add(vec.toBlockPos())).forEach(p -> {
                    if (random.nextFloat() < 0.05) {
                        IBlockState glyph = ModBlocks.MONOLITHIC_GLYPH.getDefaultState().withProperty(BlockMonolithicGlyph.GLYPH, random.nextInt(16));
                        world.setBlockState(p, glyph);
                    }
                });
                occupied.add(obeliskBB);
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) Vector3(net.katsstuff.mirror.data.Vector3) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) Template(net.minecraft.world.gen.structure.template.Template)

Example 15 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project BloodMagic by WayofTime.

the class BuildTestStructure method placeStructureAtPosition.

public boolean placeStructureAtPosition(Random rand, Rotation baseRotation, WorldServer world, BlockPos pos, int iteration) {
    if (pos == null)
        return false;
    MinecraftServer minecraftserver = world.getMinecraftServer();
    TemplateManager templatemanager = world.getStructureTemplateManager();
    ResourceLocation resource = new ResourceLocation(BloodMagic.MODID, "Corridor1");
    Template template = templatemanager.getTemplate(minecraftserver, resource);
    if (template == null) {
        BMLog.DEBUG.warn("Invalid template for location: " + resource);
        return false;
    }
    PlacementSettings settings = new PlacementSettings();
    settings.setMirror(Mirror.NONE);
    Rotation rot;
    rot = baseRotation;
    if (rot == null)
        rot = Rotation.NONE;
    settings.setRotation(rot);
    settings.setIgnoreEntities(true);
    settings.setChunk(null);
    settings.setReplacedBlock(null);
    settings.setIgnoreStructureBlock(false);
    // settings.func_189946_a(MathHelper.clamp_float(schema.integrity, 0.0F, 1.0F));
    BlockPos offset = Template.transformedBlockPos(settings, new BlockPos(0, 0, 0));
    BlockPos finalPos = pos.add(offset);
    template.addBlocksToWorldChunk(world, finalPos, settings);
    return true;
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template)

Aggregations

PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)18 BlockPos (net.minecraft.util.math.BlockPos)16 Template (net.minecraft.world.gen.structure.template.Template)13 Rotation (net.minecraft.util.Rotation)10 MinecraftServer (net.minecraft.server.MinecraftServer)9 IBlockState (net.minecraft.block.state.IBlockState)7 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)7 Mirror (net.minecraft.util.Mirror)6 Map (java.util.Map)4 TileEntity (net.minecraft.tileentity.TileEntity)4 EnumFacing (net.minecraft.util.EnumFacing)4 TileEntityLockableLoot (net.minecraft.tileentity.TileEntityLockableLoot)3 Structure (com.minecolonies.structures.helpers.Structure)2 Vector3 (net.katsstuff.mirror.data.Vector3)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 AreaDescriptor (WayofTime.bloodmagic.ritual.AreaDescriptor)1 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 StructureName (com.minecolonies.coremod.colony.StructureName)1 SchematicRequestMessage (com.minecolonies.coremod.network.messages.SchematicRequestMessage)1 Block (net.minecraft.block.Block)1