protected override void DoInteraction(IClient client, IItemStack item) { base.DoInteraction(client, item); if (client != null && item != null && !item.IsVoid()) { if (item.Type == (short)BlockData.Items.Shears && !Data.Sheared) { // Drop wool when sheared sbyte count = (sbyte)Server.Rand.Next(2, 4); if (count > 0) { Server.DropItem(World, UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z), new Interfaces.ItemStack((short)BlockData.Blocks.Wool, count, (short)Data.WoolColor)); } Data.Sheared = true; SendMetadataUpdate(); } else if (item.Type == (short)BlockData.Items.Ink_Sack) { // Set the wool colour of this Sheep based on the item.Durability // Safety check. Values of 16 and higher (color do not exist) may crash the client v1.8.1 and below if (item.Durability >= 0 && item.Durability <= 15) { //this.Data.WoolColor = (WoolColor)Enum.ToObject(typeof(WoolColor), (15 - item.Durability)); Data.WoolColor = DyeColorToWoolColor((MetaData.Dyes)Enum.ToObject(typeof(MetaData.Dyes), item.Durability)); SendMetadataUpdate(); } } } }
public static void RecalculateAttributes(IItemStack parent, IWorldAccessor world) { int durability = 0; int maxdurability = 0; ITreeAttribute ToolSlots = parent.Attributes.GetTreeAttribute("toolparts"); foreach (KeyValuePair <string, IAttribute> pair in ToolSlots) { ItemStack stack = pair.Value.GetValue() as ItemStack; stack.ResolveBlockOrItem(world); IModularItem item = (IModularItem)stack.Item; durability += stack.Attributes.GetInt("durability", item != null ? item.GetDurability(stack) : 0); maxdurability += stack.Attributes.GetInt("maxdurability", item != null ? item.GetDurability(stack) : 0); } parent.Attributes.SetInt("maxdurability", maxdurability); if (durability != maxdurability) { parent.Attributes.SetInt("durability", durability); } else { parent.Attributes.RemoveAttribute("durability"); } }
public bool Merge(IItemStack itemStack) { if (itemStack == null) { return(false); } if (_items.Count > 0 && _itemName != itemStack.GetItemName()) { return(false); } var count = itemStack.GetCount(); var wasMerged = false; for (var i = 0; i < count; i++) { var removed = itemStack.RemoveOne(); if (Add(removed)) { wasMerged = true; } else { //add it back to the other stack itemStack.Add(removed); break; } } return(wasMerged); }
public void Use(IClient client, string commandName, string[] tokens) { if (client.Point2 == null || client.Point1 == null) { client.SendMessage("§cPlease select a cuboid first."); return; } UniversalCoords start = client.SelectionStart.Value; UniversalCoords end = client.SelectionEnd.Value; IItemStack item = client.GetOwner().GetServer().GetItemDb().GetItemStack(tokens[0]); if (item == null || item.IsVoid()) { client.SendMessage("§cUnknown item."); return; } if (item.Type > 255) { client.SendMessage("§cInvalid item."); } for (int x = start.WorldX; x <= end.WorldX; x++) { for (int y = start.WorldY; y <= end.WorldY; y++) { for (int z = start.WorldZ; z <= end.WorldZ; z++) { client.GetOwner().GetWorld().SetBlockAndData(UniversalCoords.FromWorld(x, y, z), (byte)item.Type, (byte)item.Durability); } } } }
public bool Add(IItemStack itemStackToAdd) { IHasItemStack firstOpenStack = null; foreach (var stack in _stacks) { var itemStack = stack.GetItemStack(); if (firstOpenStack == null && (itemStack == null || itemStack.GetCount() == 0)) { firstOpenStack = stack; continue; } if (itemStack != null && itemStack.GetItemName() == itemStackToAdd.GetItemName() && itemStack.Merge(itemStackToAdd)) { return(true); } } if (firstOpenStack != null) { firstOpenStack.SetItemStack(itemStackToAdd); return(true); } return(false); }
public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel) { Block block = GetPottedPlant(world); if (block != null) { return(false); } IItemStack heldItem = byPlayer.InventoryManager.ActiveHotbarSlot.Itemstack; if (heldItem != null && heldItem.Class == EnumItemClass.Block) { block = GetBlockToPlant(world, heldItem); if (block != null && this != block) { world.PlaySoundAt(block.Sounds?.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer); world.BlockAccessor.SetBlock(block.BlockId, blockSel.Position); byPlayer.InventoryManager.ActiveHotbarSlot.TakeOut(1); byPlayer.InventoryManager.ActiveHotbarSlot.MarkDirty(); return(true); } } return(false); }
public override void DidModifyItemSlot(IItemSlot slot, IItemStack extractedStack = null) { base.DidModifyItemSlot(slot, extractedStack); if (slots[1] == slot) { if (slot.Itemstack == null) { discardCookingSlots(); } else { int storageType = defaultStorageType; if (slot.Itemstack.ItemAttributes?["storageType"] != null) { storageType = slot.Itemstack.ItemAttributes["storageType"].AsInt(defaultStorageType); } for (int i = 0; i < cookingSlots.Length; i++) { cookingSlots[i].StorageType = (EnumItemStorageFlags)storageType; } } } }
public bool AddStack(IItemStack stack) { if (!this.CanAdd(stack) || stack.Quantity == 0) return false; _stacks.Add(stack); return true; }
public void SetItem(IItemStack item) { this.item = item; texture = item.ItemTexture; image.texture = texture; image.color = new Color(1, 1, 1, 1); }
internal bool OnPlayerInteract(IPlayer byPlayer, Vec3d hit) { BlockFacing facing = getFacing(); int slot = 0 + (hit.Y < 0.5 ? 2 : 0); if (facing == BlockFacing.NORTH && hit.X > 0.5) { slot++; } if (facing == BlockFacing.SOUTH && hit.X < 0.5) { slot++; } if (facing == BlockFacing.WEST && hit.Z > 0.5) { slot++; } if (facing == BlockFacing.EAST && hit.Z < 0.5) { slot++; } IItemStack stack = inventory[slot].Itemstack; if (stack != null) { return(TakeFromSlot(byPlayer, slot)); } else { return(PutInSlot(byPlayer, slot)); } }
public static void PickupItem([NotNull] IItemStack itemStack) { if (OnPickupItem != null) { OnPickupItem(itemStack); } }
public static Dictionary <string, ItemStack> GetSlots(IItemStack stack, IWorldAccessor world) { Dictionary <string, ItemStack> slots = null; IModularItem tool = stack.Item as IModularItem; if (tool != null) { ITreeAttribute ToolSlots = stack.Attributes.GetOrAddTreeAttribute("toolparts"); slots = new Dictionary <string, ItemStack>(); foreach (SlotDefinition slot in GetSlotDefinitions(tool)) { ItemStack partstack = ToolSlots.GetItemstack(slot.SlotName); if (partstack != null) { partstack.ResolveBlockOrItem(world); } slots[slot.SlotName] = partstack; } } return(slots); }
private IItemStack GetStackForItem(IItem item) { IItemStack selectedStack = null; if (ItemStacks == null) { ItemStacks = new List <IItemStack>(); } foreach (var stack in ItemStacks.Reverse()) { if (stack.IsEmpty()) { selectedStack = stack; } if (!stack.ContainsItemOfType(item)) { continue; } if (!stack.HasSpaceFor(item)) { continue; } selectedStack = stack; break; } return(selectedStack ?? CreateNewStackIfPossible()); }
public void RecalculateAttributes(IItemStack stack) { ModularItemHelper.RecalculateAttributes(stack, api.World); ItemStack headstack = GetToolheadStack(stack); int tooltier = 0; if (headstack != null) { headstack.ResolveBlockOrItem(api.World); ToolPart part = (ToolPart)headstack.Item; if (part != null) { tooltier = part.TinkerProps.ToolTier; } } if (tooltier != 0) { stack.Attributes.SetInt("tooltier", tooltier); } else { stack.Attributes.RemoveAttribute("tooltier"); } }
public bool DamagePart(IWorldAccessor world, Entity byEntity, IItemStack itemstack, int amount = 1) { ITreeAttribute ToolSlots = itemstack.Attributes.GetOrAddTreeAttribute("toolparts"); IEnumerable <KeyValuePair <string, IAttribute> > validParts = ToolSlots.Where(pair => { ItemStack part = (ItemStack)pair.Value.GetValue(); return(part != null && part.Attributes.GetInt("durability", part.Collectible.GetDurability(part)) > 0); }); // Damage sub parts, if there are any if (validParts.Count() > 0) { var pair = validParts.ElementAt(new Random().Next(0, validParts.Count())); IItemStack stack = pair.Value.GetValue() as IItemStack; ToolPart part = stack.Item as ToolPart; bool broken = false; if (part != null) { broken = part.DamagePart(world, byEntity, stack); } // If the part is broken, then remove it if (broken) { RemovePart(itemstack, pair.Key); } } // Damamge the tool int leftDurability = itemstack.Attributes.GetInt("durability", GetDurability(itemstack)); leftDurability -= amount; itemstack.Attributes.SetInt("durability", leftDurability); if (leftDurability <= 0) { // Bound minimum durability leftDurability = 0; if (byEntity is EntityPlayer) { IPlayer player = world.PlayerByUid(((EntityPlayer)byEntity).PlayerUID); world.PlaySoundAt(new AssetLocation("sounds/effect/toolbreak"), player, player); } else { world.PlaySoundAt(new AssetLocation("sounds/effect/toolbreak"), byEntity.Pos.X, byEntity.Pos.Y, byEntity.Pos.Z); } } itemstack.Attributes.SetInt("durability", leftDurability); // Notify the containing item if this part has broken return(TinkerProps.Breaks && leftDurability == 0); }
private void PickupItem(IItemStack itemstack) { if (Add(itemstack)) { itemstack.Pickup(); Update(); } }
public bool CanAdd(IItemStack stack) { foreach (IStorage storage in _storages) { if (storage.CanAdd(stack)) return true; } return false; }
public void igniteWithFuel(IItemStack stack) { CombustibleProperties fuelCopts = stack.Collectible.CombustibleProps; maxFuelBurnTime = fuelBurnTime = fuelCopts.BurnDuration * BurnDurationModifier; maxTemperature = (int)(fuelCopts.BurnTemperature * HeatModifier); smokeLevel = fuelCopts.SmokeLevel; setBlockState("lit"); }
public int getSmeltedRatio(IItemStack oreStack) { if (oreStack == null) { return(0); } CombustibleProperties compustibleOpts = oreStack.Collectible.CombustibleProps; return(compustibleOpts.SmeltedStack.ResolvedItemstack.StackSize); }
public void Combine(IItemStack s2, IWorld world) { if (!CanCombine(s2)) { throw new ArgumentException("Unable to combine objects because they were were not compatible"); } StackSize += s2.StackSize; world.Erase(s2); }
void loadToolMeshes() { BlockFacing facing = getFacing().GetCW(); if (facing == null) { return; } Vec3f facingNormal = facing.Normalf; Vec3f origin = new Vec3f(0.5f, 0.5f, 0.5f); ICoreClientAPI clientApi = (ICoreClientAPI)api; for (int i = 0; i < 4; i++) { toolMeshes[i] = null; IItemStack stack = inventory[i].Itemstack; if (stack == null) { continue; } tmpItem = stack.Collectible; if (stack.Class == EnumItemClass.Item) { clientApi.Tesselator.TesselateItem(stack.Item, out toolMeshes[i], this); } else { clientApi.Tesselator.TesselateBlock(stack.Block, out toolMeshes[i]); } if (stack.Class == EnumItemClass.Item && stack.Item.Shape?.VoxelizeTexture == true) { toolMeshes[i].Scale(origin, 0.33f, 0.33f, 0.33f); toolMeshes[i].Translate(((i % 2) == 0) ? 0.23f : -0.3f, (i > 1) ? 0.2f : -0.3f, 0.429f * ((facing.Axis == EnumAxis.X) ? -1 : 1)); toolMeshes[i].Rotate(origin, 0, facing.HorizontalAngleIndex * 90 * GameMath.DEG2RAD, 0); toolMeshes[i].Rotate(origin, 180 * GameMath.DEG2RAD, 0, 0); } else { toolMeshes[i].Scale(origin, 0.6f, 0.6f, 0.6f); float x = ((i > 1) ? -0.2f : 0.3f); float z = ((i % 2 == 0) ? 0.23f : -0.2f) * (facing.Axis == EnumAxis.X ? 1 : -1); toolMeshes[i].Translate(x, 0.429f, z); toolMeshes[i].Rotate(origin, 0, facing.HorizontalAngleIndex * 90 * GameMath.DEG2RAD, GameMath.PIHALF); toolMeshes[i].Rotate(origin, 0, GameMath.PIHALF, 0); } } }
/// <summary> /// Checks to see what dress type the given item is. /// </summary> /// <param name="itemstack"></param> /// <param name="dressType"></param> /// <returns></returns> public static bool IsDressType(IItemStack itemstack, EnumCharacterDressType dressType) { if (itemstack == null || itemstack.Collectible.Attributes == null) { return(false); } string stackDressType = itemstack.Collectible.Attributes["clothescategory"].AsString(); return(stackDressType != null && dressType.ToString().Equals(stackDressType, StringComparison.InvariantCultureIgnoreCase)); }
/// <summary> /// Merges the another itemstack into this stack /// </summary> /// <returns>The amount of items that were shifted from other to this</returns> public static uint Merge(this IItemStack stack, IItemStack other) { uint itemsAdded = 0; if (stack.UnambiguousIdentifier.Equals(other.UnambiguousIdentifier)) { itemsAdded = stack.Add(other.Size); other.Remove(itemsAdded); } return(itemsAdded); }
private Block GetBlockToPlant(IWorldAccessor world, IItemStack heldItem) { string type = heldItem.Block.LastCodePart(0); Block block = world.BlockAccessor.GetBlock(CodeWithParts(type)); if (block == null) { type = heldItem.Block.LastCodePart(1); block = world.BlockAccessor.GetBlock(CodeWithParts(type)); } return(block); }
void loadToolMeshes() { Vec3f origin = new Vec3f(0.5f, 0.5f, 0.5f); ICoreClientAPI clientApi = (ICoreClientAPI)Api; toolMeshes[0] = null; IItemStack stack = inventory[0].Itemstack; if (stack == null) { return; } tmpItem = stack.Collectible; if (stack.Class == EnumItemClass.Item) { clientApi.Tesselator.TesselateItem(stack.Item, out toolMeshes[0], this); } else { clientApi.Tesselator.TesselateBlock(stack.Block, out toolMeshes[0]); } //float zOff = i > 1 ? (-1.8f / 16f) : 0; if (stack.Class == EnumItemClass.Item) { if (stack.Item.Shape?.VoxelizeTexture == true) { toolMeshes[0].Scale(origin, 0.33f, 0.33f, 0.33f); } else { origin.Y = 1f / 30f; toolMeshes[0].Scale(origin, 0.5f, 0.5f, 0.5f); toolMeshes[0].Rotate(origin, 0, 0, 90 * GameMath.DEG2RAD); toolMeshes[0].Translate(0, 0.5f, 0); } } else { toolMeshes[0].Scale(origin, 0.3f, 0.3f, 0.3f); //float x = ((i > 1) ? -0.2f : 0.3f); //float z = ((i % 2 == 0) ? 0.23f : -0.2f) * (facing.Axis == EnumAxis.X ? 1f : -1f); //toolMeshes[0].Translate(x, 0.433f + zOff, z); //toolMeshes[0].Rotate(origin, 0, facing.HorizontalAngleIndex * 90 * GameMath.DEG2RAD, GameMath.PIHALF); //toolMeshes[0].Rotate(origin, 0, GameMath.PIHALF, 0); } }
public void AddItem(IItemStack item) { IItemStack inventoryObj = Inventory.Find(x => x.ItemID == item.ItemID); if (inventoryObj != null) { inventoryObj.Amount += item.ItemID; } else { Inventory.Add(item); } }
public static int GetToolTier(IItemStack stack) { IModularTool tool = stack.Item as IModularTool; if (tool == null) { return(stack?.Item?.ToolTier ?? 0); } else { return(stack.Attributes.GetInt("tooltier", 0)); } }
public bool AddStack(IItemStack stack) { // get the first available storage foreach (IStorage storage in _storages) { var stacks = storage.Get(stack.Descriptor); if (storage.CanAdd(stack)) { return storage.AddStack(stack); } } return false; }
private static bool ApplyPart(IItemStack parent, string slot, ItemStack partstack) { ITreeAttribute ToolSlots = parent.Attributes.GetOrAddTreeAttribute("toolparts"); if (!ToolSlots.HasAttribute(slot)) { ToolSlots.SetItemstack(slot, partstack); (parent.Item as IModularItem).RecalculateAttributes(parent); return(true); } return(false); }
bool PutInSlot(IPlayer player, int slot) { IItemStack stack = player.InventoryManager.ActiveHotbarSlot.Itemstack; if (stack == null || stack.Collectible.Tool == null) { return(false); } player.InventoryManager.ActiveHotbarSlot.TryPutInto(api.World, inventory[slot]); didInteract(player); return(true); }
bool PutInSlot(IPlayer player, int slot) { IItemStack stack = player.InventoryManager.ActiveHotbarSlot.Itemstack; if (stack == null || (stack.Collectible.Tool == null && stack.Collectible.Attributes?["rackable"].AsBool() != true)) { return(false); } player.InventoryManager.ActiveHotbarSlot.TryPutInto(Api.World, inventory[slot]); didInteract(player); return(true); }
bool PutInSlot(IPlayer player, int slot) { IItemStack stack = player.InventoryManager.ActiveHotbarSlot.Itemstack; if (stack == null || !(stack.Class == EnumItemClass.Block ? stack.Block is IFluxStorageItem : stack.Item is IFluxStorageItem)) { return(false); } player.InventoryManager.ActiveHotbarSlot.TryPutInto(Api.World, inventory[slot]); didInteract(player); return(true); }
public static ItemStack GetToolheadStack(IItemStack stack) { ItemStack partstack = null; if (stack.Item is IModularTool) { string toolheadslot = (stack.Item as IModularTool).TinkerProps.ToolheadSlot ?? "toolhead"; ITreeAttribute TinkerSlots = stack.Attributes.GetOrAddTreeAttribute("toolparts"); partstack = TinkerSlots.GetItemstack(toolheadslot); } return(partstack); }
/// <summary> /// When a player interacts with a mob (right-click) with an item / hand /// </summary> /// <param name="client">The client that is interacting</param> /// <param name="item">The item being used (could be Void e.g. Hand)</param> public void InteractWith(IClient client, IItemStack item) { // TODO: create a plugin event for this action DoInteraction(client, item); }
protected virtual void DoInteraction(IClient client, IItemStack item) { }
protected override void DoInteraction(IClient iClient, IItemStack item) { base.DoInteraction(iClient, item); Client client = iClient as Client; if (item != null && !item.IsVoid()) { if ((item.Type == (short)BlockData.Items.Pork || item.Type == (short)BlockData.Items.Grilled_Pork)) { client.Owner.Inventory.RemoveItem(item.Slot); // consume the item if (this.Data.IsTamed) { // Feed a tame wolf pork chop if (this.Health < this.MaxHealth && (item.Type == (short)BlockData.Items.Pork || item.Type == (short)BlockData.Items.Grilled_Pork)) { if (this.Health < this.MaxHealth) { this.Health += 3; // Health is clamped, no need to check if exceeds MaxHealth SendMetadataUpdate(); } } } } else if (!this.Data.IsTamed && item.Type == (short)BlockData.Items.Bone) { // Give a bone this.BonesUntilTamed--; client.Owner.Inventory.RemoveItem(item.Slot); // consume the item if (this.BonesUntilTamed <= 0) { this.Data.IsTamed = true; this.Data.TamedBy = client.Username; this.Health = this.MaxHealth; // TODO: begin following this.Data.TamedBy SendMetadataUpdate(); } } } }
public bool Merge(IItemStack other) { if (other.Descriptor != this.Descriptor) return false; foreach (IItem item in other.Items) { other.Remove(item); this.Add(item); } return true; }
/// <summary> /// Drops an item based on the given player's position and rotation. /// </summary> /// <param name="player">The player to be used for position calculations.</param> /// <param name="stack">The stack to be dropped.</param> /// <returns>The entity ID of the item drop.</returns> public int DropItem(IPlayer player, IItemStack stack) { //todo - proper drop return DropItem(player.GetWorld(), UniversalCoords.FromAbsWorld(player.Position.X + 4, player.Position.Y, player.Position.Z), stack); }
/// <summary> /// Drops an item at the given location. /// </summary> /// <param name="world">The world in which the coordinates reside.</param> /// <param name="coords">The target coordinate</param> /// <param name="stack">The stack to be dropped</param> /// <param name="velocity">An optional velocity (the velocity will be clamped to -0.4 and 0.4 on each axis)</param> /// <returns>The entity ID of the item drop.</returns> public int DropItem(IWorldManager world, UniversalCoords coords, IItemStack stack, Vector3 velocity = new Vector3()) { int entityId = AllocateEntity(); bool sendVelocity = false; if (velocity != Vector3.Origin) { velocity = new Vector3(velocity.X.Clamp(-0.4, 0.4), velocity.Y.Clamp(-0.4, 0.4), velocity.Z.Clamp(-0.4, 0.4)); sendVelocity = true; } AddEntity(new ItemEntity(this, entityId) { World = world as WorldManager, Position = new AbsWorldCoords(new Vector3(coords.WorldX + 0.5, coords.WorldY, coords.WorldZ + 0.5)), // Put in the middle of the block (ignoring Y) ItemId = stack.Type, Count = stack.Count, Velocity = velocity, Durability = stack.Durability }); if (sendVelocity) SendPacketToNearbyPlayers(world as WorldManager, coords, new EntityVelocityPacket { EntityId = entityId, VelocityX = (short)(velocity.X * 8000), VelocityY = (short)(velocity.Y * 8000), VelocityZ = (short)(velocity.Z * 8000) }); return entityId; }
public Item(IItemDescriptor descriptor, IItemStack stack) : this(descriptor) { _stack = stack; }
public bool CanAdd(IItemStack stack) { return !_stacks.Contains(stack) && this.Capacity >= this.ContentWeight + stack.Weight; }
public bool MoveStack(IItemStack stack, IStorage newStorage) { if (!this.Stacks.Contains(stack)) return false; if (!newStorage.CanAdd(stack)) return false; this.RemoveStack(stack); if (newStorage.AddStack(stack)) return true; // Recover the stack this.AddStack(stack); return false; }
public bool RemoveStack(IItemStack stack) { if (stack.Storage == this) stack.Storage = null; _stacks.Remove(stack); return !_stacks.Contains(stack); }