Search in sources :

Example 6 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project Waystones by blay09.

the class ComponentVillageWaystone method addComponentParts.

@Override
public boolean addComponentParts(World world, Random random, StructureBoundingBox boundingBox) {
    if (averageGroundLvl < 0) {
        averageGroundLvl = getAverageGroundLevel(world, boundingBox);
        if (averageGroundLvl < 0) {
            return true;
        }
        this.boundingBox.offset(0, averageGroundLvl - this.boundingBox.minY, 0);
    }
    BlockPos pos = new BlockPos(this.boundingBox.minX, this.boundingBox.minY, this.boundingBox.minZ);
    TemplateManager templateManager = world.getSaveHandler().getStructureTemplateManager();
    PlacementSettings settings = (new PlacementSettings()).setReplacedBlock(Blocks.STRUCTURE_VOID).setBoundingBox(boundingBox);
    Template template = templateManager.getTemplate(world.getMinecraftServer(), structureType == 1 ? DESERT_VILLAGE_WAYSTONE_ID : VILLAGE_WAYSTONE_ID);
    template.addBlocksToWorldChunk(world, pos, settings);
    Map<BlockPos, String> dataBlocks = template.getDataBlocks(pos, settings);
    for (Map.Entry<BlockPos, String> entry : dataBlocks.entrySet()) {
        if ("Waystone".equals(entry.getValue())) {
            world.setBlockState(entry.getKey(), Waystones.blockWaystone.getDefaultState().withProperty(BlockWaystone.BASE, true), 3);
            world.setBlockState(entry.getKey().up(), Waystones.blockWaystone.getDefaultState().withProperty(BlockWaystone.BASE, false), 3);
        }
    }
    return true;
}
Also used : TemplateManager(net.minecraft.world.gen.structure.template.TemplateManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Map(java.util.Map) Template(net.minecraft.world.gen.structure.template.Template)

Example 7 with PlacementSettings

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

the class AshenCubeStructure method genCubes.

private void genCubes(World world, BlockPos pos) {
    // Gen Cube
    BlockPos origin = pos.add(5, 0, 5);
    Template template = Structure.ASHEN_CUBE.load(world);
    boolean loot = GEN_CONFIG.ashen_cube.loot / 100D > random.nextDouble();
    PlacementSettings integrity = new PlacementSettings();
    integrity.setIntegrity(loot ? 1F : 0.35F + 0.45F * random.nextFloat());
    template.addBlocksToWorld(world, origin, integrity);
    integrity.setIntegrity(!loot && random.nextFloat() > 0.45F ? 1F : random.nextFloat());
    Structure.ASHEN_CUBE_.generate(world, origin, integrity);
    // Add loot
    for (int i = 0; i < 6 + random.nextInt(6); i++) {
        loot = GEN_CONFIG.monolith.structure.loot / 100D > random.nextDouble();
        if (loot) {
            BlockPos inside = origin.add(1 + random.nextInt(4), 1, 1 + random.nextInt(4));
            IBlockState pot = ModBlocks.LARGE_POT.getDefaultState().withProperty(BlockLargePot.POT_VARIANT, random.nextInt(3));
            world.setBlockState(inside, pot);
        }
    }
    // Gen Cubes
    AxisAlignedBB cubeBB = new AxisAlignedBB(origin, origin.add(template.getSize()));
    for (int i = 0; i < GEN_CONFIG.ashen_cube.size; i++) {
        Template cube = nuggets.next().load(world);
        Rotation rotation = Rotation.values()[random.nextInt(4)];
        Vector3 vec = rotate(new Vector3.WrappedVec3i(cube.getSize()).asImmutable(), rotation);
        BlockPos offset = pos.add(randomVector().toBlockPos());
        if (offset.getY() < 1 || (world.canSeeSky(offset) && GEN_CONFIG.ashen_cube.underground))
            continue;
        AxisAlignedBB nuggetBB = new AxisAlignedBB(offset, vec.add(new Vector3.WrappedVec3i(offset)).toBlockPos());
        if (!nuggetBB.intersects(cubeBB)) {
            PlacementSettings settings = new PlacementSettings();
            settings.setIntegrity(random.nextFloat() > 0.85F ? 0.9F : 0.35F + 0.45F * random.nextFloat());
            settings.setRotation(rotation);
            settings.setRandom(random);
            cube.addBlocksToWorld(world, offset, settings);
        }
    }
}
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 8 with PlacementSettings

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

the class MonolithStructure 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 >> 2;
    succ *= z >> 2;
    random.setSeed(good * succ ^ world.getSeed());
    // Generate
    if (GEN_CONFIG.monolith.structure.rarity > 0D && GEN_CONFIG.monolith.structure.rarity / 100D > random.nextDouble()) {
        BlockPos origin = new BlockPos(x, 0, z);
        // Gen Monolith
        BlockPos surface = world.getTopSolidOrLiquidBlock(origin.add(8, 0, 8));
        BlockPos pos = origin.add(5, Math.max(surface.getY() - (5 + random.nextInt(3)), 8), 4);
        Structure.MONOLITH_CUBE.generate(world, pos.down(7), new PlacementSettings());
        // Randomize glyphs
        BlockPos.MutableBlockPos start = new BlockPos.MutableBlockPos(pos.getX(), pos.getY() - 4, pos.getZ() + 6);
        Arrays.stream(EnumFacing.HORIZONTALS).forEach(facing -> {
            for (int i = 0; i < 6; i++) {
                IBlockState glyph = ModBlocks.MONOLITHIC_GLYPH.getDefaultState().withProperty(BlockMonolithicGlyph.GLYPH, random.nextInt(16));
                world.setBlockState(start, glyph);
                start.move(facing.getOpposite(), 1);
            }
        });
        // Add loot
        BlockPos loot = pos.down(7).add(1, 1, 1);
        for (int i = 0; i < 6 + random.nextInt(6); i++) {
            if (GEN_CONFIG.monolith.structure.loot / 100D > random.nextDouble()) {
                BlockPos inside = loot.add(random.nextInt(4), 0, random.nextInt(4));
                IBlockState pot = ModBlocks.LARGE_POT.getDefaultState().withProperty(BlockLargePot.POT_VARIANT, random.nextInt(3));
                world.setBlockState(inside, pot);
            }
        }
        // Gen ruin
        if (GEN_CONFIG.monolith.structure.well) {
            Structure.MONOLITH_RUIN.generate(world, pos, new PlacementSettings());
        }
        if (GEN_CONFIG.monolith.structure.ruins > 0) {
            int size = (GEN_CONFIG.monolith.structure.ruins / 100) * 32;
            size += random.nextInt((int) (((double) GEN_CONFIG.monolith.structure.ruins / 100D) * 64D));
            for (int i = 0; i < size; i++) {
                BlockPos top = world.getTopSolidOrLiquidBlock(randomVector().add(x, 1, z).toBlockPos());
                int below = random.nextInt(3);
                if (top.getY() > below) {
                    top = top.add(0, -below, 0);
                }
                world.setBlockState(top, ModBlocks.ASHEN.getDefaultState());
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings)

Example 9 with PlacementSettings

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

the class Dungeon method placeStructureAtPosition.

public static boolean placeStructureAtPosition(Random rand, WorldServer world, BlockPos pos) {
    long startTime = System.nanoTime();
    // Map of doors. The EnumFacing indicates what way this door faces.
    Map<EnumFacing, List<BlockPos>> availableDoorMap = new HashMap<>();
    List<AreaDescriptor> descriptorList = new ArrayList<>();
    // Placement positions in terms of actual positions
    Map<BlockPos, Pair<DungeonRoom, PlacementSettings>> roomMap = new HashMap<>();
    PlacementSettings settings = new PlacementSettings();
    Mirror mir = Mirror.NONE;
    settings.setMirror(mir);
    Rotation rot = Rotation.NONE;
    settings.setRotation(rot);
    settings.setIgnoreEntities(true);
    settings.setChunk(null);
    settings.setReplacedBlock(null);
    settings.setIgnoreStructureBlock(false);
    DungeonRoom room = getRandomRoom(rand);
    roomMap.put(pos, Pair.of(room, settings.copy()));
    descriptorList.addAll(room.getAreaDescriptors(settings, pos));
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (availableDoorMap.containsKey(facing)) {
            List<BlockPos> doorList = availableDoorMap.get(facing);
            doorList.addAll(room.getDoorOffsetsForFacing(settings, facing, pos));
        } else {
            List<BlockPos> doorList = room.getDoorOffsetsForFacing(settings, facing, pos);
            availableDoorMap.put(facing, doorList);
        }
    }
    // Initial AreaDescriptors and door positions are initialized. Time for fun!
    for (int i = 0; i < 100; i++) {
        List<EnumFacing> facingList = new ArrayList<>();
        for (Entry<EnumFacing, List<BlockPos>> entry : availableDoorMap.entrySet()) {
            if (entry.getValue() != null && !entry.getValue().isEmpty()) {
                facingList.add(entry.getKey());
            }
        }
        // Shuffle the list so that it is random what is chosen
        Collections.shuffle(facingList);
        Pair<EnumFacing, BlockPos> removedDoor1 = null;
        Pair<EnumFacing, BlockPos> removedDoor2 = null;
        BlockPos roomLocation = null;
        for (EnumFacing doorFacing : facingList) {
            EnumFacing oppositeDoorFacing = doorFacing.getOpposite();
            // May need to copy here
            List<BlockPos> availableDoorList = availableDoorMap.get(doorFacing);
            Collections.shuffle(availableDoorList);
            // Same for the Mirror
            settings.setRotation(Rotation.values()[rand.nextInt(Rotation.values().length)]);
            DungeonRoom testingRoom = getRandomRoom(rand);
            List<BlockPos> otherDoorList = testingRoom.getDoorOffsetsForFacing(settings, oppositeDoorFacing, BlockPos.ORIGIN);
            if (otherDoorList != null && !otherDoorList.isEmpty()) {
                // See if one of these doors works.
                Collections.shuffle(otherDoorList);
                BlockPos testDoor = otherDoorList.get(0);
                testDoor: for (BlockPos availableDoor : availableDoorList) {
                    // TODO: Test if it fits, then add the doors to the list.
                    roomLocation = availableDoor.subtract(testDoor).add(doorFacing.getDirectionVec());
                    List<AreaDescriptor> descriptors = testingRoom.getAreaDescriptors(settings, roomLocation);
                    for (AreaDescriptor testDesc : descriptors) {
                        for (AreaDescriptor currentDesc : descriptorList) {
                            if (testDesc.intersects(currentDesc)) {
                                break testDoor;
                            }
                        }
                    }
                    roomMap.put(roomLocation, Pair.of(testingRoom, settings.copy()));
                    descriptorList.addAll(descriptors);
                    removedDoor1 = Pair.of(doorFacing, availableDoor);
                    removedDoor2 = Pair.of(oppositeDoorFacing, testDoor.add(roomLocation));
                    room = testingRoom;
                }
                break;
            }
        // Collections.shuffle(otherDoorList);
        }
        if (removedDoor1 != null) {
            for (EnumFacing facing : EnumFacing.VALUES) {
                if (availableDoorMap.containsKey(facing)) {
                    List<BlockPos> doorList = availableDoorMap.get(facing);
                    doorList.addAll(room.getDoorOffsetsForFacing(settings, facing, roomLocation));
                } else {
                    List<BlockPos> doorList = room.getDoorOffsetsForFacing(settings, facing, roomLocation);
                    availableDoorMap.put(facing, doorList);
                }
            }
            EnumFacing face = removedDoor1.getKey();
            if (availableDoorMap.containsKey(face)) {
                availableDoorMap.get(face).remove(removedDoor1.getRight());
            }
        }
        if (removedDoor2 != null) {
            EnumFacing face = removedDoor2.getKey();
            if (availableDoorMap.containsKey(face)) {
                availableDoorMap.get(face).remove(removedDoor2.getRight());
            }
        }
    }
    long endTime = System.nanoTime();
    // divide by 1000000 to get milliseconds.
    long duration = (endTime - startTime);
    BMLog.DEBUG.info("Duration: " + duration + "(ns), " + duration / 1000000 + "(ms)");
    // Building what I've got
    for (Entry<BlockPos, Pair<DungeonRoom, PlacementSettings>> entry : roomMap.entrySet()) {
        BlockPos placementPos = entry.getKey();
        DungeonRoom placedRoom = entry.getValue().getKey();
        PlacementSettings placementSettings = entry.getValue().getValue();
        placedRoom.placeStructureAtPosition(rand, placementSettings, world, placementPos);
    }
    return false;
}
Also used : AreaDescriptor(WayofTime.bloodmagic.ritual.AreaDescriptor) EnumFacing(net.minecraft.util.EnumFacing) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) BlockPos(net.minecraft.util.math.BlockPos) Mirror(net.minecraft.util.Mirror) Pair(org.apache.commons.lang3.tuple.Pair)

Example 10 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project Pearcel-Mod by MiningMark48.

the class StructureGenPearcel3 method generateStructure.

public static void generateStructure(WorldServer world, BlockPos pos, Random random) {
    MinecraftServer server = world.getMinecraftServer();
    Template template = world.getStructureTemplateManager().getTemplate(server, STRUCTURE);
    PlacementSettings settings = new PlacementSettings();
    settings.setRotation(Rotation.NONE);
    template.addBlocksToWorld(world, pos, settings);
    Map<BlockPos, String> dataBlocks = template.getDataBlocks(pos, settings);
    for (Map.Entry<BlockPos, String> entry : dataBlocks.entrySet()) {
        String[] tokens = entry.getValue().split(" ");
        if (tokens.length == 0)
            return;
        BlockPos dataPos = entry.getKey();
        String s = tokens[0].toLowerCase();
        if (s.equals("lootchest2")) {
            String chestOrientation = tokens[1];
            EnumFacing chestFacing = settings.getRotation().rotate(EnumFacing.byName(chestOrientation));
            IBlockState chestState = Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, chestFacing);
            world.setBlockState(dataPos, chestState);
            TileEntity tile = world.getTileEntity(dataPos);
            if (tile != null && tile instanceof TileEntityLockableLoot)
                ((TileEntityLockableLoot) tile).setLootTable(LOOT2, random.nextLong());
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) MinecraftServer(net.minecraft.server.MinecraftServer) Template(net.minecraft.world.gen.structure.template.Template) TileEntity(net.minecraft.tileentity.TileEntity) TileEntityLockableLoot(net.minecraft.tileentity.TileEntityLockableLoot) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map)

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