예제 #1
0
        public static void UpdateOrder(BlockDefinition def, bool global, Level level)
        {
            if (def.InventoryOrder == -1)
            {
                return;
            }
            byte raw = def.BlockID, order = (byte)def.InventoryOrder;

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (!global && pl.level != level)
                {
                    continue;
                }
                if (global && pl.level.CustomBlockDefs[raw] != GlobalDefs[raw])
                {
                    continue;
                }

                if (!pl.Supports(CpeExt.InventoryOrder))
                {
                    continue;
                }
                pl.Send(Packet.SetInventoryOrder(raw, order));
            }
        }
예제 #2
0
 internal static void SendLevelInventoryOrder(Player pl)
 {
     BlockDefinition[] defs = pl.level.CustomBlockDefs;
     for (int i = 0; i < defs.Length; i++)
     {
         BlockDefinition def = defs[i];
         if (def != null && def.InventoryOrder >= 0)
         {
             pl.Send(Packet.SetInventoryOrder((byte)i, (byte)def.InventoryOrder));
         }
     }
 }
예제 #3
0
        internal unsafe static void SendLevelInventoryOrder(Player pl)
        {
            BlockDefinition[] defs = pl.level.CustomBlockDefs;

            int  count           = pl.MaxRawBlock + 1;
            int *order_to_blocks = stackalloc int[Block.ExtendedCount];
            int *block_to_orders = stackalloc int[Block.ExtendedCount];

            for (int b = 0; b < Block.ExtendedCount; b++)
            {
                order_to_blocks[b] = -1;
                block_to_orders[b] = -1;
            }

            // Fill slots with explicit order
            for (int i = 0; i < defs.Length; i++)
            {
                BlockDefinition def = defs[i];
                if (def == null || def.RawID > pl.MaxRawBlock)
                {
                    continue;
                }
                if (def.InventoryOrder == -1)
                {
                    continue;
                }

                if (def.InventoryOrder != 0)
                {
                    if (order_to_blocks[def.InventoryOrder] != -1)
                    {
                        continue;
                    }
                    order_to_blocks[def.InventoryOrder] = def.RawID;
                }
                block_to_orders[def.RawID] = def.InventoryOrder;
            }

            // Put blocks into their default slot if slot is unused
            for (int i = 0; i < defs.Length; i++)
            {
                BlockDefinition def = defs[i];
                int             raw = def != null ? def.RawID : i;
                if (raw > pl.MaxRawBlock || (def == null && raw >= Block.CpeCount))
                {
                    continue;
                }

                if (def != null && def.InventoryOrder >= 0)
                {
                    continue;
                }
                if (order_to_blocks[raw] == -1)
                {
                    order_to_blocks[raw] = raw;
                    block_to_orders[raw] = raw;
                }
            }

            // Push blocks whose slots conflict with other blocks into free slots at end
            for (int i = defs.Length - 1; i >= 0; i--)
            {
                BlockDefinition def = defs[i];
                int             raw = def != null ? def.RawID : i;
                if (raw > pl.MaxRawBlock || (def == null && raw >= Block.CpeCount))
                {
                    continue;
                }

                if (block_to_orders[raw] != -1)
                {
                    continue;
                }
                for (int slot = count - 1; slot >= 1; slot--)
                {
                    if (order_to_blocks[slot] != -1)
                    {
                        continue;
                    }

                    block_to_orders[raw]  = slot;
                    order_to_blocks[slot] = raw;
                    break;
                }
            }

            for (int raw = 0; raw < count; raw++)
            {
                int order = block_to_orders[raw];
                if (order == -1)
                {
                    order = 0;
                }

                BlockDefinition def = defs[Block.FromRaw((BlockID)raw)];
                if (def == null && raw >= Block.CpeCount)
                {
                    continue;
                }
                // Special case, don't want 255 getting hidden by default
                if (raw == 255 && def.InventoryOrder == -1)
                {
                    continue;
                }

                pl.Send(Packet.SetInventoryOrder((BlockID)raw, (BlockID)order, pl.hasExtBlocks));
            }
        }