Beispiel #1
0
 private bool MatchRecipe(ICraftingRecipe recipe, IWindowArea craftingArea)
 {
     for (int x = 0; x < craftingArea.Width; x++)
     {
         for (int y = 0; y < craftingArea.Height; y++)
         {
             if (TestRecipe(craftingArea, recipe, x, y))
             {
                 // Check to make sure there aren't any sneaky unused items in the grid
                 int minX = x, maxX = x + recipe.Pattern.GetLength(1);
                 int minY = y, maxY = y + recipe.Pattern.GetLength(0);
                 for (int _x = 0; _x < craftingArea.Width; _x++)
                 {
                     for (int _y = 0; _y < craftingArea.Height; _y++)
                     {
                         if (_x < minX || _x >= maxX || _y < minY || _y >= maxY)
                         {
                             if (!craftingArea[(_y * craftingArea.Width) + _x].Empty)
                                 return false;
                         }
                     }
                 }
                 return true;
             }
         }
     }
     return false;
 }
        private bool MatchRecipe(ICraftingRecipe recipe, IWindowArea craftingArea)
        {
            for (var x = 0; x < craftingArea.Width; x++)
            {
                for (var y = 0; y < craftingArea.Height; y++)
                {
                    if (TestRecipe(craftingArea, recipe, x, y))
                    {
                        // Check to make sure there aren't any sneaky unused items in the grid
                        int minX = x, maxX = x + recipe.Pattern.GetLength(1);
                        int minY = y, maxY = y + recipe.Pattern.GetLength(0);
                        for (var _x = 0; _x < craftingArea.Width; _x++)
                        {
                            for (var _y = 0; _y < craftingArea.Height; _y++)
                            {
                                if (_x < minX || _x >= maxX || _y < minY || _y >= maxY)
                                {
                                    if (!craftingArea[_y * craftingArea.Width + _x].Empty)
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
 public void CopyTo(IWindowArea area)
 {
     for (int i = 0; i < area.Length && i < Length; i++)
     {
         area[i] = this[i];
     }
 }
Beispiel #4
0
 public ICraftingRecipe GetRecipe(IWindowArea craftingArea)
 {
     foreach (var r in Recipes)
     {
         if (MatchRecipe(r, craftingArea))
             return r;
     }
     return null;
 }
 public ICraftingRecipe GetRecipe(IWindowArea craftingArea)
 {
     foreach (var r in _recipes)
     {
         if (MatchRecipe(r, craftingArea))
         {
             return(r);
         }
     }
     return(null);
 }
Beispiel #6
0
 public override int MoveOrMergeItem(int index, ItemStack slot, IWindowArea from)
 {
     for (int i = 0; i < Length; i++)
     {
         if (IsValid(slot, i))
         {
             if (this[i].Empty)
             {
                 this[i]     = slot;
                 from[index] = ItemStack.EmptyStack;
                 return(i);
             }
         }
     }
     return(-1);
 }
Beispiel #7
0
 public override int MoveOrMergeItem(int index, ItemStack slot, IWindowArea from)
 {
     for (int i = 0; i < Length; i++)
     {
         if (IsValid(slot, i))
         {
             if (this[i].Empty)
             {
                 this[i] = slot;
                 from[index] = ItemStack.EmptyStack;
                 return i;
             }
         }
     }
     return -1;
 }
Beispiel #8
0
        public virtual int MoveOrMergeItem(int index, ItemStack item, IWindowArea from)
        {
            int emptyIndex = -1;
            //var maximumStackSize = Item.GetMaximumStackSize(new ItemDescriptor(item.Id, item.Metadata));
            // TODO
            var maximumStackSize = 64;

            for (int i = 0; i < Length; i++)
            {
                if (this[i].Empty && emptyIndex == -1)
                {
                    emptyIndex = i;
                }
                else if (this[i].ID == item.ID &&
                         this[i].Metadata == item.Metadata &&
                         this[i].Count < maximumStackSize)
                {
                    // Merging takes precedence over empty slots
                    emptyIndex = -1;
                    if (from != null)
                    {
                        from[index] = ItemStack.EmptyStack;
                    }
                    if (this[i].Count + item.Count > maximumStackSize)
                    {
                        item = new ItemStack(item.ID, (sbyte)(item.Count - (maximumStackSize - this[i].Count)),
                                             item.Metadata, item.Nbt);
                        this[i] = new ItemStack(item.ID, (sbyte)maximumStackSize, item.Metadata, item.Nbt);
                        continue;
                    }
                    this[i] = new ItemStack(item.ID, (sbyte)(this[i].Count + item.Count), item.Metadata);
                    return(i);
                }
            }
            if (emptyIndex != -1)
            {
                if (from != null)
                {
                    from[index] = ItemStack.EmptyStack;
                }
                this[emptyIndex] = item;
            }
            return(emptyIndex);
        }
Beispiel #9
0
 public bool TestRecipe(IWindowArea craftingArea, ICraftingRecipe recipe, int x, int y)
 {
     if (x + recipe.Pattern.GetLength(1) > craftingArea.Width || y + recipe.Pattern.GetLength(0) > craftingArea.Height)
         return false;
     for (int _x = 0; _x < recipe.Pattern.GetLength(1); _x++)
     {
         for (int _y = 0; _y < recipe.Pattern.GetLength(0); _y++)
         {
             var supplied = craftingArea[(y + _y) * craftingArea.Width + (x + _x)];
             var required = recipe.Pattern[_y, _x];
             if (supplied.ID != required.ID || supplied.Count < required.Count ||
                 (recipe.SignificantMetadata && (required.Metadata != supplied.Metadata)))
             {
                 return false;
             }
         }
     }
     return true;
 }
Beispiel #10
0
 public bool TestRecipe(IWindowArea craftingArea, ICraftingRecipe recipe, int x, int y)
 {
     if (x + recipe.Pattern.GetLength(1) > craftingArea.Width || y + recipe.Pattern.GetLength(0) > craftingArea.Height)
     {
         return(false);
     }
     for (int _x = 0; _x < recipe.Pattern.GetLength(1); _x++)
     {
         for (int _y = 0; _y < recipe.Pattern.GetLength(0); _y++)
         {
             var supplied = craftingArea[(y + _y) * craftingArea.Width + (x + _x)];
             var required = recipe.Pattern[_y, _x];
             if (supplied.ID != required.ID || supplied.Count < required.Count ||
                 (recipe.SignificantMetadata && (required.Metadata != supplied.Metadata)))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #11
0
 public virtual int MoveOrMergeItem(int index, ItemStack item, IWindowArea from)
 {
     int emptyIndex = -1;
     //var maximumStackSize = Item.GetMaximumStackSize(new ItemDescriptor(item.Id, item.Metadata));
     // TODO
     var maximumStackSize = 64;
     for (int i = 0; i < Length; i++)
     {
         if (this[i].Empty && emptyIndex == -1)
             emptyIndex = i;
         else if (this[i].ID == item.ID &&
             this[i].Metadata == item.Metadata &&
             this[i].Count < maximumStackSize)
         {
             // Merging takes precedence over empty slots
             emptyIndex = -1;
             if (from != null)
                 from[index] = ItemStack.EmptyStack;
             if (this[i].Count + item.Count > maximumStackSize)
             {
                 item = new ItemStack(item.ID, (sbyte)(item.Count - (maximumStackSize - this[i].Count)),
                     item.Metadata, item.Nbt);
                 this[i] = new ItemStack(item.ID, (sbyte)maximumStackSize, item.Metadata, item.Nbt);
                 continue;
             }
             this[i] = new ItemStack(item.ID, (sbyte)(this[i].Count + item.Count), item.Metadata);
             return i;
         }
     }
     if (emptyIndex != -1)
     {
         if (from != null)
             from[index] = ItemStack.EmptyStack;
         this[emptyIndex] = item;
     }
     return emptyIndex;
 }
Beispiel #12
0
        private void DrawWindowArea(IWindowArea area, int _x, int _y, Rectangle frame, RenderStage stage)
        {
            var mouse  = Mouse.GetState().Position.ToVector2();
            var scale  = new Point((int)(16 * Game.ScaleFactor * 2));
            var origin = new Point((int)(
                                       Game.GraphicsDevice.Viewport.Width / 2 - Scale(frame.Width / 2) + Scale(_x)),
                                   (int)(Game.GraphicsDevice.Viewport.Height / 2 - Scale(frame.Height / 2) + Scale(_y)));

            for (int i = 0; i < area.Length; i++)
            {
                var item = area[i];
                int x    = (int)((i % area.Width) * Scale(18));
                int y    = (int)((i / area.Width) * Scale(18));
                if (area is CraftingWindowArea)
                {
                    // yes I know this is a crappy hack, bite me
                    if (i == 0)
                    {
                        if (area.Width == 2)
                        {
                            x = (int)Scale(144 - _x);
                            y = (int)Scale(36 - _y);
                        }
                        else
                        {
                            x = (int)Scale(124 - _x);
                            y = (int)Scale(35 - _y);
                        }
                    }
                    else
                    {
                        i--;
                        x = (int)((i % area.Width) * Scale(18));
                        y = (int)((i / area.Width) * Scale(18));
                        i++;
                    }
                }
                var position = origin + new Point(x, y);
                var rect     = new Rectangle(position, scale);
                if (stage == RenderStage.Sprites && rect.Contains(mouse))
                {
                    SelectedSlot = (short)(area.StartIndex + i);
                    SpriteBatch.Draw(Game.White1x1, rect, new Color(Color.White, 150));
                }
                if (item.Empty)
                {
                    continue;
                }
                var provider = Game.ItemRepository.GetItemProvider(item.ID);
                var texture  = provider.GetIconTexture((byte)item.Metadata);
                if (texture != null && stage == RenderStage.Sprites)
                {
                    IconRenderer.RenderItemIcon(SpriteBatch, Items, provider,
                                                (byte)item.Metadata, rect, Color.White);
                }
                if (texture == null && stage == RenderStage.Models && provider is IBlockProvider)
                {
                    IconRenderer.RenderBlockIcon(Game, provider as IBlockProvider, (byte)item.Metadata, rect);
                }
                if (stage == RenderStage.Text && item.Count > 1)
                {
                    int offset = 10;
                    if (item.Count >= 10)
                    {
                        offset -= 6;
                    }
                    position += new Point((int)Scale(offset), (int)Scale(5));
                    Font.DrawText(SpriteBatch, position.X, position.Y, item.Count.ToString(), Game.ScaleFactor);
                }
            }
        }
Beispiel #13
0
 private void DrawWindowArea(IWindowArea area, int _x, int _y, Rectangle frame, RenderStage stage)
 {
     var mouse = Mouse.GetState().Position.ToVector2();
     var scale = new Point((int)(16 * Game.ScaleFactor * 2));
     var origin = new Point((int)(
         Game.GraphicsDevice.Viewport.Width / 2 - Scale(frame.Width / 2) + Scale(_x)),
         (int)(Game.GraphicsDevice.Viewport.Height / 2 - Scale(frame.Height / 2) + Scale(_y)));
     for (int i = 0; i < area.Length; i++)
     {
         var item = area[i];
         int x = (int)((i % area.Width) * Scale(18));
         int y = (int)((i / area.Width) * Scale(18));
         if (area is CraftingWindowArea)
         {
             // yes I know this is a crappy hack, bite me
             if (i == 0)
             {
                 if (area.Width == 2)
                 {
                     x = (int)Scale(144 - _x);
                     y = (int)Scale(36 - _y);
                 }
                 else
                 {
                     x = (int)Scale(124 - _x);
                     y = (int)Scale(35 - _y);
                 }
             }
             else
             {
                 i--;
                 x = (int)((i % area.Width) * Scale(18));
                 y = (int)((i / area.Width) * Scale(18));
                 i++;
             }
         }
         var position = origin + new Point(x, y);
         var rect = new Rectangle(position, scale);
         if (stage == RenderStage.Sprites && rect.Contains(mouse))
         {
             SelectedSlot = (short)(area.StartIndex + i);
             SpriteBatch.Draw(Game.White1x1, rect, new Color(Color.White, 150));
         }
         if (item.Empty)
             continue;
         var provider = Game.ItemRepository.GetItemProvider(item.ID);
         var texture = provider.GetIconTexture((byte)item.Metadata);
         if (texture != null && stage == RenderStage.Sprites)
             IconRenderer.RenderItemIcon(SpriteBatch, Items, provider,
                 (byte)item.Metadata, rect, Color.White);
         if (texture == null && stage == RenderStage.Models && provider is IBlockProvider)
             IconRenderer.RenderBlockIcon(Game, provider as IBlockProvider, (byte)item.Metadata, rect);
         if (stage == RenderStage.Text && item.Count > 1)
         {
             int offset = 10;
             if (item.Count >= 10)
                 offset -= 6;
             position += new Point((int)Scale(offset), (int)Scale(5));
             Font.DrawText(SpriteBatch, position.X, position.Y, item.Count.ToString(), Game.ScaleFactor);
         }
     }
 }
Beispiel #14
0
 public void CopyTo(IWindowArea area)
 {
     for (int i = 0; i < area.Length && i < Length; i++)
         area[i] = this[i];
 }