Search in sources :

Example 1 with Rotation

use of net.minecraft.util.Rotation in project NetherEx by LogicTechCorp.

the class WorldGenWallStructure 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.AIR).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.getSuitableWallPos(world, newPos, 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 2 with Rotation

use of net.minecraft.util.Rotation in project NetherEx by LogicTechCorp.

the class WorldGenCeilingStructure 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, 48, pos.getZ() - structureSize.getZ() / 2);
    BlockPos spawnPos = WorldGenUtil.getSuitableCeilingPos(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 3 with Rotation

use of net.minecraft.util.Rotation in project minecolonies by Minecolonies.

the class StructureProxy method rotateWithMirror.

/**
     * Rotate the structure depending on the direction it's facing.
     *
     * @param times     times to rotateWithMirror.
     * @param world     the world to rotateWithMirror it in.
     * @param rotatePos the pos to rotateWithMirror it around.
     * @param mirror    the mirror
     */
public void rotateWithMirror(final int times, final World world, final BlockPos rotatePos, final Mirror mirror) {
    final Rotation rotation;
    switch(times) {
        case 1:
            rotation = Rotation.CLOCKWISE_90;
            break;
        case 2:
            rotation = Rotation.CLOCKWISE_180;
            break;
        case 3:
            rotation = Rotation.COUNTERCLOCKWISE_90;
            break;
        default:
            rotation = Rotation.NONE;
    }
    structure.setPlacementSettings(new PlacementSettings().setRotation(rotation).setMirror(mirror));
    final BlockPos size = structure.getSize(rotation);
    this.width = size.getX();
    this.height = size.getY();
    this.length = size.getZ();
    this.blocks = new Template.BlockInfo[width][height][length];
    this.entities = new Template.EntityInfo[width][height][length];
    int minX = 0;
    int minY = 0;
    int minZ = 0;
    for (final Template.BlockInfo info : structure.getBlockInfoWithSettings(new PlacementSettings().setRotation(rotation).setMirror(mirror))) {
        final BlockPos tempPos = info.pos;
        final int x = tempPos.getX();
        final int y = tempPos.getY();
        final int z = tempPos.getZ();
        if (x < minX) {
            minX = x;
        }
        if (y < minY) {
            minY = y;
        }
        if (z < minZ) {
            minZ = z;
        }
    }
    minX = Math.abs(minX);
    minY = Math.abs(minY);
    minZ = Math.abs(minZ);
    boolean foundHut = false;
    final PlacementSettings settings = new PlacementSettings().setRotation(rotation).setMirror(mirror);
    for (final Template.BlockInfo info : structure.getBlockInfoWithSettings(settings)) {
        final BlockPos tempPos = info.pos;
        final int x = tempPos.getX() + minX;
        final int y = tempPos.getY() + minY;
        final int z = tempPos.getZ() + minZ;
        this.blocks[x][y][z] = info;
        this.entities[x][y][z] = null;
        if (info.blockState.getBlock() instanceof AbstractBlockHut) {
            foundHut = true;
            offset = info.pos.add(minX, minY, minZ);
        }
    }
    updateOffSetIfDecoration(foundHut, size, times, minX, minY, minZ);
    for (final Template.EntityInfo info : structure.getTileEntities()) {
        final Template.EntityInfo newInfo = structure.transformEntityInfoWithSettings(info, world, rotatePos.subtract(offset).add(new BlockPos(minX, minY, minZ)), settings);
        //289 74 157 - 289.9 76.5, 157.5
        final BlockPos tempPos = Template.transformedBlockPos(settings, info.blockPos);
        final int x = tempPos.getX() + minX;
        final int y = tempPos.getY() + minY;
        final int z = tempPos.getZ() + minZ;
        this.entities[x][y][z] = newInfo;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings) Rotation(net.minecraft.util.Rotation) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut) Template(net.minecraft.world.gen.structure.template.Template)

Example 4 with Rotation

use of net.minecraft.util.Rotation 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 5 with Rotation

use of net.minecraft.util.Rotation 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)

Aggregations

Rotation (net.minecraft.util.Rotation)6 BlockPos (net.minecraft.util.math.BlockPos)6 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)6 Template (net.minecraft.world.gen.structure.template.Template)6 MinecraftServer (net.minecraft.server.MinecraftServer)5 Mirror (net.minecraft.util.Mirror)5 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)5 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1