예제 #1
0
        public override void OnBeingLookedAt(IPlayer byPlayer, BlockSelection blockSel, bool firstTick)
        {
            if (firstTick && api.Side == EnumAppSide.Server)
            {
                BlockEntityTapestry beTas = api.World.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityTapestry;
                if (beTas.Rotten)
                {
                    return;
                }

                string baseCode = GetBaseCode(beTas.Type);
                string size     = Attributes["sizes"][baseCode].AsString();
                Dictionary <string, TVec2i[]> neighbours;

                switch (size)
                {
                case "2x1":
                    neighbours = neighbours2x1;
                    break;

                case "1x2":
                    neighbours = neighbours1x2;
                    break;

                case "3x1":
                    neighbours = neighbours3x1;
                    break;

                case "2x2":
                    neighbours = neighbours2x2;
                    break;

                default:
                    throw new Exception("invalid tapestry json config - missing size attribute for size '" + size + "'");
                }

                string   intComp = beTas.Type.Substring(baseCode.Length);
                TVec2i[] vecs    = neighbours[intComp];

                if (isComplete(blockSel.Position, baseCode, vecs))
                {
                    ModJournal jour = api.ModLoader.GetModSystem <ModJournal>();
                    if (!jour.DidDiscoverLore(byPlayer.PlayerUID, LoreCode, GetLoreChapterId(baseCode)))
                    {
                        var splr = byPlayer as IServerPlayer;
                        jour.DiscoverLore(new LoreDiscovery()
                        {
                            Code = LoreCode, ChapterIds = new List <int>()
                            {
                                GetLoreChapterId(baseCode)
                            }
                        }, splr);
                    }
                }
            }
        }
예제 #2
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityTapestry bet = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityTapestry;

            ItemStack stack = new ItemStack(this);

            stack.Attributes.SetString("type", bet?.Type);
            stack.Attributes.SetBool("rotten", bet?.Rotten == true);

            return(stack);
        }
예제 #3
0
        public override string GetPlacedBlockName(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityTapestry bet = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityTapestry;

            if (bet?.Rotten == true)
            {
                return(Lang.Get("Rotten Tapestry"));
            }

            return(base.GetPlacedBlockName(world, pos));
        }
예제 #4
0
        public override string GetPlacedBlockName(IWorldAccessor world, BlockPos pos)
        {
            BlockEntityTapestry bet = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityTapestry;

            if (bet?.Rotten == true)
            {
                return(Lang.Get("Rotten Tapestry"));
            }

            string type = bet?.Type;

            return(Lang.Get("tapestry-name", Lang.GetMatching("tapestry-" + type)));
        }
예제 #5
0
        public override ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, float dropQuantityMultiplier = 1)
        {
            ItemStack[] stacks = base.GetDrops(world, pos, byPlayer, dropQuantityMultiplier);

            BlockEntityTapestry bet = api.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityTapestry;

            if (bet.Rotten)
            {
                return(new ItemStack[0]);
            }

            stacks[0].Attributes.SetString("type", bet?.Type);

            return(stacks);
        }
예제 #6
0
        private bool isComplete(BlockPos position, string baseCode, TVec2i[] vecs)
        {
            foreach (var vec in vecs)
            {
                Vec3i offs;
                switch (orientation.Index)
                {
                // n
                case 0: offs = new Vec3i(vec.X, vec.Y, 0); break;

                // e
                case 1: offs = new Vec3i(0, vec.Y, vec.X); break;

                // s
                case 2: offs = new Vec3i(-vec.X, vec.Y, 0); break;

                // w
                case 3: offs = new Vec3i(0, vec.Y, -vec.X); break;

                default: return(false);
                }

                BlockEntityTapestry bet = api.World.BlockAccessor.GetBlockEntity(position.AddCopy(offs.X, offs.Y, offs.Z)) as BlockEntityTapestry;

                if (bet == null)
                {
                    return(false);
                }
                string nbaseCode = GetBaseCode(bet.Type);
                if (nbaseCode != baseCode)
                {
                    return(false);
                }
                if (bet.Rotten)
                {
                    return(false);
                }

                string intComp = bet.Type.Substring(nbaseCode.Length);

                if (intComp != vec.IntComp)
                {
                    return(false);
                }
            }

            return(true);
        }