public override List <ItemStack> GetHandBookStacks(ICoreClientAPI capi) { if (Code == null) { return(null); } bool inCreativeTab = CreativeInventoryTabs != null && CreativeInventoryTabs.Length > 0; bool inCreativeTabStack = CreativeInventoryStacks != null && CreativeInventoryStacks.Length > 0; bool explicitlyIncluded = Attributes?["handbook"]?["include"].AsBool() == true; bool explicitlyExcluded = Attributes?["handbook"]?["exclude"].AsBool() == true; if (explicitlyExcluded) { return(null); } if (!explicitlyIncluded && !inCreativeTab && !inCreativeTabStack) { return(null); } List <ItemStack> stacks = new List <ItemStack>(); if (inCreativeTabStack) { for (int i = 0; i < CreativeInventoryStacks.Length; i++) { for (int j = 0; j < CreativeInventoryStacks[i].Stacks.Length; j++) { ItemStack stack = CreativeInventoryStacks[i].Stacks[j].ResolvedItemstack; stack.ResolveBlockOrItem(capi.World); stack = stack.Clone(); stack.StackSize = stack.Collectible.MaxStackSize; if (!stacks.Any((stack1) => stack1.Equals(stack))) { stacks.Add(stack); ItemStack otherGlass = stack.Clone(); otherGlass.Attributes.SetString("glass", "plain"); stacks.Add(otherGlass); ItemStack otherLiningSilver = stack.Clone(); ItemStack otherLiningGold = stack.Clone(); otherLiningSilver.Attributes.SetString("lining", "silver"); otherLiningGold.Attributes.SetString("lining", "gold"); stacks.Add(otherLiningSilver); stacks.Add(otherLiningGold); } } } } else { stacks.Add(new ItemStack(this)); } return(stacks); }
public void ReceiveLiquidMetal(ItemStack metal, ref int amount, float temperature) { if (lastPouringMarkdirtyMs + 500 < api.World.ElapsedMilliseconds) { MarkDirty(true); lastPouringMarkdirtyMs = api.World.ElapsedMilliseconds + 500; } if ((quantityMolds == 1 || !fillSide) && fillLevelLeft < 100 && (contentsLeft == null || metal.Collectible.Equals(contentsLeft, metal, GlobalConstants.IgnoredStackAttributes))) { if (contentsLeft == null) { contentsLeft = metal.Clone(); contentsLeft.ResolveBlockOrItem(api.World); contentsLeft.Collectible.SetTemperature(api.World, contentsLeft, temperature, false); contentsLeft.StackSize = 1; (contentsLeft.Attributes["temperature"] as ITreeAttribute)?.SetFloat("cooldownSpeed", 300); } else { contentsLeft.Collectible.SetTemperature(api.World, contentsLeft, temperature, false); } int amountToFill = Math.Min(amount, 100 - fillLevelLeft); fillLevelLeft += amountToFill; amount -= amountToFill; UpdateIngotRenderer(); return; } if (fillSide && quantityMolds > 1 && fillLevelRight < 100 && (contentsRight == null || metal.Collectible.Equals(contentsRight, metal, GlobalConstants.IgnoredStackAttributes))) { if (contentsRight == null) { contentsRight = metal.Clone(); contentsRight.ResolveBlockOrItem(api.World); contentsRight.Collectible.SetTemperature(api.World, contentsRight, temperature, false); contentsRight.StackSize = 1; (contentsRight.Attributes["temperature"] as ITreeAttribute)?.SetFloat("cooldownSpeed", 300); } else { contentsRight.Collectible.SetTemperature(api.World, contentsRight, temperature, false); } int amountToFill = Math.Min(amount, 100 - fillLevelRight); fillLevelRight += amountToFill; amount -= amountToFill; UpdateIngotRenderer(); return; } }
/// <summary> /// Tries to take out as much items/liquid as possible from a placed bucket and returns it /// </summary> /// <param name="world"></param> /// <param name="pos"></param> /// <param name="quantity"></param> public ItemStack TryTakeContent(IWorldAccessor world, BlockPos pos, int quantity) { BlockEntityBucket bebucket = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityBucket; if (bebucket == null) { return(null); } ItemStack stack = bebucket.GetContent(); if (stack == null) { return(null); } ItemStack takenStack = stack.Clone(); takenStack.StackSize = quantity; stack.StackSize -= quantity; if (stack.StackSize <= 0) { bebucket.SetContent(null); } else { bebucket.SetContent(stack); } return(takenStack); }
public override void DropAll(Vec3d pos) { foreach (var slot in this) { if (slot.Itemstack == null) { continue; } int count = slot.Itemstack.StackSize; if (count == 0) { continue; } int i = 0; while (i + 2 <= count) { ItemStack newStack = slot.Itemstack.Clone(); newStack.StackSize = 1; Api.World.SpawnItemEntity(newStack, pos); Api.World.SpawnItemEntity(newStack.Clone(), secondaryPos); i += 2; } if (i < count) { ItemStack newStack = slot.Itemstack.Clone(); newStack.StackSize = 1; Api.World.SpawnItemEntity(newStack, pos); } slot.Itemstack = null; slot.MarkDirty(); } }
/** * Copies properties from another tile entity of this type into this one. */ public void CopyLootContainerDataFromOther(TileEntityBlockTransformer _other) { this.lootListIndex = _other.lootListIndex; this.containerSize = _other.containerSize; this.items = ItemStack.Clone(_other.items); this.bTouched = _other.bTouched; this.worldTimeTouched = _other.worldTimeTouched; this.bPlayerBackpack = _other.bPlayerBackpack; this.bPlayerStorage = _other.bPlayerStorage; this.bUserAccessing = _other.bUserAccessing; this.collection = _other.collection; this.tQueue = _other.tQueue; this.useHash = _other.useHash; this.requiresPower = _other.requiresPower; this.requiresHeat = _other.requiresHeat; this.powerSources = _other.powerSources; this.heatSources = _other.heatSources; this.requiresNearbyBlocks = _other.requiresNearbyBlocks; this.nearbyBlockNames = _other.nearbyBlockNames; this.nearbyBlockTags = _other.nearbyBlockTags; this.nearbyBlockRequireAllTags = _other.nearbyBlockRequireAllTags; this.nearbyBlockRange = _other.nearbyBlockRange; this.nearbyBlocksNeeded = _other.nearbyBlocksNeeded; this.hasPower = false; this.hasHeat = false; this.hasNearbyBlocks = false; this.userAccessing = false; this.CalculateLookupCoordinates(); this.random = RandomStatic.Range(0, 5); }
public override void OnBlockPlaced(ItemStack byItemStack = null) { if (byItemStack != null) { inv[0].Itemstack = byItemStack.Clone(); } }
public ItemStack TryPlaceOn(ItemStack stack, BlockEntityAnvil beAnvil) { // Already occupied anvil if (beAnvil.WorkItemStack != null) { return(null); } if (stack.Attributes.HasAttribute("voxels")) { try { beAnvil.Voxels = BlockEntityAnvil.deserializeVoxels(stack.Attributes.GetBytes("voxels")); beAnvil.SelectedRecipeId = stack.Attributes.GetInt("selectedRecipeId"); } catch (Exception) { CreateVoxelsFromIronBloom(ref beAnvil.Voxels); } } else { CreateVoxelsFromIronBloom(ref beAnvil.Voxels); } ItemStack workItemStack = stack.Clone(); workItemStack.StackSize = 1; workItemStack.Collectible.SetTemperature(api.World, workItemStack, stack.Collectible.GetTemperature(api.World, stack)); return(workItemStack.Clone()); }
protected virtual bool TryTake(IPlayer byPlayer) { for (int index = itemCapacity; index >= 0; index--) { if (index == itemCapacity && !FuelSlot.Empty && FuelSlot.Itemstack.Collectible.Attributes?.IsTrue("isFirewood") == true) { continue; } if (!ovenInv[index].Empty) { ItemStack stack = ovenInv[index].TakeOut(1); lastRemoved = stack == null ? null : stack.Clone(); if (byPlayer.InventoryManager.TryGiveItemstack(stack)) //TODO GENERALLY ## this behaviour is annoying if the player has a different hotbar slot highlighted { AssetLocation sound = stack.Block?.Sounds?.Place; Api.World.PlaySoundAt(sound != null ? sound : new AssetLocation("sounds/player/throw"), byPlayer.Entity, byPlayer, true, 16); } if (stack.StackSize > 0) { Api.World.SpawnItemEntity(stack, Pos.ToVec3d().Add(0.5, 0.5, 0.5)); } bakingData[index].CurHeightMul = 1; // Reset risenLevel to avoid brief render of unwanted size on next item inserted, if server/client not perfectly in sync - note this only really works if the newly inserted item can be assumed to have risenLevel of 0 i.e. dough updateMesh(index); MarkDirty(true); return(true); } } return(false); }
private void CreateDrop(EntityAgent byEntity, string rocktype) { IPlayer player = (byEntity as EntityPlayer)?.Player; for (int i = 0; i < drops.Length; i++) { double rnd = api.World.Rand.NextDouble(); PanningDrop drop = drops[i]; float val = drop.Chance.nextFloat(); ItemStack stack = drop.ResolvedStack; if (drops[i].Code.Contains("{rocktype}")) { stack = Resolve(drops[i].Type, drops[i].Code.Replace("{rocktype}", rocktype)); } if (rnd < val && stack != null) { stack = stack.Clone(); if (player == null || !player.InventoryManager.TryGiveItemstack(stack, true)) { api.World.SpawnItemEntity(stack, byEntity.ServerPos.XYZ); } break; } } }
/// <summary> /// Tries to take out as much items/liquid as possible and returns it /// </summary> /// <param name="world"></param> /// <param name="bucketStack"></param> /// <param name="quantity"></param> /// <returns></returns> public ItemStack TryTakeContent(IWorldAccessor world, ItemStack bucketStack, int quantity) { ItemStack stack = GetContent(world, bucketStack); if (stack == null) { return(null); } ItemStack takenStack = stack.Clone(); takenStack.StackSize = quantity; stack.StackSize -= quantity; if (stack.StackSize <= 0) { SetContent(bucketStack, null); } else { SetContent(bucketStack, stack); } return(takenStack); }
public void OnFired() { if (IsValidPitKiln()) { for (int i = 0; i < 4; i++) { ItemSlot slot = inventory[i]; if (slot.Empty) { continue; } ItemStack rawStack = slot.Itemstack; ItemStack firedStack = rawStack.Collectible.CombustibleProps?.SmeltedStack?.ResolvedItemstack; if (firedStack != null) { slot.Itemstack = firedStack.Clone(); slot.Itemstack.StackSize = rawStack.StackSize / rawStack.Collectible.CombustibleProps.SmeltedRatio; } } MarkDirty(true); } KillFire(true); }
/// <summary> /// Tries to take out as much items/liquid as possible from a placed bucket and returns it /// </summary> /// <param name="world"></param> /// <param name="pos"></param> /// <param name="quantityItem"></param> public ItemStack TryTakeContent(IWorldAccessor world, BlockPos pos, int quantityItem) { BlockEntityContainer becontainer = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer; if (becontainer == null) { return(null); } ItemStack stack = becontainer.Inventory[GetContainerSlotId(world, pos)].Itemstack; if (stack == null) { return(null); } ItemStack takenStack = stack.Clone(); takenStack.StackSize = quantityItem; stack.StackSize -= quantityItem; if (stack.StackSize <= 0) { becontainer.Inventory[GetContainerSlotId(world, pos)].Itemstack = null; } else { becontainer.Inventory[GetContainerSlotId(world, pos)].Itemstack = stack; } becontainer.Inventory[GetContainerSlotId(world, pos)].MarkDirty(); becontainer.MarkDirty(true); return(takenStack); }
public void GiveOrDropToPlayer(IPlayer buyingPlayer, ItemStack stack, int quantity) { if (stack == null) { return; } while (quantity > 0) { int stacksize = Math.Min(quantity, stack.Collectible.MaxStackSize); if (stacksize <= 0) { return; } ItemStack stackPart = stack.Clone(); stackPart.StackSize = stacksize; if (!buyingPlayer.InventoryManager.TryGiveItemstack(stackPart, true)) { Api.World.SpawnItemEntity(stackPart, buyingPlayer.Entity.Pos.XYZ); } quantity -= stacksize; } }
public override bool TryGiveItemStack(ItemStack itemstack) { if (itemstack == null || itemstack.StackSize == 0) { return(false); } ItemSlot dummySlot = new DummySlot(null); dummySlot.Itemstack = itemstack.Clone(); ItemStackMoveOperation op = new ItemStackMoveOperation(World, EnumMouseButton.Left, 0, EnumMergePriority.AutoMerge, itemstack.StackSize); WeightedSlot wslot = inv.GetBestSuitedSlot(dummySlot, new List <ItemSlot>()); if (wslot.weight > 0) { dummySlot.TryPutInto(wslot.slot, ref op); itemstack.StackSize -= op.MovedQuantity; WatchedAttributes.MarkAllDirty(); return(op.MovedQuantity > 0); } return(false); }
/// <summary> /// Tries to take out as much items/liquid as possible and returns it /// </summary> /// <param name="world"></param> /// <param name="containerStack"></param> /// <param name="quantityItems"></param> /// <returns></returns> public ItemStack TryTakeContent(IWorldAccessor world, ItemStack containerStack, int quantityItems) { ItemStack stack = GetContent(world, containerStack); if (stack == null) { return(null); } ItemStack takenStack = stack.Clone(); takenStack.StackSize = quantityItems; stack.StackSize -= quantityItems; if (stack.StackSize <= 0) { SetContent(containerStack, null); } else { SetContent(containerStack, stack); } return(takenStack); }
/** * Place this itemstack in the inventory. The stackSize of the parameter will be modified * If it is 0 everything is placed. */ public void PlaceItemStack(ItemStack stack) { // First find a slot that has the same seed and still has room foreach (ItemSlot slot in slots) { if (slot.Itemstack != null) { if (slot.Itemstack.Item == stack.Item) { int remaining = slot.Itemstack.Item.MaxStackSize - slot.Itemstack.StackSize; int tomove = Math.Min(remaining, stack.StackSize); if (tomove > 0) { slot.Itemstack.StackSize += tomove; stack.StackSize -= tomove; } } if (stack.StackSize <= 0) { return; } } } // Otherwise find an empty slot foreach (ItemSlot slot in slots) { if (slot.Itemstack == null) { slot.Itemstack = stack.Clone(); stack.StackSize = 0; return; } } }
public void CheckIfFinished(IPlayer byPlayer) { if (MatchesRecipe() && api.World is IServerWorldAccessor) { Voxels = new bool[16, 16]; ItemStack outstack = SelectedRecipe.Output.ResolvedItemstack.Clone(); selectedRecipeNumber = -1; if (outstack.StackSize == 1 && outstack.Class == EnumItemClass.Block) { api.World.BlockAccessor.SetBlock(outstack.Block.BlockId, pos); return; } while (outstack.StackSize > 0) { ItemStack dropStack = outstack.Clone(); dropStack.StackSize = Math.Min(outstack.StackSize, outstack.Collectible.MaxStackSize); outstack.StackSize -= dropStack.StackSize; if (byPlayer.InventoryManager.TryGiveItemstack(dropStack)) { api.World.PlaySoundAt(new AssetLocation("sounds/player/collect"), byPlayer); } else { api.World.SpawnItemEntity(dropStack, pos.ToVec3d().Add(0.5, 0.5, 0.5)); } } api.World.BlockAccessor.SetBlock(0, pos); } }
public static void GiveOrDrop(EntityAgent eagent, ItemStack stack, int quantity) { if (stack == null) { return; } while (quantity > 0) { int stacksize = Math.Min(quantity, stack.Collectible.MaxStackSize); if (stacksize <= 0) { return; } ItemStack stackPart = stack.Clone(); stackPart.StackSize = stacksize; if (!eagent.TryGiveItemStack(stackPart)) { eagent.World.SpawnItemEntity(stackPart, eagent.Pos.XYZ); } quantity -= stacksize; } }
public static void CheckStorage() { try { LinkedList <Chunk> chunkArray = new LinkedList <Chunk>(); DictionaryList <Vector3i, TileEntity> tiles = new DictionaryList <Vector3i, TileEntity>(); ChunkClusterList chunklist = GameManager.Instance.World.ChunkClusters; for (int i = 0; i < chunklist.Count; i++) { ChunkCluster chunk = chunklist[i]; chunkArray = chunk.GetChunkArray(); foreach (Chunk _c in chunkArray) { tiles = _c.GetTileEntities(); foreach (TileEntity tile in tiles.dict.Values) { if (tile.GetTileEntityType().ToString().Equals("SecureLoot")) { TileEntitySecureLootContainer SecureLoot = (TileEntitySecureLootContainer)tile; AdminToolsClientInfo Admin = GameManager.Instance.adminTools.GetAdminToolsClientInfo(SecureLoot.GetOwner()); if (Admin.PermissionLevel > Admin_Level) { ItemStack[] items = SecureLoot.items; int slotNumber = 0; foreach (ItemStack item in items) { if (!item.IsEmpty()) { string _itemName = ItemClass.list[item.itemValue.type].Name; if (dict.Contains(_itemName)) { int _count = item.count; ItemStack itemStack = new ItemStack(); SecureLoot.UpdateSlot(slotNumber, itemStack.Clone()); Vector3i _chestPos = SecureLoot.localChunkPos; using (StreamWriter sw = new StreamWriter(_filepath, true)) { sw.WriteLine("[SERVERTOOLS] Removed {0} {1}, from a secure loot located at {2} {3} {4}, owned by {5}", item.count, _itemName, _chestPos.x, _chestPos.y, _chestPos.z, SecureLoot.GetOwner()); sw.WriteLine(); sw.Flush(); sw.Close(); } Log.Out(string.Format("[SERVERTOOLS] Removed {0} {1}, from a secure loot located at {2} {3} {4}, owned by {5}", item.count, _itemName, _chestPos.x, _chestPos.y, _chestPos.z, SecureLoot.GetOwner())); } } slotNumber++; } } } } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in InventoryCheck.ChestCheck: {0}.", e.Message)); } }
public static MatchedSmeltableStack GetSingleSmeltableStack(ItemStack[] stacks) { // Got only same stacks to smelt directly? ItemStack outputStack = null; float quantity = 0; for (int i = 0; i < stacks.Length; i++) { if (stacks[i] == null) { continue; } ItemStack stack = stacks[i]; float stackSize = stack.StackSize; if (stack.Collectible.CombustibleProps?.SmeltedStack != null && stack.Collectible.CombustibleProps.MeltingPoint > 0) { stackSize *= stack.Collectible.CombustibleProps.SmeltedStack.StackSize; stackSize /= stack.Collectible.CombustibleProps.SmeltedRatio; stack = stack.Collectible.CombustibleProps.SmeltedStack.ResolvedItemstack; } else { return(null); } if (outputStack == null) { outputStack = stack.Clone(); quantity += stackSize; continue; } if (outputStack.Class != stack.Class || outputStack.Id != stack.Id) { return(null); } quantity += stackSize; } if (outputStack == null) { return(null); } if (outputStack.Collectible is BlockSmeltingContainer) { return(null); } return(new MatchedSmeltableStack() { output = outputStack, stackSize = quantity }); }
private void CreateDrop(EntityAgent byEntity, string fromBlockCode) { IPlayer player = (byEntity as EntityPlayer)?.Player; PanningDrop[] drops = null; foreach (var val in dropsBySourceMat.Keys) { if (WildcardUtil.Match(val, fromBlockCode)) { drops = dropsBySourceMat[val]; } } if (drops == null) { throw new InvalidOperationException("Coding error, no drops defined for source mat " + fromBlockCode); } string rocktype = api.World.GetBlock(new AssetLocation(fromBlockCode))?.Variant["rock"]; drops.Shuffle(api.World.Rand); for (int i = 0; i < drops.Length; i++) { PanningDrop drop = drops[i]; double rnd = api.World.Rand.NextDouble(); float extraMul = 1f; if (drop.DropModbyStat != null) { // If the stat does not exist, then GetBlended returns 1 \o/ extraMul = byEntity.Stats.GetBlended(drop.DropModbyStat); } float val = drop.Chance.nextFloat() * extraMul; ItemStack stack = drop.ResolvedItemstack; if (drops[i].Code.Path.Contains("{rocktype}")) { stack = Resolve(drops[i].Type, drops[i].Code.Path.Replace("{rocktype}", rocktype)); } if (rnd < val && stack != null) { stack = stack.Clone(); if (player == null || !player.InventoryManager.TryGiveItemstack(stack, true)) { api.World.SpawnItemEntity(stack, byEntity.ServerPos.XYZ); } break; } } }
List <MatchedSmeltableStackAlloy> mergeAndCompareStacks(ItemStack[] inputStacks, bool useSmeltedWhereApplicable) { List <MatchedSmeltableStackAlloy> mergedStacks = new List <MatchedSmeltableStackAlloy>(); List <MetalAlloyIngredient> ingredients = new List <MetalAlloyIngredient>(this.Ingredients); for (int i = 0; i < inputStacks.Length; i++) { if (inputStacks[i] == null) { continue; } ItemStack stack = inputStacks[i]; float stackSize = stack.StackSize; if (useSmeltedWhereApplicable && stack.Collectible.CombustibleProps?.SmeltedStack != null) { stackSize /= stack.Collectible.CombustibleProps.SmeltedRatio; stack = stack.Collectible.CombustibleProps.SmeltedStack.ResolvedItemstack; } bool exists = false; for (int j = 0; j < mergedStacks.Count; j++) { if (stack.Class == mergedStacks[j].stack.Class && stack.Id == mergedStacks[j].stack.Id) { mergedStacks[j].stackSize += stackSize; exists = true; break; } } if (!exists) { MetalAlloyIngredient ingred = getIgrendientFor(stack, ingredients); if (ingred == null) { return(null); } mergedStacks.Add(new MatchedSmeltableStackAlloy() { stack = stack.Clone(), ingred = ingred, stackSize = stackSize }); } } if (ingredients.Count > 0) { return(null); } return(mergedStacks); }
public ItemStack GetRightContents() { if (contentsRight != null && fillLevelRight >= 100 && IsHardenedRight) { ItemStack outstack = contentsRight.Clone(); (outstack.Attributes["temperature"] as ITreeAttribute)?.RemoveAttribute("cooldownSpeed"); return(outstack); } return(null); }
private static void FinishPaint(RemoteClient client, ItemStack heldItem, bool onePerSlot) { //sbyte maxStack = (sbyte)Item.GetMaximumStackSize(new ItemDescriptor(heldItem.Id, heldItem.Metadata)); sbyte maxStack = 64; // TODO while (heldItem.Count < client.PaintedSlots.Count) { client.PaintedSlots.RemoveAt(client.PaintedSlots.Count - 1); } for (int i = 0; i < client.PaintedSlots.Count; i++) { if (!client.Entity.Inventory[client.PaintedSlots[i]].CanMerge(heldItem)) { client.PaintedSlots.RemoveAt(i); i--; } } int itemsPerSlot = heldItem.Count / client.PaintedSlots.Count; if (onePerSlot) { itemsPerSlot = 1; } var item = (ItemStack)heldItem.Clone(); item.Count = (sbyte)itemsPerSlot; foreach (var slot in client.PaintedSlots) { if (client.Entity.Inventory[slot].Empty) { client.Entity.Inventory[slot] = item; heldItem.Count -= item.Count; } else // Merge { sbyte total = (sbyte)(client.Entity.Inventory[slot].Count + item.Count); if (total <= maxStack) { var newSlot = (ItemStack)client.Entity.Inventory[slot].Clone(); newSlot.Count = total; client.Entity.Inventory[slot] = newSlot; heldItem.Count -= item.Count; } else { heldItem.Count -= (sbyte)(maxStack - client.Entity.Inventory[slot].Count); var newSlot = (ItemStack)client.Entity.Inventory[slot].Clone(); newSlot.Count = maxStack; client.Entity.Inventory[slot] = newSlot; } } } client.Entity.ItemInMouse = heldItem; }
public Entity getRangedEntity(Entity projectile, Entity Firedby, float DamageMult = 1) { if (modConverts != null) { foreach (projectileConverter dele in modConverts.GetInvocationList()) { projectile = dele.Invoke(projectile, Firedby, ProjectileStack?.Clone(), Damage * DamageMult, DropChance, Weight); } } return(projectile); }
public ItemStack TryPlaceOn(ItemStack stack, BlockEntityAnvil beAnvil) { try { beAnvil.Voxels = BlockEntityAnvil.deserializeVoxels(stack.Attributes.GetBytes("voxels")); beAnvil.SelectedRecipeId = stack.Attributes.GetInt("selectedRecipeId"); } catch (Exception) { } return(stack.Clone()); }
public bool Drench(IWorldAccessor world, BlockSelection blockSel) { Block dropblock = world.GetBlock(new AssetLocation("game", "muddygravel")); if (storedtypes["gravel"] > 0) { ItemStack dropStack = new ItemStack(dropblock, Math.Min(dropblock.MaxStackSize / 4, storedtypes["gravel"]));//Deviding max stack drop by four because not doing so created a mess. world.SpawnItemEntity(dropStack.Clone(), blockSel.Position.ToVec3d() + blockSel.HitPosition, (blockSel.Face.Normalf.ToVec3d() * .05) + new Vec3d(0, .08, 0)); storedtypes["gravel"] -= Math.Min(dropblock.MaxStackSize / 4, storedtypes["gravel"]); return(true); } return(false); }
/// <summary> /// Tries to put as much items/liquid as possible into a placed container and returns it how much items it actually moved /// </summary> /// <param name="world"></param> /// <param name="pos"></param> /// <param name="quantity"></param> public virtual int TryPutContent(IWorldAccessor world, BlockPos pos, ItemStack contentStack, int quantity) { if (contentStack == null) { return(0); } float availItems = contentStack.StackSize; ItemStack stack = GetContent(world, pos); if (stack == null) { WaterTightContainableProps props = GetInContainerProps(contentStack); if (props == null || !props.Containable) { return(0); } float maxItems = CapacityLitres * props.ItemsPerLitre; int placeableItems = (int)GameMath.Min(quantity, maxItems, availItems); ItemStack placedstack = contentStack.Clone(); placedstack.StackSize = Math.Min(quantity, placeableItems); SetContent(world, pos, placedstack); return(Math.Min(quantity, placeableItems)); } else { if (!stack.Equals(world, contentStack, GlobalConstants.IgnoredStackAttributes)) { return(0); } WaterTightContainableProps props = GetContentProps(world, pos); float maxItems = CapacityLitres * props.ItemsPerLitre; int placeableItems = (int)Math.Min(availItems, maxItems - (float)stack.StackSize); stack.StackSize += Math.Min(placeableItems, quantity); world.BlockAccessor.GetBlockEntity(pos).MarkDirty(true); (world.BlockAccessor.GetBlockEntity(pos) as BlockEntityContainer).Inventory[GetContainerSlotId(world, pos)].MarkDirty(); return(Math.Min(placeableItems, quantity)); } }
public ItemStack[] GetCookingStacks(ISlotProvider cookingSlotsProvider, bool clone = true) { List <ItemStack> stacks = new List <ItemStack>(4); for (int i = 0; i < cookingSlotsProvider.Slots.Length; i++) { ItemStack stack = cookingSlotsProvider.Slots[i].Itemstack; if (stack == null) { continue; } stacks.Add(clone ? stack.Clone() : stack); } return(stacks.ToArray()); }
public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel) { if (secondsUsed > 4.5f) { if (api.Side == EnumAppSide.Server) { ItemStack resultstack = craftResultStacks[api.World.Rand.Next(craftResultStacks.Length)]; slot.Itemstack = resultstack.Clone(); slot.MarkDirty(); } else { slot.Itemstack.TempAttributes.SetBool("consumed", true); } } }
public static void HandleClickPacket(ClickWindowPacket packet, IWindow window, ref ItemStack itemStaging) { if (packet.SlotIndex >= window.Length || packet.SlotIndex < 0) return; var existing = window[packet.SlotIndex]; if (window.ReadOnlySlots.Contains(packet.SlotIndex)) { if (itemStaging.ID == existing.ID || itemStaging.Empty) { if (itemStaging.Empty) itemStaging = existing; else itemStaging.Count += existing.Count; window[packet.SlotIndex] = ItemStack.EmptyStack; } return; } if (itemStaging.Empty) // Picking up something { if (packet.Shift) { window.MoveToAlternateArea(packet.SlotIndex); } else { if (packet.RightClick) { sbyte mod = (sbyte)(existing.Count % 2); existing.Count /= 2; itemStaging = existing; itemStaging.Count += mod; window[packet.SlotIndex] = existing; } else { itemStaging = window[packet.SlotIndex]; window[packet.SlotIndex] = ItemStack.EmptyStack; } } } else // Setting something down { if (existing.Empty) // Replace empty slot { if (packet.RightClick) { var newItem = (ItemStack)itemStaging.Clone(); newItem.Count = 1; itemStaging.Count--; window[packet.SlotIndex] = newItem; } else { window[packet.SlotIndex] = itemStaging; itemStaging = ItemStack.EmptyStack; } } else { if (existing.CanMerge(itemStaging)) // Merge items { // TODO: Consider the maximum stack size if (packet.RightClick) { existing.Count++; itemStaging.Count--; window[packet.SlotIndex] = existing; } else { existing.Count += itemStaging.Count; window[packet.SlotIndex] = existing; itemStaging = ItemStack.EmptyStack; } } else // Swap items { window[packet.SlotIndex] = itemStaging; itemStaging = existing; } } } }
private static void FinishPaint(RemoteClient client, ItemStack heldItem, bool onePerSlot) { sbyte maxStack = (sbyte)Item.GetMaximumStackSize(new ItemDescriptor(heldItem.Id, heldItem.Metadata)); while (heldItem.Count < client.PaintedSlots.Count) client.PaintedSlots.RemoveAt(client.PaintedSlots.Count - 1); for (int i = 0; i < client.PaintedSlots.Count; i++) { if (!client.Entity.Inventory[client.PaintedSlots[i]].CanMerge(heldItem)) { client.PaintedSlots.RemoveAt(i); i--; } } int itemsPerSlot = heldItem.Count / client.PaintedSlots.Count; if (onePerSlot) itemsPerSlot = 1; var item = (ItemStack)heldItem.Clone(); item.Count = (sbyte)itemsPerSlot; foreach (var slot in client.PaintedSlots) { if (client.Entity.Inventory[slot].Empty) { client.Entity.Inventory[slot] = item; heldItem.Count -= item.Count; } else // Merge { sbyte total = (sbyte)(client.Entity.Inventory[slot].Count + item.Count); if (total <= maxStack) { var newSlot = (ItemStack)client.Entity.Inventory[slot].Clone(); newSlot.Count = total; client.Entity.Inventory[slot] = newSlot; heldItem.Count -= item.Count; } else { heldItem.Count -= (sbyte)(maxStack - client.Entity.Inventory[slot].Count); var newSlot = (ItemStack)client.Entity.Inventory[slot].Clone(); newSlot.Count = maxStack; client.Entity.Inventory[slot] = newSlot; } } } client.Entity.ItemInMouse = heldItem; }