Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
 /// <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);
 }
Ejemplo n.º 3
0
 public BlockDropItemStack(ItemStack stack, float chance = 1)
 {
     this.Type         = stack.Class;
     this.Code         = stack.Collectible.Code;
     Quantity.avg      = chance;
     ResolvedItemstack = stack;
 }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
0
 /// <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;
 }
Ejemplo n.º 6
0
        /// <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);
            }
        }
Ejemplo n.º 7
0
        /// <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;
        }
Ejemplo n.º 8
0
 /// <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();
     }
 }
Ejemplo n.º 9
0
        public static string Name(this EnumItemClass s1)
        {
            switch (s1)
            {
            case EnumItemClass.Block:
                return("block");

            case EnumItemClass.Item:
                return("item");
            }

            return(null);
        }
Ejemplo n.º 10
0
        /// <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);
            }
        }
Ejemplo n.º 11
0
        /// <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;
            }
        }
Ejemplo n.º 12
0
 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));
     }
 }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
 public IngredientConverter(EnumItemClass type, bool wildcardSupported, string[] invalid)
 {
     DefaultType = type; WildcardSupported = wildcardSupported; Invalid = invalid;
 }