Search in sources :

Example 11 with Template

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

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