private void Inv_SlotModified(int slotid)
        {
            TreeAttribute tree = new TreeAttribute();

            inv.ToTreeAttributes(tree);
            entity.WatchedAttributes["harvestableInv"] = tree;
            entity.WatchedAttributes.MarkPathDirty("harvestableInv");
        }
Ejemplo n.º 2
0
        public override bool OnPlayerRightClick(IPlayer byPlayer, BlockSelection blockSel)
        {
            if (api.World is IServerWorldAccessor)
            {
                byte[] data;

                using (MemoryStream ms = new MemoryStream())
                {
                    BinaryWriter writer = new BinaryWriter(ms);
                    writer.Write("BlockEntityInventory");
                    writer.Write(Lang.Get(dialogTitleLangCode));
                    writer.Write((byte)4);
                    TreeAttribute tree = new TreeAttribute();
                    inventory.ToTreeAttributes(tree);
                    tree.ToBytes(writer);
                    data = ms.ToArray();
                }

                ((ICoreServerAPI)api).Network.SendBlockEntityPacket(
                    (IServerPlayer)byPlayer,
                    pos.X, pos.Y, pos.Z,
                    (int)EnumBlockContainerPacketId.OpenInventory,
                    data
                    );

                byPlayer.InventoryManager.OpenInventory(inventory);
            }

            return(true);
        }
Ejemplo n.º 3
0
        internal void SaveDeathContent(InventoryGeneric inventory, IPlayer player)
        {
            ICoreAPI api = player.Entity?.Api;

            if (api == null)
            {
                throw new NullReferenceException("player.Entity.api is null");
            }

            string datapath = api.GetOrCreateDataPath($"ModData/{api.GetWorldId()}/{ConstantsCore.ModId}/{player.PlayerUID}");

            string[] files = Directory.GetFiles(datapath).OrderByDescending(f => new FileInfo(f).Name).ToArray();

            for (int i = files.Count() - 1; i > Config.Current.MaxDeathContentSavedPerPlayer.Val - 2; i--)
            {
                File.Delete(files[i]);
            }

            TreeAttribute tree = new TreeAttribute();

            inventory.ToTreeAttributes(tree);

            string name = "inventory-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".dat";

            File.WriteAllBytes($"{datapath}/{name}", tree.ToBytes());
        }
Ejemplo n.º 4
0
        public override void ToTreeAttributes(ITreeAttribute tree)
        {
            base.ToTreeAttributes(tree);
            ITreeAttribute invtree = new TreeAttribute();

            inventory.ToTreeAttributes(invtree);
            tree["inventory"] = invtree;
        }
Ejemplo n.º 5
0
        public override void ToTreeAttributes(ITreeAttribute tree)
        {
            base.ToTreeAttributes(tree);

            bloomeryInv.ToTreeAttributes(tree);
            tree.SetInt("burning", burning ? 1 : 0);
            tree.SetDouble("burningUntilTotalDays", burningUntilTotalDays);
            tree.SetDouble("burningStartTotalDays", burningStartTotalDays);
        }
Ejemplo n.º 6
0
        private void GearInv_SlotModified(int t1)
        {
            ITreeAttribute tree = new TreeAttribute();

            WatchedAttributes["inventory"] = tree;

            gearInv.ToTreeAttributes(tree);
            WatchedAttributes.MarkPathDirty("inventory");
        }
        private void MouthInv_SlotModified(int slotid)
        {
            ITreeAttribute tree = new TreeAttribute();

            entity.WatchedAttributes["mouthInv"] = tree;
            entity.WatchedAttributes.MarkPathDirty("mouthInv");
            mouthInv.ToTreeAttributes(tree);

            if (entityAgent.Api is ICoreServerAPI sapi)
            {
                sapi.Network.BroadcastEntityPacket(entity.EntityId, 1235, SerializerUtil.ToBytes((w) => tree.ToBytes(w)));
            }
        }
        private void WorkInv_SlotModified(int slotid)
        {
            ITreeAttribute tree = new TreeAttribute();

            maintree["workInv"] = tree;
            entity.WatchedAttributes.MarkPathDirty("reprog");
            workInv.ToTreeAttributes(tree);

            if (entity.Api is ICoreServerAPI sapi)
            {
                sapi.Network.BroadcastEntityPacket(entity.EntityId, 2450, SerializerUtil.ToBytes((w) => tree.ToBytes(w)));
            }
        }
Ejemplo n.º 9
0
    public override void ToTreeAttributes(ITreeAttribute tree)
    {
        base.ToTreeAttributes(tree);
        ITreeAttribute invtree = new TreeAttribute();

        inventory.ToTreeAttributes(invtree);
        tree["inventory"] = invtree;

        if (energyStorage != null)
        {
            tree.SetFloat("energy", energyStorage.getEnergyStored());
        }
    }
Ejemplo n.º 10
0
        public override void ToTreeAttributes(ITreeAttribute tree)
        {
            base.ToTreeAttributes(tree);
            _inv.ToTreeAttributes(tree);
            if (PlayerUid != null)
            {
                tree.SetString("playerUID", PlayerUid);
            }

            if (PlayerName != null)
            {
                tree.SetString("playerName", PlayerName);
            }
        }
Ejemplo n.º 11
0
        public override bool OnPlayerRightClick(IPlayer byPlayer, BlockSelection blockSel)
        {
            if (byPlayer.WorldData.CurrentGameMode == EnumGameMode.Creative)
            {
                inventory.PutLocked = false;
            }

            if (inventory.PutLocked && inventory.Empty)
            {
                return(false);
            }

            if (Api.World is IServerWorldAccessor)
            {
                byte[] data;

                using (MemoryStream ms = new MemoryStream())
                {
                    BinaryWriter writer = new BinaryWriter(ms);
                    writer.Write("BlockEntityInventory");
                    writer.Write(DialogTitle);
                    writer.Write((byte)quantityColumns);
                    TreeAttribute tree = new TreeAttribute();
                    inventory.ToTreeAttributes(tree);
                    tree.ToBytes(writer);
                    data = ms.ToArray();
                }

                ((ICoreServerAPI)Api).Network.SendBlockEntityPacket(
                    (IServerPlayer)byPlayer,
                    Pos.X, Pos.Y, Pos.Z,
                    (int)EnumBlockContainerPacketId.OpenInventory,
                    data
                    );

                byPlayer.InventoryManager.OpenInventory(inventory);
            }

            return(true);
        }
Ejemplo n.º 12
0
        public void SaveDeathContent(InventoryGeneric inventory, IPlayer player)
        {
            ICoreAPI api = player.Entity.Api;

            string localPath = "ModData" + api.GetWorldId() + "/" + Mod.Info.ModID + "/" + player.PlayerUID;
            string path      = api.GetOrCreateDataPath(localPath);

            string[] files = Directory.GetFiles(path).OrderByDescending(f => new FileInfo(f).Name).ToArray();

            for (int i = files.Length - 1; i > Config.Current.MaxDeathContentSavedPerPlayer.Value - 2; i--)
            {
                File.Delete(files[i]);
            }

            TreeAttribute tree = new TreeAttribute();

            inventory.ToTreeAttributes(tree);

            string name = "inventory-" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".dat";

            File.WriteAllBytes(path + "/" + name, tree.ToBytes());
        }
Ejemplo n.º 13
0
        public void SetHarvested(IPlayer byPlayer, float dropQuantityMultiplier = 1f)
        {
            //entity.World.Logger.Debug("setharvested begin " + entity.World.Side);

            if (entity.WatchedAttributes.GetBool("harvested", false))
            {
                return;
            }

            entity.WatchedAttributes.SetBool("harvested", true);

            if (entity.World.Side == EnumAppSide.Client)
            {
                return;
            }


            List <ItemStack> todrop = new List <ItemStack>();


            for (int i = 0; i < jsonDrops.Length; i++)
            {
                if (jsonDrops[i].Tool != null && (byPlayer == null || jsonDrops[i].Tool != byPlayer.InventoryManager.ActiveTool))
                {
                    continue;
                }

                jsonDrops[i].Resolve(entity.World, "BehaviorHarvestable");

                ItemStack stack = jsonDrops[i].GetNextItemStack(this.dropQuantityMultiplier * dropQuantityMultiplier);
                if (stack == null)
                {
                    continue;
                }

                todrop.Add(stack);
                if (jsonDrops[i].LastDrop)
                {
                    break;
                }
            }

            //entity.World.Logger.Debug("setharvested drops resolved");

            ItemStack[] resolvedDrops = todrop.ToArray();

            TreeAttribute tree = new TreeAttribute();

            for (int i = 0; i < resolvedDrops.Length; i++)
            {
                inv[i].Itemstack = resolvedDrops[i];

                //entity.World.Logger.Debug("drop {0} is {1}", i, resolvedDrops[i]?.GetName());
            }

            inv.ToTreeAttributes(tree);
            entity.WatchedAttributes["harvestableInv"] = tree;
            entity.WatchedAttributes.MarkPathDirty("harvestableInv");
            entity.WatchedAttributes.MarkPathDirty("harvested");

            if (entity.World.Side == EnumAppSide.Server)
            {
                entity.World.BlockAccessor.GetChunkAtBlockPos(entity.ServerPos.AsBlockPos).MarkModified();
            }

            //entity.World.Logger.Debug("setharvested done");
        }