Esempio n. 1
0
        public SwapBlocks Copy()
        {
            SwapBlocks copy = new SwapBlocks(Takes, Makes, Tool, Count);

            return(copy);
        }
Esempio n. 2
0
        public void PostOLInit()
        {
            SwapSystem swapSystem = api.ModLoader.GetModSystem <SwapSystem>();

            requireSneak   = properties["requireSneak"].AsBool(requireSneak);
            particleOrigin = properties["particleOrigin"].Exists ? properties["particleOrigin"].AsObject <Vec3d>() : particleOrigin;
            pRadius        = properties["particleRadius"].AsInt(pRadius);
            pQuantity      = properties["particleQuantity"].AsInt(pQuantity);
            playSound      = properties["playSound"].AsBool(true);

            if (properties["allowedVariants"].Exists)
            {
                string[] allowed = properties["allowedVariants"].AsArray <string>().WithDomain();

                disabled = true;
                if (allowed.Contains(block.Code.ToString()))
                {
                    disabled = false;
                }
                else
                {
                    return;
                }
            }
            if (properties["swapBlocks"].Exists)
            {
                if (api.World.Side.IsServer())
                {
                    try
                    {
                        SwapBlocks[] swapBlocks = properties["swapBlocks"].AsObject <SwapBlocks[]>();
                        foreach (SwapBlocks val in swapBlocks)
                        {
                            if (val.Tool.Contains("*"))
                            {
                                for (int i = 0; i < api.World.Blocks.Count; i++)
                                {
                                    Block iBlock = api.World.Blocks[i];
                                    if (iBlock != null && iBlock.WildCardMatch(new AssetLocation(val.Tool)))
                                    {
                                        SwapBlocks tmp = val.Copy();
                                        tmp.Tool = iBlock.Code.ToString();
                                        if (!swapSystem.SwapPairs.ContainsKey(GetKey(tmp.Tool)))
                                        {
                                            swapSystem.SwapPairs.Add(GetKey(tmp.Tool), tmp);
                                        }
                                    }
                                }
                                for (int i = 0; i < api.World.Items.Count; i++)
                                {
                                    Item iItem = api.World.Items[i];
                                    if (iItem != null && iItem.WildCardMatch(new AssetLocation(val.Tool)))
                                    {
                                        SwapBlocks tmp = val.Copy();
                                        tmp.Tool = iItem.Code.ToString();
                                        if (!swapSystem.SwapPairs.ContainsKey(GetKey(tmp.Tool)))
                                        {
                                            swapSystem.SwapPairs.Add(GetKey(tmp.Tool), tmp);
                                        }
                                    }
                                }
                            }
                            else if (!swapSystem.SwapPairs.ContainsKey(GetKey(val.Tool)))
                            {
                                swapSystem.SwapPairs.Add(GetKey(val.Tool), val);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        disabled = true;
                        api.World.Logger.Notification("Deprecated or unsupported use of swapblocks in " + block.Code.ToString());
                    }
                }
            }
            else
            {
                disabled = true;
                return;
            }
        }