public override void OnReceivedServerPacket(int packetid, byte[] data, ref EnumHandling handled)
 {
     if (packetid == 1235)
     {
         TreeAttribute tree = new TreeAttribute();
         SerializerUtil.FromBytes(data, (r) => tree.FromBytes(r));
         mouthInv.FromTreeAttributes(tree);
     }
 }
Example #2
0
        private void readInventoryFromAttributes()
        {
            ITreeAttribute tree = WatchedAttributes["inventory"] as ITreeAttribute;

            if (gearInv != null && tree != null)
            {
                gearInv.FromTreeAttributes(tree);
            }

            (Properties.Client.Renderer as EntityShapeRenderer)?.MarkShapeModified();
        }
Example #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);
        }
Example #4
0
        public bool MergeWith(TreeAttribute blockEntityAttributes)
        {
            InventoryGeneric otherinv = new InventoryGeneric(1, BlockCode, null, null, null);

            otherinv.FromTreeAttributes(blockEntityAttributes.GetTreeAttribute("inventory"));
            otherinv.Api = Api;
            otherinv.ResolveBlocksOrItems();

            if (!inventory[0].Empty && otherinv[0].Itemstack.Equals(Api.World, inventory[0].Itemstack, GlobalConstants.IgnoredStackAttributes))
            {
                int quantityToMove = Math.Min(otherinv[0].StackSize, Math.Max(0, MaxStackSize - inventory[0].StackSize));
                inventory[0].Itemstack.StackSize += quantityToMove;

                otherinv[0].TakeOut(quantityToMove);
                if (otherinv[0].StackSize > 0)
                {
                    BlockPos uppos   = Pos.UpCopy();
                    Block    upblock = Api.World.BlockAccessor.GetBlock(uppos);
                    if (upblock.Replaceable > 6000)
                    {
                        ((IBlockItemPile)Block).Construct(otherinv[0], Api.World, uppos, null);
                    }
                }

                MarkDirty(true);
                TriggerPileChanged();
            }

            return(true);
        }
Example #5
0
 public override void FromTreeAtributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve)
 {
     base.FromTreeAtributes(tree, worldAccessForResolve);
     _inv.FromTreeAttributes(tree);
     PlayerUid  = tree.GetString("playerUID");
     PlayerName = tree.GetString("playerName");
 }
Example #6
0
        public override void Initialize(EntityProperties properties, JsonObject typeAttributes)
        {
            inv = new InventoryGeneric(typeAttributes["quantitySlots"].AsInt(4), "harvestableContents-" + entity.EntityId, entity.Api);
            TreeAttribute tree = entity.WatchedAttributes["harvestableInv"] as TreeAttribute;

            if (tree != null)
            {
                inv.FromTreeAttributes(tree);
            }
            inv.PutLocked = true;

            if (entity.World.Side == EnumAppSide.Server)
            {
                inv.SlotModified      += Inv_SlotModified;
                inv.OnInventoryClosed += Inv_OnInventoryClosed;
            }

            base.Initialize(properties, typeAttributes);

            if (entity.World.Side == EnumAppSide.Server)
            {
                jsonDrops = typeAttributes["drops"].AsObject <BlockDropItemStack[]>();
            }

            baseHarvestDuration = typeAttributes["duration"].AsFloat(5);
        }
        public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d)
        {
            base.Initialize(properties, api, InChunkIndex3d);

            if (gearInv == null)
            {
                gearInv = new InventoryGeneric(15, "gear-" + EntityId, api, onNewSlot);
                gearInv.SlotModified += GearInv_SlotModified;
            }

            ITreeAttribute tree = WatchedAttributes["inventory"] as ITreeAttribute;

            if (gearInv != null && tree != null)
            {
                gearInv.FromTreeAttributes(tree);
            }
        }
        private void onDropsModified()
        {
            TreeAttribute tree = entity.WatchedAttributes["harvestableInv"] as TreeAttribute;

            if (tree != null)
            {
                inv.FromTreeAttributes(tree);
            }

            // Maybe fixes meat reappearing non nun full harvested animals? (reported by Its Ragnar! on discord)
            entity.World.BlockAccessor.GetChunkAtBlockPos(entity.ServerPos.XYZ.AsBlockPos)?.MarkModified();
        }
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            base.FromTreeAttributes(tree, worldForResolving);
            inventory.FromTreeAttributes(tree.GetTreeAttribute("inventory"));
            if (Api != null)
            {
                inventory.Api = Api;
                inventory.ResolveBlocksOrItems();
            }

            if (Api is ICoreClientAPI)
            {
                Api.World.BlockAccessor.MarkBlockDirty(Pos);
            }
        }
Example #10
0
        public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
        {
            base.FromTreeAttributes(tree, worldForResolving);

            bloomeryInv.FromTreeAttributes(tree);
            burning = tree.GetInt("burning") > 0;
            burningUntilTotalDays = tree.GetDouble("burningUntilTotalDays");
            burningStartTotalDays = tree.GetDouble("burningStartTotalDays");

            if (burning)
            {
                ambientSound?.Start();
            }
            else
            {
                ambientSound?.Stop();
            }
        }
        public override void FromBytes(BinaryReader reader, bool forClient)
        {
            base.FromBytes(reader, forClient);

            if (WatchedAttributes != null)
            {
                string inventoryID = WatchedAttributes.GetString("invid");
                int    qslots      = WatchedAttributes.GetInt("qslots", 0);

                Inventory = new InventoryGeneric(qslots, inventoryID, Api);
                Inventory.FromTreeAttributes(WatchedAttributes);

                if (Api != null)
                {
                    Inventory.ResolveBlocksOrItems();
                }
            }
        }
Example #12
0
        public EntityBehaviorHarvestable(Entity entity) : base(entity)
        {
            if (entity.World.Side == EnumAppSide.Client)
            {
                entity.WatchedAttributes.RegisterModifiedListener("harvestableInv", onDropsModified);
            }

            inv = new InventoryGeneric(4, "harvestableContents-" + entity.EntityId, entity.Api);
            TreeAttribute tree = entity.WatchedAttributes["harvestableInv"] as TreeAttribute;

            if (tree != null)
            {
                inv.FromTreeAttributes(tree);
            }
            inv.PutLocked = true;

            if (entity.World.Side == EnumAppSide.Server)
            {
                inv.OnInventoryClosed += Inv_OnInventoryClosed;
            }
        }
Example #13
0
    public override void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldForResolving)
    {
        base.FromTreeAttributes(tree, worldForResolving);
        inventory.FromTreeAttributes(tree.GetTreeAttribute("inventory"));
        if (Api != null)
        {
            inventory.Api = Api;
            inventory.ResolveBlocksOrItems();
        }

        if (Api is ICoreClientAPI)
        {
            loadToolMeshes();
            Api.World.BlockAccessor.MarkBlockDirty(Pos);
        }

        if (energyStorage == null)
        {
            energyStorage = new FluxStorage(MyMiniLib.GetAttributeInt(Block, "storage", 10000), MyMiniLib.GetAttributeInt(Block, "input", 1000), MyMiniLib.GetAttributeInt(Block, "output", 1000));
        }
        energyStorage.setEnergy(tree.GetFloat("energy"));
    }
Example #14
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);
        }
        public override void Initialize(EntityProperties properties, JsonObject attributes)
        {
            base.Initialize(properties, attributes);

            blockCheck = entity.World.GetCachingBlockAccessor(false, false);

            if (attributes.IsTrue("relaxed"))
            {
                relaxed = true;
            }
            if (attributes.IsTrue("nochest"))
            {
                nochest = true;
            }
            if (attributes.IsTrue("nobarrel"))
            {
                nobarrel = true;
            }
            if (attributes.IsTrue("invLocked"))
            {
                invLocked = true;
            }

            if (attributes["restrictItem"] != null)
            {
                JsonItemStack prestack = attributes["restrictItem"].AsObject <JsonItemStack>();
                if (prestack != null)
                {
                    prestack.Resolve(entity.World, "Locust Program");
                    if (prestack.ResolvedItemstack != null)
                    {
                        maintree.SetItemstack("workStack", prestack.ResolvedItemstack);
                        maintree.SetBool("restrictItem", true);
                        restricted = true;
                    }
                }
            }

            ITreeAttribute area   = maintree.GetTreeAttribute("workArea");
            ITreeAttribute box    = maintree.GetTreeAttribute("workChest");
            ITreeAttribute barrel = maintree.GetTreeAttribute("workBarrel");


            workStack = maintree.GetItemstack("workStack");
            workStack?.ResolveBlockOrItem(entity.World);
            if (entity.Api.Side == EnumAppSide.Client && maintree.GetBool("restrictItem"))
            {
                restricted = true;
            }

            if (area != null)
            {
                workArea = cuboiddFromTree(area);
            }
            if (box != null)
            {
                workChest = new BlockPos(box.GetInt("x"), box.GetInt("y"), box.GetInt("z"));
            }
            if (barrel != null)
            {
                workBarrel = new BlockPos(barrel.GetInt("x"), barrel.GetInt("y"), barrel.GetInt("z"));
            }

            ITreeAttribute tree = maintree["workInv"] as ITreeAttribute;

            if (tree != null)
            {
                workInv.FromTreeAttributes(tree);
            }
        }