Search in sources :

Example 16 with PlacementSettings

use of net.minecraft.world.gen.structure.template.PlacementSettings in project minecolonies by Minecolonies.

the class WindowBuildTool method updateRotation.

/**
 * Updates the rotation of the structure depending on the input.
 *
 * @param rotation the rotation to be set.
 */
private static void updateRotation(final int rotation) {
    final PlacementSettings settings = new PlacementSettings();
    switch(rotation) {
        case ROTATE_RIGHT:
            settings.setRotation(Rotation.CLOCKWISE_90);
            break;
        case ROTATE_180:
            settings.setRotation(Rotation.CLOCKWISE_180);
            break;
        case ROTATE_LEFT:
            settings.setRotation(Rotation.COUNTERCLOCKWISE_90);
            break;
        default:
            settings.setRotation(Rotation.NONE);
    }
    Settings.instance.setRotation(rotation);
    if (Settings.instance.getActiveStructure() != null) {
        Settings.instance.getActiveStructure().setPlacementSettings(settings.setMirror(Settings.instance.getMirror()));
    }
}
Also used : PlacementSettings(net.minecraft.world.gen.structure.template.PlacementSettings)

Example 17 with PlacementSettings

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

the class StructureGenPearcel2 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("lootchest")) {
            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(LOOT, random.nextLong());
        } else 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());
        } else if (s.equals("epet")) {
            int epetChance = random.nextInt(1000);
            int topChance = random.nextInt(500);
            IBlockState epetState = ModBlocks.pearcel_beacon.getDefaultState();
            if (epetChance == 0) {
                world.setBlockState(dataPos, epetState);
            } else if (topChance == 0) {
                world.setBlockState(dataPos, Blocks.OBSIDIAN.getDefaultState());
                for (int i = 0; i <= 3; i++) {
                    world.setBlockState(dataPos.add(0, i + 1, 0), Blocks.GOLD_BLOCK.getDefaultState());
                }
            } else {
                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(LOOT, 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)

Example 18 with PlacementSettings

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

the class StructureGenPearcel1 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("lootchest")) {
            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(LOOT, random.nextLong());
        } else 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