Ejemplo n.º 1
0
 private static void MakeHelperChest(BlockManager bm, int x, int y, int z)
 {
     TileEntityChest tec = new TileEntityChest();
     tec.Items[0] = BlockHelper.MakeItem(ItemInfo.DiamondSword.ID, 1);
     tec.Items[1] = BlockHelper.MakeItem(ItemInfo.DiamondPickaxe.ID, 1);
     tec.Items[2] = BlockHelper.MakeItem(ItemInfo.DiamondShovel.ID, 1);
     tec.Items[3] = BlockHelper.MakeItem(ItemInfo.DiamondAxe.ID, 1);
     tec.Items[4] = BlockHelper.MakeItem(BlockType.LADDER, 64);
     tec.Items[5] = BlockHelper.MakeItem(BlockType.DIRT, 64);
     tec.Items[6] = BlockHelper.MakeItem(BlockType.SAND, 64);
     tec.Items[7] = BlockHelper.MakeItem(BlockType.CRAFTING_TABLE, 64);
     tec.Items[8] = BlockHelper.MakeItem(BlockType.FURNACE, 64);
     tec.Items[9] = BlockHelper.MakeItem(ItemInfo.Bread.ID, 64);
     tec.Items[10] = BlockHelper.MakeItem(BlockType.TORCH, 64);
     tec.Items[11] = BlockHelper.MakeItem(BlockType.STONE, 64);
     tec.Items[12] = BlockHelper.MakeItem(BlockType.CHEST, 64);
     tec.Items[13] = BlockHelper.MakeItem(BlockType.GLASS, 64);
     tec.Items[14] = BlockHelper.MakeItem(BlockType.WOOD, 64);
     tec.Items[15] = BlockHelper.MakeItem(ItemInfo.Cookie.ID, 64);
     tec.Items[16] = BlockHelper.MakeItem(ItemInfo.RedstoneDust.ID, 64);
     tec.Items[17] = BlockHelper.MakeItem(BlockType.IRON_BLOCK, 64);
     tec.Items[18] = BlockHelper.MakeItem(BlockType.DIAMOND_BLOCK, 64);
     tec.Items[19] = BlockHelper.MakeItem(BlockType.GOLD_BLOCK, 64);
     bm.SetID(x, y, z, BlockType.CHEST);
     bm.SetTileEntity(x, y, z, tec);
 }
Ejemplo n.º 2
0
 private static void MakeGuardChest(BlockManager bm, int x, int y, int z, bool booIncludeItemsInChests)
 {
     TileEntityChest tec = new TileEntityChest();
     if (booIncludeItemsInChests)
     {
         for (int a = 0; a < 5; a++)
         {
             tec.Items[a] = BlockHelper.MakeItem(RandomHelper.RandomNumber(ItemInfo.IronSword.ID,
                                                                           ItemInfo.WoodenSword.ID,
                                                                           ItemInfo.StoneSword.ID), 1);
         }
         tec.Items[6] = BlockHelper.MakeItem(ItemInfo.Bow.ID, 1);
         tec.Items[7] = BlockHelper.MakeItem(ItemInfo.Arrow.ID, 64);
         int intArmourStartID = RandomHelper.RandomNumber(ItemInfo.LeatherCap.ID, ItemInfo.ChainHelmet.ID,
                                                          ItemInfo.IronHelmet.ID);
         for (int a = 9; a < 18; a++)
         {
             // random armour
             tec.Items[a] = BlockHelper.MakeItem(intArmourStartID + RandomHelper.Next(4), 1);
         }
     }
     bm.SetID(x, y, z, BlockType.CHEST);
     bm.SetTileEntity(x, y, z, tec);
 }
Ejemplo n.º 3
0
        public static void InsertBuilding(BlockManager bmDest, int[,] intArea, int intBlockStart,
                                          int x1dest, int z1dest, Building bldInsert, int y1dest)
        {
            List<Spawner> lstSpawners = new List<Spawner>();
            _lstInstanceSigns.Clear();
            int intRandomWoolColour = RandomHelper.Next(16);
            int intSourceX = 0, intSourceZ = 0;
            int intRotate = -1;
            if (bldInsert.btThis == BuildingTypes.MineshaftSection)
            {
                intRotate = 0;
            }
            else
            {
                for (int intDistance = 0; intRotate == -1 && intDistance < 10; intDistance++)
                {
                    for (int intCheck = 0; intRotate == -1 && intCheck <= bldInsert.intSizeX; intCheck++)
                    {
                        if (CheckArea(intArea, x1dest + intCheck, z1dest - intDistance) == 1)
                        {
                            intRotate = 0;
                        }
                        else if (CheckArea(intArea, x1dest - intDistance, z1dest + intCheck) == 1)
                        {
                            intRotate = 1;
                        }
                        else if (CheckArea(intArea, x1dest + bldInsert.intSizeX + intDistance, z1dest + intCheck) == 1)
                        {
                            intRotate = 2;
                        }
                        else if (CheckArea(intArea, x1dest + intCheck, z1dest + bldInsert.intSizeZ + intDistance) == 1)
                        {
                            intRotate = 3;
                        }
                    }
                }
            }
            if (intRotate == -1)
            {
                intRotate = RandomHelper.Next(4);
            }

            for (int x = 0; x < bldInsert.intSizeX; x++)
            {
                for (int z = 0; z < bldInsert.intSizeZ; z++)
                {
                    switch (intRotate)
                    {
                        case 0:
                            intSourceX = x;
                            intSourceZ = z;
                            break;
                        case 1:
                            intSourceX = (bldInsert.intSizeX - 1) - z;
                            intSourceZ = x;
                            break;
                        case 2:
                            intSourceX = z;
                            intSourceZ = (bldInsert.intSizeZ - 1) - x;
                            break;
                        case 3:
                            intSourceX = (bldInsert.intSizeX - 1) - x;
                            intSourceZ = (bldInsert.intSizeZ - 1) - z;
                            break;
                        default:
                            Debug.Fail("Invalid switch result");
                            break;
                    }

                    int intSourceEndY;
                    if (bldInsert.btThis == BuildingTypes.MineshaftSection)
                    {
                        intSourceEndY = bldInsert.intSourceStartY + 4;
                    }
                    else
                    {
                        for (intSourceEndY = 128; intSourceEndY > 64; intSourceEndY--)
                        {
                            if (_bmSource.GetID(intSourceX + bldInsert.intSourceX, intSourceEndY,
                                                intSourceZ + bldInsert.intSourceZ) != BlockType.AIR)
                            {
                                break;
                            }
                        }
                    }
                    for (int ySource = bldInsert.intSourceStartY; ySource <= intSourceEndY; ySource++)
                    {
                        int yDest = ySource;
                        if (bldInsert.btThis == BuildingTypes.MineshaftSection)
                        {
                            yDest = y1dest + (ySource - bldInsert.intSourceStartY);
                        }

                        if (bldInsert.btThis == BuildingTypes.MineshaftSection ||
                            ((yDest != 64 || bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) == BlockType.AIR) &&
                            bmDest.GetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest) != BlockType.WOOD_PLANK))
                        {
                            int intBlockID = _bmSource.GetID(intSourceX + bldInsert.intSourceX, ySource,
                                                             intSourceZ + bldInsert.intSourceZ);
                            int intBlockData = _bmSource.GetData(intSourceX + bldInsert.intSourceX, ySource,
                                                                 intSourceZ + bldInsert.intSourceZ);
                            bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockID);
                            bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, intBlockData);

                            #region import paintings
                            // todo: test for mineshaft features
                            foreach (EntityPainting entPainting in _AllEntityPainting)
                            {
                                if (entPainting.TileX == intSourceX + bldInsert.intSourceX &&
                                    entPainting.TileY == ySource &&
                                    entPainting.TileZ == intSourceZ + bldInsert.intSourceZ)
                                {
                                    EntityPainting entNewPainting = (EntityPainting)entPainting.Copy();
                                    entNewPainting.TileX = intBlockStart + x + x1dest;
                                    entNewPainting.TileY = yDest;
                                    entNewPainting.TileZ = intBlockStart + z + z1dest;
                                    entNewPainting.Position.X = entNewPainting.TileX;
                                    entNewPainting.Position.Z = entNewPainting.TileZ;
                                    entNewPainting.Direction = BlockHelper.RotatePortrait(entPainting.Direction,
                                                                                          intRotate);
                                    ChunkRef chunkBuilding = _cmDest.GetChunkRef((intBlockStart + x + x1dest) / 16,
                                                                                 (intBlockStart + z + z1dest) / 16);
                                    chunkBuilding.Entities.Add(entNewPainting);
                                    _cmDest.Save();
                                }
                            }
                            #endregion
                            #region Rotation
                            if (intRotate > 0)
                            {
                                switch (intBlockID)
                                {
                                    case BlockType.PORTAL:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotatePortal(intBlockData, intRotate));
                                        break;
                                    case BlockType.SIGN_POST:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateSignPost(intBlockData, intRotate));
                                        break;
                                    case BlockType.STONE_BUTTON:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateButton(intBlockData, intRotate));
                                        break;
                                    case BlockType.PUMPKIN:
                                    case BlockType.JACK_O_LANTERN:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotatePumpkin(intBlockData, intRotate));
                                        break;
                                    case BlockType.IRON_DOOR:
                                    case BlockType.WOOD_DOOR:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateDoor(intBlockData, intRotate));
                                        break;
                                    case BlockType.TRAPDOOR:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateTrapdoor(intBlockData, intRotate));
                                        break;
                                    case BlockType.BED:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateBed(intBlockData, intRotate));
                                        break;
                                    case BlockType.REDSTONE_TORCH_OFF:
                                    case BlockType.REDSTONE_TORCH_ON:
                                    case BlockType.TORCH:
                                    case BlockType.LEVER:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                       BlockHelper.RotateTorchOrLever(intBlockData, intRotate));
                                        break;
                                    case BlockType.WALL_SIGN:
                                    case BlockType.LADDER:
                                    case BlockType.DISPENSER:
                                    case BlockType.FURNACE:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                        BlockHelper.RotateWallSignOrLadderOrFurnanceOrDispenser(
                                                          intBlockData, intRotate));
                                        break;
                                    case BlockType.COBBLESTONE_STAIRS:
                                    case BlockType.WOOD_STAIRS:
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                        BlockHelper.RotateStairs(intBlockData, intRotate));
                                        break;
                                    // no need for a default - all other blocks are okay
                                }
                            }
                            #endregion
                            #region Handle entities
                            switch (intBlockID)
                            {
                                case BlockType.SPONGE:
                                    bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.WOOL);
                                    bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                   intRandomWoolColour);
                                    break;
                                case BlockType.CHEST:
                                    TileEntityChest tec = (TileEntityChest)_bmSource.GetTileEntity(
                                        intSourceX + bldInsert.intSourceX, ySource, intSourceZ + bldInsert.intSourceZ);
                                    if (_booIncludeItemsInChests)
                                    {
                                        if (tec.Items[0] != null)
                                        {
                                            if (tec.Items[0].ID == ItemInfo.Paper.ID &&
                                                tec.Items[0].Count == 3)
                                            {
                                                tec = MakeHouseChest();
                                            }
                                            if (tec.Items[0].ID == ItemInfo.Paper.ID &&
                                                tec.Items[0].Count == 4)
                                            {
                                                tec = MakeTreasureChest();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        tec.Items.ClearAllItems();
                                    }
                                    bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tec);
                                    break;
                                case BlockType.FURNACE:
                                case BlockType.MONSTER_SPAWNER:
                                case BlockType.NOTE_BLOCK:
                                    bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                         _bmSource.GetTileEntity(intSourceX + bldInsert.intSourceX, ySource,
                                                                                 intSourceZ + bldInsert.intSourceZ));
                                    break;
                                case BlockType.SIGN_POST:
                                case BlockType.WALL_SIGN:
                                    #region Determine sign text
                                    int intUniqueType = 0;
                                    TileEntitySign tes = (TileEntitySign)_bmSource.
                                        GetTileEntity(intSourceX + bldInsert.intSourceX, ySource,
                                                      intSourceZ + bldInsert.intSourceZ);
                                    string strSourceSign = tes.Text1 + " " + tes.Text2 + " " + tes.Text3 + " " + tes.Text4;
                                    switch (strSourceSign.Substring(0, 1))
                                    {
                                        case "2":
                                        case "1":
                                        case "0":
                                            intUniqueType = Convert.ToInt32(strSourceSign.Substring(0, 1));
                                            strSourceSign = strSourceSign.Remove(0, 1);
                                            break;
                                        default:
                                            intUniqueType = 0;
                                            break;
                                    }
                                    if (tes.Text1.ToLower() == "commentsign" || tes.Text1.ToLower() == "comment sign")
                                    {
                                        // these exist to give advice to people in the resource world.
                                        // so we just remove them from the real world
                                        bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest,
                                                     BlockType.AIR);
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0);
                                    }
                                    if (tes.Text1.ToLower() == "spawner" || tes.Text1.ToLower() == "gspawner")
                                    {
                                        if (!tes.Text2.ToLower().StartsWith("g") || tes.Text2.ToLower() == "[randomenemy]" || _booIncludeGhostdancerSpawners)
                                        {
                                            Spawner spawnerCurrent = new Spawner();
                                            if (tes.Text2.ToLower() == "[randomenemy]")
                                            {
                                                if (_booIncludeGhostdancerSpawners)
                                                {
                                                    spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie", "GGeist", "GGrim");
                                                }
                                                else
                                                {
                                                    spawnerCurrent.strEntityID = RandomHelper.RandomString("Creeper", "Skeleton", "Spider", "Zombie");
                                                }
                                            }
                                            else
                                            {
                                                spawnerCurrent.strEntityID = tes.Text2;
                                            }

                                            if (tes.Text3.Split(' ').GetUpperBound(0) == 2)
                                            {
                                                spawnerCurrent.sy = yDest + Convert.ToInt32(tes.Text3.Split(' ')[1]);
                                                spawnerCurrent.sx = 0;
                                                spawnerCurrent.sz = 0;
                                                switch (intRotate)
                                                {
                                                    case 0:
                                                        spawnerCurrent.sx = intBlockStart + x + x1dest +
                                                                            (Convert.ToInt32(tes.Text3.Split(' ')[0]));
                                                        spawnerCurrent.sz = intBlockStart + z + z1dest +
                                                                            (Convert.ToInt32(tes.Text3.Split(' ')[2]));
                                                        break;
                                                    case 1:
                                                        spawnerCurrent.sx = intBlockStart + x + x1dest +
                                                                            (Convert.ToInt32(tes.Text3.Split(' ')[2]));
                                                        spawnerCurrent.sz = intBlockStart + z + z1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0]));
                                                        break;
                                                    case 2:
                                                        spawnerCurrent.sx = intBlockStart + x + x1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2]));
                                                        spawnerCurrent.sz = intBlockStart + z + z1dest +
                                                                            (Convert.ToInt32(tes.Text3.Split(' ')[0]));
                                                        break;
                                                    case 3:
                                                        spawnerCurrent.sx = intBlockStart + x + x1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text3.Split(' ')[0]));
                                                        spawnerCurrent.sz = intBlockStart + z + z1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text3.Split(' ')[2]));
                                                        break;
                                                }
                                            }
                                            else
                                            {
                                                spawnerCurrent.sx = intBlockStart + x + x1dest;
                                                spawnerCurrent.sy = yDest - 2;
                                                spawnerCurrent.sz = intBlockStart + z + z1dest;
                                            }
                                            if (tes.Text4.ToLower() == "no")
                                            {
                                                spawnerCurrent.booGrass = false;
                                            }
                                            else if (tes.Text4.Split(' ').GetUpperBound(0) == 2)
                                            {
                                                spawnerCurrent.gy = yDest + Convert.ToInt32(tes.Text4.Split(' ')[1]);
                                                switch (intRotate)
                                                {
                                                    case 0:
                                                        spawnerCurrent.gx = intBlockStart + x + x1dest +
                                                                            (Convert.ToInt32(tes.Text4.Split(' ')[0]));
                                                        spawnerCurrent.gz = intBlockStart + z + z1dest +
                                                                            (Convert.ToInt32(tes.Text4.Split(' ')[2]));
                                                        break;
                                                    case 1:
                                                        spawnerCurrent.gx = intBlockStart + x + x1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2]));
                                                        spawnerCurrent.gz = intBlockStart + z + z1dest +
                                                                            (Convert.ToInt32(tes.Text4.Split(' ')[0]));
                                                        break;
                                                    case 2:
                                                        spawnerCurrent.gx = intBlockStart + x + x1dest +
                                                                            (Convert.ToInt32(tes.Text4.Split(' ')[2]));
                                                        spawnerCurrent.gz = intBlockStart + z + z1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0]));
                                                        break;
                                                    case 3:
                                                        spawnerCurrent.gx = intBlockStart + x + x1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text4.Split(' ')[0]));
                                                        spawnerCurrent.gz = intBlockStart + z + z1dest +
                                                                            (-1 * Convert.ToInt32(tes.Text4.Split(' ')[2]));
                                                        break;
                                                }
                                                spawnerCurrent.booGrass = true;
                                            }
                                            else
                                            {
                                                spawnerCurrent.gx = intBlockStart + x + x1dest;
                                                spawnerCurrent.gy = yDest - 1;
                                                spawnerCurrent.gz = intBlockStart + z + z1dest;
                                                spawnerCurrent.booGrass = true;
                                            }
                                            lstSpawners.Add(spawnerCurrent);
                                        }
                                        bmDest.SetID(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, BlockType.AIR);
                                        bmDest.SetData(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, 0);
                                    }
                                    else if (strSourceSign.Contains("["))
                                    {
                                        string strSignText;
                                        bool booDuplicate;
                                        int intFail = 0;
                                        do
                                        {
                                            strSignText = SignText(strSourceSign);
                                            booDuplicate = false;
                                            switch (intUniqueType)
                                            {
                                                case 1: // unique by instance
                                                    booDuplicate = _lstInstanceSigns.Contains(strSignText);
                                                    break;
                                                case 2: // unique by city
                                                    booDuplicate = _lstCitySigns.Contains(strSignText);
                                                    break;
                                            }
                                            if (++intFail > 100)
                                            {
                                                Debug.WriteLine("Could not make a unique sign for " + strSourceSign);
                                                booDuplicate = false;
                                            }
                                        } while (booDuplicate);
                                        _lstCitySigns.Add(strSignText);
                                        _lstInstanceSigns.Add(strSignText);
                                        string[] strRandomSign = Utils.TextToSign(Utils.ConvertStringToSignText(strSignText));
                                        tes.Text1 = strRandomSign[0];
                                        tes.Text2 = strRandomSign[1];
                                        tes.Text3 = strRandomSign[2];
                                        tes.Text4 = strRandomSign[3];
                                        bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes);
                                    }
                                    else
                                    {
                                        bmDest.SetTileEntity(intBlockStart + x + x1dest, yDest, intBlockStart + z + z1dest, tes);
                                    }
                                    break;
                                    #endregion
                                // no need for a default - all the other blocks are okay
                            }
                            #endregion
                        }
                    }
                }
            }
            foreach (Spawner spnAdd in lstSpawners)
            {
                bmDest.SetID(spnAdd.sx, spnAdd.sy, spnAdd.sz, BlockType.MONSTER_SPAWNER);
                TileEntityMobSpawner tems = new TileEntityMobSpawner();
                tems.EntityID = spnAdd.strEntityID;
                bmDest.SetTileEntity(spnAdd.sx, spnAdd.sy, spnAdd.sz, tems);
                if (spnAdd.booGrass)
                {
                    bmDest.SetID(spnAdd.gx, spnAdd.gy, spnAdd.gz, BlockType.GRASS);
                }
            }
        }
Ejemplo n.º 4
0
        private static void MakeChestItems(BlockManager bm, int x, int y, int z, int[] intResourceChances, string[] strResourceNames)
        {
            string strResource = strResourceNames[RandomHelper.RandomWeightedNumber(intResourceChances)];
            string strAmount;
            _dictResourceAmounts.TryGetValue(strResource.ToLower(), out strAmount);
            strAmount = strAmount ?? "1,1";
            int intAmount = RandomHelper.Next(Convert.ToInt32(strAmount.Split(',')[0]),
                                              Convert.ToInt32(strAmount.Split(',')[1]) + 1);
            string strBlockID;
            _dictResourceIDs.TryGetValue(strResource.ToLower(), out strBlockID);
            TileEntityChest tec = new TileEntityChest();
            int intSlot = 0;
            do
            {
                if (intAmount > MINECRAFT_ITEM_STACK_AMOUNT)
                {
                    tec.Items[intSlot++] = BlockHelper.MakeItem(Convert.ToInt32(strBlockID),
                                                                MINECRAFT_ITEM_STACK_AMOUNT);
                }
                else
                {
                    tec.Items[intSlot++] = BlockHelper.MakeItem(Convert.ToInt32(strBlockID), intAmount);
                }
                intAmount -= MINECRAFT_ITEM_STACK_AMOUNT;
            } while (intAmount > 0);

            bm.SetTileEntity(x, y, z, tec);
        }