Ejemplo n.º 1
0
 static ProtoBlock[] RegisterNewBlock(string modNamespace, string shortID, Version?versionAdded, ProtoBlock substitute)
 {
     if (!versionAdded.HasValue)
     {
         versionAdded = Version.FirstVersion;
     }
     if (shortID.Contains("*"))
     {
         //Multicolored blocks
         ProtoBlock[] blocks = new ProtoBlock[Blocks.commonColors.Length];
         for (int i = 0; i < Blocks.commonColors.Length; i++)
         {
             string colorBlockID = shortID.Replace("*", Blocks.commonColors[i]);
             //TODO: how to substitute color block with another color block?
             var b = new ProtoBlock(modNamespace, colorBlockID, versionAdded.Value, substitute);
             BlockList.allBlocks.Add(b.ID, b);
             blocks[i] = b;
         }
         return(blocks);
     }
     else
     {
         var b = new ProtoBlock(modNamespace, shortID, versionAdded.Value, substitute);
         BlockList.allBlocks.Add(b.ID, b);
         return(new ProtoBlock[] { b });
     }
 }
Ejemplo n.º 2
0
 private ProtoBlock(string ns, string id, Version v, ProtoBlock sub)
 {
     customNamespace = ns;
     shortID         = id;
     addedInVersion  = v;
     substitute      = sub;
 }
Ejemplo n.º 3
0
 public static bool IsBlockForMap(ProtoBlock b, HeightmapType type)
 {
     if (b == null || IsAir(b))
     {
         return(false);
     }
     if (type == HeightmapType.AllBlocks)
     {
         return(true);
     }
     else if (type == HeightmapType.SolidBlocks)
     {
         return(!IsTransparentBlock(b));
     }
     else if (type == HeightmapType.SolidBlocksNoLiquid)
     {
         return(!IsTransparentBlock(b) && !IsLiquid(b) && !b.Compare("minecraft:ice"));
     }
     else if (type == HeightmapType.TerrainBlocks)
     {
         return(b.CompareMultiple(commonTerrainBlocks) || b.CompareMultiple(waterBlock, lavaBlock));
     }
     else if (type == HeightmapType.TerrainBlocksNoLiquid)
     {
         return(b.CompareMultiple(commonTerrainBlocks));
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        static BlockList()
        {
            allBlocks        = new Dictionary <string, ProtoBlock>();
            numerics         = new Dictionary <ProtoBlock, NumericID>();
            protoByNumerics  = new Dictionary <ushort, ProtoBlock>();
            preFlatteningIDs = new Dictionary <ProtoBlock, string>();
            var lines = Resources.blocks.Replace("\r", "").Split('\n');
            //ID,Properties,Numeric ID,Pre-flattening ID,Added in Version,Fallback
            List <(ProtoBlock, string)> fallbacks = new List <(ProtoBlock, string)>();

            for (int i = 1; i < lines.Length; i++)
            {
                var split = lines[i].Split(';');
                if (split[0].Length > 0)
                {
                    string id = split[0];
                    if (allBlocks.ContainsKey("minecraft:" + id))
                    {
                        //TODO: how to handle multiple equal ids (such as different facing logs) ?
                        continue;
                    }
                    string    props         = split[1];          //TODO: introduce default properties?
                    NumericID?numeric       = NumericID.TryParse(split[2]);
                    string    preFlattening = split[3];
                    Version   version       = split[4].Length > 1 ? Version.Parse(split[4]) : Version.FirstVersion;
                    var       newBlocks     = ProtoBlock.RegisterNewVanillaBlock(id, version);
                    foreach (var newBlock in newBlocks)
                    {
                        if (split[5].Length > 1)
                        {
                            fallbacks.Add((newBlock, split[5]));
Ejemplo n.º 5
0
 public static bool IsPlantSustaining(ProtoBlock b)
 {
     if (b == null)
     {
         return(false);
     }
     return(b.CompareMultiple(plantSustainingBlocks));
 }
Ejemplo n.º 6
0
 public static bool IsLiquid(ProtoBlock b)
 {
     if (b == null)
     {
         return(false);
     }
     return(b.CompareMultiple(waterBlock, lavaBlock));
 }
Ejemplo n.º 7
0
 public static bool IsAir(ProtoBlock b)
 {
     if (b == null)
     {
         return(false);
     }
     return(b.CompareMultiple("minecraft:air", "minecraft:cave_air"));
 }
Ejemplo n.º 8
0
 public BlockState(ProtoBlock blockType)
 {
     if (blockType == null)
     {
         throw new NullReferenceException("Attempted to create a BlockState with a null ProtoBlock.");
     }
     block = blockType;
     AddDefaultBlockProperties();
 }
Ejemplo n.º 9
0
 public static Color GetMapColor(ProtoBlock block, int shade)
 {
     if (colormap == null)
     {
         colormap = LoadColorMap();
     }
     if (block != null)
     {
         if (!colorMapIndices.TryGetValue(block.ID, out int index))
         {
             index = 15;
         }
         shade = 1 - shade;
         return(colormap[index, shade]);
     }
     else
     {
         return(Color.FromArgb(0, 0, 0, 0));
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Registers a new vanilla block type.
 /// </summary>
 public static ProtoBlock[] RegisterNewVanillaBlock(string shortID, Version versionAdded, ProtoBlock substitute = null)
 {
     return(RegisterNewBlock(null, shortID, versionAdded, substitute));
 }
Ejemplo n.º 11
0
        public static bool IsTransparentBlock(ProtoBlock b)
        {
            string id = b.ID;

            if (id == null)
            {
                return(true);
            }
            if (id.Contains("minecraft:glass"))
            {
                return(true);
            }
            if (id.Contains("minecraft:bars"))
            {
                return(true);
            }
            if (id.Contains("minecraft:sapling"))
            {
                return(true);
            }
            if (id.Contains("minecraft:rail"))
            {
                return(true);
            }
            if (id.Contains("minecraft:tulip"))
            {
                return(true);
            }
            if (id.Contains("minecraft:mushroom"))
            {
                return(true);
            }
            if (id.Contains("minecraft:pressure_plate"))
            {
                return(true);
            }
            if (id.Contains("minecraft:button"))
            {
                return(true);
            }
            if (id.Contains("minecraft:torch"))
            {
                return(true);
            }
            if (id.Contains("minecraft:fence"))
            {
                return(true);
            }
            if (id.Contains("minecraft:door"))
            {
                return(true);
            }
            if (id.Contains("minecraft:carpet"))
            {
                return(true);
            }
            switch (id)
            {
            case "minecraft:air":
            case "minecraft:cave_air":
            case "minecraft:cobweb":
            case "minecraft:grass":
            case "minecraft:fern":
            case "minecraft:dead_bush":
            case "minecraft:seagrass":
            case "minecraft:sea_pickle":
            case "minecraft:dandelion":
            case "minecraft:poppy":
            case "minecraft:blue_orchid":
            case "minecraft:allium":
            case "minecraft:azure_bluet":
            case "minecraft:end_rod":
            case "minecraft:ladder":
            case "minecraft:lever":
            case "minecraft:snow":
            case "minecraft:lily_pad":
            case "minecraft:tripwire_hook":
            case "minecraft:barrier":
            case "minecraft:tall_grass":
            case "minecraft:large_fern":
            case "minecraft:sunflower":
            case "minecraft:lilac":
            case "minecraft:rose_bush":
            case "minecraft:peony":
            case "minecraft:structure_void":
            case "minecraft:turtle_egg":
            case "minecraft:redstone":
            case "minecraft:sweet_berry_bush": return(true);
            }
            return(false);
        }