Search in sources :

Example 1 with Template

use of net.minecraft.world.gen.structure.template.Template 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 Template

use of net.minecraft.world.gen.structure.template.Template 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 Template

use of net.minecraft.world.gen.structure.template.Template 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)

Example 4 with Template

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

the class WorldGenUtil method generateStructure.

public static void generateStructure(World world, BlockPos pos, Random rand, Template template, PlacementSettings placementSettings, ResourceLocation[] lootTables, ResourceLocation[] spawnerMobs) {
    try {
        List<Template.BlockInfo> blocks = (List<Template.BlockInfo>) FIELD_BLOCKS.get(template);
        List<Template.EntityInfo> entities = (List<Template.EntityInfo>) FIELD_ENTITIES.get(template);
        if ((!blocks.isEmpty() || !placementSettings.getIgnoreEntities() && !entities.isEmpty()) && template.getSize().getX() >= 1 && template.getSize().getY() >= 1 && template.getSize().getZ() >= 1) {
            BlockRotationProcessor processor = new BlockRotationProcessor(pos, placementSettings);
            Block block = placementSettings.getReplacedBlock();
            StructureBoundingBox boundingBox = placementSettings.getBoundingBox();
            for (Template.BlockInfo blockInfo : blocks) {
                BlockPos blockPos = Template.transformedBlockPos(placementSettings, blockInfo.pos).add(pos);
                Template.BlockInfo blockInfo1 = processor != null ? processor.processBlock(world, blockPos, blockInfo) : blockInfo;
                if (blockInfo1 != null) {
                    Block block1 = blockInfo1.blockState.getBlock();
                    if ((block == null || block != block1) && (!placementSettings.getIgnoreStructureBlock() || block1 != Blocks.STRUCTURE_BLOCK) && (boundingBox == null || boundingBox.isVecInside(blockPos))) {
                        IBlockState state = blockInfo1.blockState.withMirror(placementSettings.getMirror()).withRotation(placementSettings.getRotation());
                        if (blockInfo1.tileentityData != null) {
                            TileEntity tileEntity = world.getTileEntity(blockPos);
                            if (tileEntity != null) {
                                if (tileEntity instanceof IInventory) {
                                    ((IInventory) tileEntity).clear();
                                }
                                world.setBlockState(blockPos, Blocks.BARRIER.getDefaultState(), 4);
                            }
                        }
                        if (world.setBlockState(blockPos, state, 3) && blockInfo1.tileentityData != null) {
                            TileEntity tileEntity = world.getTileEntity(blockPos);
                            if (tileEntity != null) {
                                blockInfo1.tileentityData.setInteger("x", blockPos.getX());
                                blockInfo1.tileentityData.setInteger("y", blockPos.getY());
                                blockInfo1.tileentityData.setInteger("z", blockPos.getZ());
                                tileEntity.readFromNBT(blockInfo1.tileentityData);
                                tileEntity.mirror(placementSettings.getMirror());
                                tileEntity.rotate(placementSettings.getRotation());
                                if (state.getBlock() instanceof BlockChest) {
                                    ((TileEntityChest) tileEntity).setLootTable(lootTables[rand.nextInt(lootTables.length)], rand.nextLong());
                                } else if (state.getBlock() instanceof BlockMobSpawner) {
                                    ((TileEntityMobSpawner) tileEntity).getSpawnerBaseLogic().setEntityId(spawnerMobs[rand.nextInt(spawnerMobs.length)]);
                                } else if (state.getBlock() instanceof BlockUrnOfSorrow) {
                                    ((TileEntityUrnOfSorrow) tileEntity).setCanBreak(false);
                                }
                            }
                        }
                    }
                }
            }
            for (Template.BlockInfo blockInfo2 : blocks) {
                if (block == null || block != blockInfo2.blockState.getBlock()) {
                    BlockPos blockPos1 = Template.transformedBlockPos(placementSettings, blockInfo2.pos).add(pos);
                    if (boundingBox == null || boundingBox.isVecInside(blockPos1)) {
                        world.notifyNeighborsRespectDebug(blockPos1, blockInfo2.blockState.getBlock(), false);
                        if (blockInfo2.tileentityData != null) {
                            TileEntity tileEntity = world.getTileEntity(blockPos1);
                            if (tileEntity != null) {
                                tileEntity.markDirty();
                            }
                        }
                    }
                }
            }
            if (!placementSettings.getIgnoreEntities()) {
                addEntitiesToWorld(world, pos, placementSettings, entities, boundingBox);
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) TileEntityChest(net.minecraft.tileentity.TileEntityChest) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) IBlockState(net.minecraft.block.state.IBlockState) BlockChest(net.minecraft.block.BlockChest) BlockUrnOfSorrow(nex.block.BlockUrnOfSorrow) BlockRotationProcessor(net.minecraft.world.gen.structure.template.BlockRotationProcessor) Template(net.minecraft.world.gen.structure.template.Template) TileEntity(net.minecraft.tileentity.TileEntity) BlockMobSpawner(net.minecraft.block.BlockMobSpawner) TileEntityUrnOfSorrow(nex.tileentity.TileEntityUrnOfSorrow) Block(net.minecraft.block.Block) NBTTagList(net.minecraft.nbt.NBTTagList) EntityList(net.minecraft.entity.EntityList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

Example 5 with Template

use of net.minecraft.world.gen.structure.template.Template 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)

Aggregations

Template (net.minecraft.world.gen.structure.template.Template)11 BlockPos (net.minecraft.util.math.BlockPos)10 MinecraftServer (net.minecraft.server.MinecraftServer)9 PlacementSettings (net.minecraft.world.gen.structure.template.PlacementSettings)8 TemplateManager (net.minecraft.world.gen.structure.template.TemplateManager)6 IBlockState (net.minecraft.block.state.IBlockState)5 Mirror (net.minecraft.util.Mirror)5 Rotation (net.minecraft.util.Rotation)5 TileEntity (net.minecraft.tileentity.TileEntity)4 Map (java.util.Map)3 TileEntityLockableLoot (net.minecraft.tileentity.TileEntityLockableLoot)3 EnumFacing (net.minecraft.util.EnumFacing)3 Block (net.minecraft.block.Block)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 SaveScanMessage (com.minecolonies.coremod.network.messages.SaveScanMessage)1 List (java.util.List)1 BlockChest (net.minecraft.block.BlockChest)1 BlockMobSpawner (net.minecraft.block.BlockMobSpawner)1 EntityList (net.minecraft.entity.EntityList)1 IInventory (net.minecraft.inventory.IInventory)1