예제 #1
0
 private void onLeafDecayEventReceived(string eventName, ref EnumHandling handling, IAttribute data)
 {
     if (checkDecayThread != null)
     {
         TreeAttribute tree = data as TreeAttribute;
         BlockPos      pos  = new BlockPos(tree.GetInt("x"), tree.GetInt("y"), tree.GetInt("z"));
         queueNeighborsForCheckDecay(pos);
     }
 }
예제 #2
0
        public static IMountable GetMountable(IWorldAccessor world, TreeAttribute tree)
        {
            BlockPos pos   = new BlockPos(tree.GetInt("posx"), tree.GetInt("posy"), tree.GetInt("posz"));
            Block    block = world.BlockAccessor.GetBlock(pos);

            BlockFacing    facing = BlockFacing.FromCode(block.LastCodePart());
            BlockEntityBed beBed  = world.BlockAccessor.GetBlockEntity(block.LastCodePart(1) == "feet" ? pos.AddCopy(facing) : pos) as BlockEntityBed;

            return(beBed);
        }
예제 #3
0
        internal InventoryGeneric LoadLastDeathContent(IPlayer player, int offset = 0)
        {
            ICoreAPI api = player.Entity?.Api;

            if (api == null)
            {
                throw new NullReferenceException("player.Entity.api is null");
            }
            if (Config.Current.MaxDeathContentSavedPerPlayer.Val <= offset)
            {
                throw new IndexOutOfRangeException("offset is too large or save data disabled");
            }

            string datapath = api.GetOrCreateDataPath($"ModData/{api.GetWorldId()}/{ConstantsCore.ModId}/{player.PlayerUID}");
            string file     = Directory.GetFiles(datapath).OrderByDescending(f => new FileInfo(f).Name).ToArray().ElementAt(offset);

            TreeAttribute tree = new TreeAttribute();

            tree.FromBytes(File.ReadAllBytes(file));

            InventoryGeneric inv = new InventoryGeneric(tree.GetInt("qslots"), "playercorpse-" + player.PlayerUID, api);

            inv.FromTreeAttributes(tree);
            return(inv);
        }
예제 #4
0
        public InventoryGeneric LoadLastDeathContent(IPlayer player, int offset = 0)
        {
            ICoreAPI api = player.Entity.Api;

            if (Config.Current.MaxDeathContentSavedPerPlayer.Value <= offset)
            {
                throw new IndexOutOfRangeException("offset is too large or save data disabled");
            }

            string localPath = "ModData" + api.GetWorldId() + "/" + Mod.Info.ModID + "/" + player.PlayerUID;
            string path      = api.GetOrCreateDataPath(localPath);
            string file      = Directory.GetFiles(path).OrderByDescending(f => new FileInfo(f).Name).ToArray().ElementAt(offset);

            TreeAttribute tree = new TreeAttribute();

            tree.FromBytes(File.ReadAllBytes(file));

            InventoryGeneric inv = new InventoryGeneric(tree.GetInt("qslots"), "playercorpse-" + player.PlayerUID, api);

            inv.FromTreeAttributes(tree);
            return(inv);
        }
예제 #5
0
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            base.FromTreeAttributes(tree, worldForResolving);

            bool wasHarvestable = Harvestable;

            scanIteration = tree.GetInt("scanIteration");

            quantityNearbyFlowers = tree.GetInt("quantityNearbyFlowers");
            quantityNearbyHives   = tree.GetInt("quantityNearbyHives");
            emptySkeps.Clear();
            TreeAttribute emptySkepTree = tree["emptyskeps"] as TreeAttribute;

            for (int i = 0; i < emptySkepTree.Count / 3; i++)
            {
                emptySkeps.Add(new BlockPos(
                                   emptySkepTree.GetInt("posX-" + i),
                                   emptySkepTree.GetInt("posY-" + i),
                                   emptySkepTree.GetInt("posZ-" + i)
                                   ));
            }


            scanQuantityNearbyFlowers = tree.GetInt("scanQuantityNearbyFlowers");
            scanQuantityNearbyHives   = tree.GetInt("scanQuantityNearbyHives");
            scanEmptySkeps.Clear();
            TreeAttribute scanEmptySkepTree = tree["scanEmptySkeps"] as TreeAttribute;

            for (int i = 0; scanEmptySkepTree != null && i < scanEmptySkepTree.Count / 3; i++)
            {
                scanEmptySkeps.Add(new BlockPos(
                                       scanEmptySkepTree.GetInt("posX-" + i),
                                       scanEmptySkepTree.GetInt("posY-" + i),
                                       scanEmptySkepTree.GetInt("posZ-" + i)
                                       ));
            }


            isWildHive  = tree.GetInt("isWildHive") > 0;
            Harvestable = tree.GetInt("harvestable") > 0;
            int x = tree.GetInt("skepToPopX");
            int y = tree.GetInt("skepToPopY");
            int z = tree.GetInt("skepToPopZ");

            if (x != 0 || y != 0 || z != 0)
            {
                skepToPop = new BlockPos(x, y, z);
            }
            else
            {
                skepToPop = null;
            }

            beginPopStartTotalHours = tree.GetDouble("beginPopStartTotalHours");
            popHiveAfterHours       = tree.GetFloat("popHiveAfterHours");
            cooldownUntilTotalHours = tree.GetDouble("cooldownUntilTotalHours");
            harvestableAtTotalHours = tree.GetDouble("harvestableAtTotalHours");
            hivePopSize             = (EnumHivePopSize)tree.GetInt("hiveHealth");

            if (Harvestable != wasHarvestable && Api != null)
            {
                MarkDirty(true);
            }
        }