public virtual void FromBytes(BinaryReader reader, IWorldAccessor resolver) { IsWildCard = reader.ReadBoolean(); Type = (EnumItemClass)reader.ReadInt32(); Code = new AssetLocation(reader.ReadString()); Quantity = reader.ReadInt32(); if (!IsWildCard) { ResolvedItemstack = new ItemStack(reader, resolver); } IsTool = reader.ReadBoolean(); ToolDurabilityCost = reader.ReadInt32(); bool haveVariants = reader.ReadBoolean(); if (haveVariants) { AllowedVariants = new string[reader.ReadInt32()]; for (int i = 0; i < AllowedVariants.Length; i++) { AllowedVariants[i] = reader.ReadString(); } } bool haveConsumedStack = reader.ReadBoolean(); if (haveConsumedStack) { ReturnedStack = new JsonItemStack(); ReturnedStack.FromBytes(reader, resolver.ClassRegistry); ReturnedStack.ResolvedItemstack.ResolveBlockOrItem(resolver); } }
/// <summary> /// Reads all the itemstacks properties from a series of bytes, including its stack attributes /// </summary> /// <param name="stream"></param> public void FromBytes(BinaryReader stream) { Class = (EnumItemClass)stream.ReadInt32(); Id = stream.ReadInt32(); stacksize = stream.ReadInt32(); stackAttributes.FromBytes(stream); }
public BlockDropItemStack(ItemStack stack, float chance = 1) { this.Type = stack.Class; this.Code = stack.Collectible.Code; Quantity.avg = chance; ResolvedItemstack = stack; }
/// <summary> /// Replace all the attributes from this item stack by given stack /// </summary> /// <param name="stack"></param> public void SetFrom(ItemStack stack) { this.Id = stack.Collectible.Id; this.Class = stack.Class; this.item = stack.item; this.block = stack.block; this.stacksize = stack.stacksize; this.stackAttributes = stack.stackAttributes.Clone() as TreeAttribute; this.tempAttributes = stack.tempAttributes.Clone() as TreeAttribute; }
/// <summary> /// Create a new itemstack from given item and given stack size /// </summary> /// <param name="item"></param> /// <param name="stacksize"></param> public ItemStack(Item item, int stacksize = 1) { if (item == null) { throw new Exception("Can't create itemstack without item!"); } Class = EnumItemClass.Item; Id = item.ItemId; this.item = item; this.stacksize = stacksize; }
/// <summary> /// Loads the ItemStack from the reader. /// </summary> /// <param name="reader">The reader to get the ItemStack from</param> /// <param name="instancer">The instancer for the ItemStack.</param> public virtual void FromBytes(BinaryReader reader, IClassRegistryAPI instancer) { Type = (EnumItemClass)reader.ReadInt16(); Code = new AssetLocation(reader.ReadString()); StackSize = reader.ReadInt32(); if (reader.ReadBoolean()) { ResolvedItemstack = new ItemStack(reader); } }
/// <summary> /// Create a new itemstack from given block and given stack size /// </summary> /// <param name="block"></param> /// <param name="stacksize"></param> public ItemStack(Block block, int stacksize = 1) { if (block == null) { throw new Exception("Can't create itemstack without block!"); } Class = EnumItemClass.Block; Id = block.BlockId; this.block = block; this.stacksize = stacksize; }
/// <summary> /// Reads the contents of the block bytes and converts it into a block. /// </summary> /// <param name="reader">The reader of the block</param> /// <param name="instancer">The block registry</param> public virtual void FromBytes(BinaryReader reader, IClassRegistryAPI instancer) { Type = (EnumItemClass)reader.ReadInt16(); Code = new AssetLocation(reader.ReadString()); Quantity = NatFloat.One; Quantity.FromBytes(reader); ResolvedItemstack = new ItemStack(reader); LastDrop = reader.ReadBoolean(); if (reader.ReadBoolean()) { DropModbyStat = reader.ReadString(); } }
public static string Name(this EnumItemClass s1) { switch (s1) { case EnumItemClass.Block: return("block"); case EnumItemClass.Item: return("item"); } return(null); }
/// <summary> /// Create a new itemstack with given collectible id, itemclass, stacksize, attributes and a resolver to turn the collectibe + itemclass into an Item/Block /// </summary> /// <param name="id"></param> /// <param name="itemClass"></param> /// <param name="stacksize"></param> /// <param name="stackAttributes"></param> /// <param name="resolver"></param> public ItemStack(int id, EnumItemClass itemClass, int stacksize, TreeAttribute stackAttributes, IWorldAccessor resolver) { this.Id = id; this.Class = itemClass; this.stacksize = stacksize; this.stackAttributes = stackAttributes; if (Class == EnumItemClass.Block) { block = resolver.GetBlock((ushort)this.Id); } else { item = resolver.GetItem(Id); } }
/// <summary> /// Create a new itemstack from given block/item and given stack size /// </summary> /// <param name="collectible"></param> /// <param name="stacksize"></param> public ItemStack(CollectibleObject collectible, int stacksize = 1) { if (collectible == null) { throw new Exception("Can't create itemstack without collectible!"); } if (collectible is Block) { Class = EnumItemClass.Block; Id = collectible.Id; this.block = collectible as Block; this.stacksize = stacksize; } else { Class = EnumItemClass.Item; Id = collectible.Id; this.item = collectible as Item; this.stacksize = stacksize; } }
private ItemStack Resolve(EnumItemClass type, string code) { if (type == EnumItemClass.Block) { Block block = api.World.GetBlock(new AssetLocation(code)); if (block == null) { api.World.Logger.Error("Failed resolving panning block drop with code {0}. Will skip.", code); return(null); } return(new ItemStack(block)); } else { Item item = api.World.GetItem(new AssetLocation(code)); if (item == null) { api.World.Logger.Error("Failed resolving panning item drop with code {0}. Will skip.", code); return(null); } return(new ItemStack(item)); } }
public static bool WildCardMatch(this AssetLocation asset, AssetLocation match, EnumItemClass itemClass, ICoreAPI Api) { if (asset == null || match == null) { return(false); } if (itemClass == EnumItemClass.Item) { return(asset.GetItem(Api).WildCardMatch(match)); } else if (itemClass == EnumItemClass.Block) { return(asset.GetBlock(Api).WildCardMatch(match)); } return(false); }
public IngredientConverter(EnumItemClass type, bool wildcardSupported, string[] invalid) { DefaultType = type; WildcardSupported = wildcardSupported; Invalid = invalid; }