public BlockEntityBarrel() { inventory = new InventoryGeneric(2, null, null, (id, self) => { if (id == 0) { return(new ItemSlotBarrelInput(self)); } else { return(new ItemSlotLiquidOnly(self)); } }); inventory.OnAcquireTransitionSpeed = (type, stack, basemul) => { // Don't spoil while sealed if (Sealed && CurrentRecipe != null && CurrentRecipe.SealHours > 0) { return(0); } return(type == EnumTransitionType.Perish ? 1 : 0); }; inventory.SlotModified += Inventory_SlotModified; }
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()); }
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); }
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); }
public GuiDialogCarcassContents(InventoryGeneric inv, EntityAgent owningEntity, ICoreClientAPI capi) : base(capi) { this.inv = inv; this.owningEntity = owningEntity; double pad = GuiElementItemSlotGrid.unscaledSlotPadding; int rows = (int)Math.Ceiling(inv.Count / 4f); ElementBounds slotBounds = ElementStdBounds.SlotGrid(EnumDialogArea.None, pad, 40 + pad, 4, rows).FixedGrow(2 * pad, 2 * pad); ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); bgBounds.BothSizing = ElementSizing.FitToChildren; ElementBounds dialogBounds = ElementStdBounds .AutosizedMainDialog.WithAlignment(EnumDialogArea.RightMiddle) .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0); SingleComposer = capi.Gui .CreateCompo("carcasscontents" + owningEntity.EntityId, dialogBounds) .AddShadedDialogBG(bgBounds, true) .AddDialogTitleBar(Lang.Get("carcass-contents"), OnTitleBarClose) .BeginChildElements(bgBounds) .AddItemSlotGrid(inv, DoSendPacket, 4, slotBounds, "slots") .EndChildElements() .Compose() ; }
public override string GetBlockInfo(IPlayer forPlayer) { float rate = GetPerishRate(); if (Inventory is InventoryGeneric) { InventoryGeneric inv = Inventory as InventoryGeneric; float rateMul = 1; if (inv.TransitionableSpeedMulByType != null && inv.TransitionableSpeedMulByType.TryGetValue(EnumTransitionType.Perish, out rateMul)) { rate *= rateMul; } if (inv.PerishableFactorByFoodCategory != null) { StringBuilder sb = new StringBuilder(); sb.AppendLine(Lang.Get("Stored food perish speed:")); foreach (var val in inv.PerishableFactorByFoodCategory) { sb.AppendLine(Lang.Get("- {0}: {1}x", Lang.Get(val.Key.ToString()), Math.Round(rate * val.Value, 2))); } if (inv.PerishableFactorByFoodCategory.Count != Enum.GetValues(typeof(EnumFoodCategory)).Length) { sb.AppendLine(Lang.Get("- {0}: {1}x", Lang.Get("Other"), Math.Round(rate, 2))); } return(sb.ToString()); } } return(Lang.Get("Stored food perish speed: {0}x", Math.Round(rate, 2))); }
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); }
public GuiDialogCreateAuction(ICoreClientAPI capi, EntityAgent owningEntity, InventoryGeneric auctionSlotInv) : base(capi) { this.owningEntity = owningEntity; this.auctionSlotInv = auctionSlotInv; auctionSys = capi.ModLoader.GetModSystem <ModSystemAuction>(); Init(); }
private void InitInventory(Block Block) { // Ripped right out of the SurvivalMod code. this.inventory = new InventoryGeneric(quantitySlots, null, null, null); this.inventory.OnInventoryClosed += OnInvClosed; this.inventory.OnInventoryOpened += OnInvOpened; this.inventory.SlotModified += OnSlotModified; }
private ItemSlot onNewSlot(int slotId, InventoryGeneric self) { EnumCharacterDressType type = (EnumCharacterDressType)slotId; ItemSlotCharacter slot = new ItemSlotCharacter(type, self); iconByDressType.TryGetValue(type, out slot.BackgroundIcon); return(slot); }
private void InitInventory() { if (inventory == null) { inventory = new InventoryGeneric(1, null, null, null); inventory.OnInventoryClosed += OnInventoryClosed; inventory.OnInventoryOpened += OnInvOpened; inventory.SlotModified += OnSlotModified; } }
private void InitInventory() { if (Block?.Attributes != null) { if (Block.Attributes["pullFaces"].Exists) { string[] faces = Block.Attributes["pullFaces"].AsArray <string>(null); PullFaces = new BlockFacing[faces.Length]; for (int i = 0; i < faces.Length; i++) { PullFaces[i] = BlockFacing.FromCode(faces[i]); } } if (Block.Attributes["pushFaces"].Exists) { string[] faces = Block.Attributes["pushFaces"].AsArray <string>(null); PushFaces = new BlockFacing[faces.Length]; for (int i = 0; i < faces.Length; i++) { PushFaces[i] = BlockFacing.FromCode(faces[i]); } } if (Block.Attributes["acceptFromFaces"].Exists) { string[] faces = Block.Attributes["acceptFromFaces"].AsArray <string>(null); AcceptFromFaces = new BlockFacing[faces.Length]; for (int i = 0; i < faces.Length; i++) { AcceptFromFaces[i] = BlockFacing.FromCode(faces[i]); } } itemFlowRate = Block.Attributes["item-flowrate"].AsFloat(itemFlowRate); checkRateMs = Block.Attributes["item-checkrateMs"].AsInt(200); inventoryClassName = Block.Attributes["inventoryClassName"].AsString(inventoryClassName); ItemFlowObjectLangCode = Block.Attributes["itemFlowObjectLangCode"].AsString(ItemFlowObjectLangCode); QuantitySlots = Block.Attributes["quantitySlots"].AsInt(QuantitySlots); } if (inventory == null) { inventory = new InventoryGeneric(QuantitySlots, null, null, null); inventory.OnInventoryClosed += OnInvClosed; inventory.OnInventoryOpened += OnInvOpened; inventory.SlotModified += OnSlotModifid; inventory.OnGetAutoPushIntoSlot = GetAutoPushIntoSlot; inventory.OnGetAutoPullFromSlot = GetAutoPullFromSlot; } }
private void InitInventory(Block block) { this.ownBlock = block; if (block?.Attributes != null) { inventoryClassName = block.Attributes["inventoryClassName"].AsString(inventoryClassName); dialogTitleLangCode = block.Attributes["dialogTitleLangCode"].AsString(dialogTitleLangCode); quantitySlots = block.Attributes["quantitySlots"].AsInt(quantitySlots); retrieveOnly = block.Attributes["retrieveOnly"].AsBool(false); } inventory = new InventoryGeneric(quantitySlots, null, null, null); inventory.OnInventoryClosed += OnInvClosed; inventory.OnInventoryOpened += OnInvOpened; }
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); } }
public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d) { base.Initialize(properties, api, InChunkIndex3d); if (gearInv == null) { gearInv = new InventoryGeneric(17, "gear-" + EntityId, api, onNewSlot); gearInv.SlotModified += GearInv_SlotModified; } if (api.Side == EnumAppSide.Client) { WatchedAttributes.RegisterModifiedListener("inventory", readInventoryFromAttributes); } readInventoryFromAttributes(); }
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(); } } }
public BlockEntitySingleSink() { inventory = new InventoryGeneric(9, null, null, (id, self) => { if (id == 0 || id == 2 || id == 3 || id == 4 || id == 5 || id == 6 || id == 7 || id == 8) { return(new ItemSlotBarrelInput(self)); } else { return(new ItemSlotLiquidOnly(self, 50)); } }); inventory.BaseWeight = 1; inventory.OnGetSuitability = (sourceSlot, targetSlot, isMerge) => (isMerge ? (inventory.BaseWeight + 3) : (inventory.BaseWeight + 3)) + (sourceSlot.Inventory is InventoryBasePlayer ? 9 : 0); inventory.SlotModified += Inventory_SlotModified; }
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; } }
public BlockEntityCauld() { inventory = new InventoryGeneric(7, null, null, (id, self) => { if (id >= 0 && id < 5) { return(new ItemSlotWatertight(self)); } else if (id == 5) { return(new ItemSlotLiquidOutput(self, 50)); } else { return(new ItemSlotLiquidOnly(self, 50)); } }); inventory.BaseWeight = 1; inventory.OnGetSuitability = (sourceSlot, targetSlot, isMerge) => (isMerge ? (inventory.BaseWeight + 3) : (inventory.BaseWeight + 1)) + (sourceSlot.Inventory is InventoryBasePlayer ? 6 : 0); inventory.SlotModified += Inventory_SlotModified; }
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()); }
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 GetBlockInfo(IPlayer forPlayer, StringBuilder dsc) { base.GetBlockInfo(forPlayer, dsc); room = roomReg.GetRoomForPosition(Pos); float rate = GetPerishRate(); if (Inventory is InventoryGeneric) { InventoryGeneric inv = Inventory as InventoryGeneric; float rateMul; if (inv.TransitionableSpeedMulByType != null && inv.TransitionableSpeedMulByType.TryGetValue(EnumTransitionType.Perish, out rateMul)) { rate *= rateMul; } if (inv.PerishableFactorByFoodCategory != null) { dsc.AppendLine(Lang.Get("Stored food perish speed:")); foreach (var val in inv.PerishableFactorByFoodCategory) { string type = Lang.Get("foodcategory-" + val.Key.ToString().ToLowerInvariant()); dsc.AppendLine(Lang.Get("- {0}: {1}x", type, Math.Round(rate * val.Value, 2))); } if (inv.PerishableFactorByFoodCategory.Count != Enum.GetValues(typeof(EnumFoodCategory)).Length) { dsc.AppendLine(Lang.Get("- {0}: {1}x", Lang.Get("food_perish_speed_other"), Math.Round(rate, 2))); } return; } } dsc.AppendLine(Lang.Get("Stored food perish speed: {0}x", Math.Round(rate, 2))); }
protected virtual void InitInventory(Block block) { this.ownBlock = block; if (block?.Attributes != null) { inventoryClassName = block.Attributes["inventoryClassName"].AsString(inventoryClassName); dialogTitleLangCode = block.Attributes["dialogTitleLangCode"][type].AsString(dialogTitleLangCode); quantitySlots = block.Attributes["quantitySlots"][type].AsInt(quantitySlots); retrieveOnly = block.Attributes["retrieveOnly"][type].AsBool(false); } inventory = new InventoryGeneric(quantitySlots, null, null, null); inventory.PutLocked = retrieveOnly; inventory.OnInventoryClosed += OnInvClosed; inventory.OnInventoryOpened += OnInvOpened; if (api?.Side == EnumAppSide.Client) { ownMesh = GenMesh(); } }
public GuiDialogTrader(InventoryTrader traderInventory, EntityAgent owningEntity, ICoreClientAPI capi, int rows = 4, int cols = 4) : base(capi) { auctionSys = capi.ModLoader.GetModSystem <ModSystemAuction>(); auctionSys.OnCellUpdateClient = () => { listElem?.ReloadCells(auctions); updateScrollbarBounds(); }; auctionSys.curTraderClient = owningEntity as EntityTrader; this.traderInventory = traderInventory; this.owningEntity = owningEntity; this.rows = rows; this.cols = cols; if (!auctionSys.createAuctionSlotByPlayer.TryGetValue(capi.World.Player.PlayerUID, out auctionSlotInv)) { auctionSys.createAuctionSlotByPlayer[capi.World.Player.PlayerUID] = auctionSlotInv = new InventoryGeneric(1, "auctionslot-" + capi.World.Player.PlayerUID, capi); } capi.Network.SendPacketClient(auctionSlotInv.Open(capi.World.Player)); Compose(); }